$(DDOC $(DDOC_BLANKLINE )
$(DDOC_BLANKLINE )
$(SPEC_S Legacy Code,
$(DDOC_BLANKLINE )
$(HEADERNAV_TOC $(HEADERNAV_ITEM body, body
keyword)
)
$(DDOC_BLANKLINE )
$(P To maintain compatibility with older D code, many legacy features remain supported.
$(COMMENT If the $(TT -wo) compiler command line switch is used, the compiler will give warning messages
for each use of a legacy feature.
)
This page describes each legacy feature that is supported, with a suggestion of how to
modernize the code.
)
$(DDOC_BLANKLINE )
$(TABLE2 Legacy Features,
Feature, Summary
$(TROW $(RELATIVE_LINK2 body, body
keyword), $(D body) after a contract statement -
use $(D do) instead)
$(TROW alias
target first syntax, use alias name = target
instead.)
$(TROW Struct/union postblit, use a $(DDSUBLINK spec/struct, struct-copy-constructor,
copy constructor) instead.)
)
$(DDOC_BLANKLINE )
body
keyword)body
was a keyword used to specify a function/method's body after a contract statement:)
$(D_CODE $(D_KEYWORD class) Foo
{
$(D_KEYWORD void) bar($(D_KEYWORD int) i)
$(D_KEYWORD in) { $(D_KEYWORD assert)(i >= 42); }
body { $(D_COMMENT /* Do something interesting */) }
string method(string s)
$(D_KEYWORD out)(v) { $(D_KEYWORD assert)(v.length == s.length); }
body { $(D_COMMENT /* Do something even more interesting */) }
$(D_KEYWORD void) noBody() { $(D_COMMENT /* No contracts, no body */) }
}
)
$(DDOC_BLANKLINE )
do
keyword instead (introduced in v2.075.0):)
$(D_CODE $(D_KEYWORD void) bar($(D_KEYWORD int) i)
$(D_KEYWORD in) { $(D_KEYWORD assert)(i >= 42); }
$(D_KEYWORD do) { $(D_COMMENT /* Look ma, no body! */) }
)
$(DDOC_BLANKLINE )
$(RATIONALE The body
keyword was only used for this single purpose.
Since D grammar aims to be context free, this common word was reserved,
which led to frequent trouble for people interfacing with other languages
(e.g. javascript) or auto-generating code.
)
$(DDOC_BLANKLINE )
$(DDOC_BLANKLINE )
$(SPEC_SUBNAV_PREV glossary, Glossary)
)
)