Skip to content

Commit bcff902

Browse files
authored
[spec/function] Remove MissingFunctionBody from FunctionBody (#4156)
* [spec/function] Split MissingFunctionBody from FunctionBody Fixes #4101. I think this is more natural, as a prototype does not have a body. Changing the definition resolves an inaccuracy in the spec here: > A disabled default constructor may not have a FunctionBody. https://dlang.org/spec/struct.html#disable_default_construction * Remove MainFunctionBody and unindent GRAMMAR Otherwise indent shows up in output.
1 parent 888c37b commit bcff902

File tree

4 files changed

+26
-23
lines changed

4 files changed

+26
-23
lines changed

spec/class.dd

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,7 @@ $(H2 $(LNAME2 constructors, Constructors))
374374
$(GRAMMAR
375375
$(GNAME Constructor):
376376
$(D this) $(GLINK2 function, Parameters) $(GLINK2 function, MemberFunctionAttributes)$(OPT) $(GLINK2 function, FunctionBody)
377+
$(D this) $(GLINK2 function, Parameters) $(GLINK2 function, MemberFunctionAttributes)$(OPT) $(GLINK2 function, MissingFunctionBody)
377378
$(GLINK2 template, ConstructorTemplate)
378379
)
379380

@@ -741,6 +742,7 @@ $(H2 $(LNAME2 destructors, Destructors))
741742
$(GRAMMAR
742743
$(GNAME Destructor):
743744
$(D ~ this ( )) $(GLINK2 function, MemberFunctionAttributes)$(OPT) $(GLINK2 function, FunctionBody)
745+
$(D ~ this ( )) $(GLINK2 function, MemberFunctionAttributes)$(OPT) $(GLINK2 function, MissingFunctionBody)
744746
)
745747

746748
$(P The destructor function is called when:)
@@ -819,6 +821,7 @@ $(H2 $(LNAME2 static-constructor, Static Constructors))
819821
$(GRAMMAR
820822
$(GNAME StaticConstructor):
821823
$(D static this ( )) $(GLINK2 function, MemberFunctionAttributes)$(OPT) $(GLINK2 function, FunctionBody)
824+
$(D static this ( )) $(GLINK2 function, MemberFunctionAttributes)$(OPT) $(GLINK2 function, MissingFunctionBody)
822825
)
823826

824827
$(P A static constructor is a function that performs initializations of
@@ -961,6 +964,7 @@ $(H2 $(LNAME2 shared_static_constructors, Shared Static Constructors))
961964
$(GRAMMAR
962965
$(GNAME SharedStaticConstructor):
963966
$(D shared static this ( )) $(GLINK2 function, MemberFunctionAttributes)$(OPT) $(GLINK2 function, FunctionBody)
967+
$(D shared static this ( )) $(GLINK2 function, MemberFunctionAttributes)$(OPT) $(GLINK2 function, MissingFunctionBody)
964968
)
965969

966970
$(P Shared static constructors are executed before any $(GLINK StaticConstructor)s,
@@ -972,6 +976,7 @@ $(H2 $(LNAME2 shared_static_destructors, Shared Static Destructors))
972976
$(GRAMMAR
973977
$(GNAME SharedStaticDestructor):
974978
$(D shared static ~ this ( )) $(GLINK2 function, MemberFunctionAttributes)$(OPT) $(GLINK2 function, FunctionBody)
979+
$(D shared static ~ this ( )) $(GLINK2 function, MemberFunctionAttributes)$(OPT) $(GLINK2 function, MissingFunctionBody)
975980
)
976981

977982
$(P Shared static destructors are executed at program termination

spec/function.dd

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ $(H2 $(LNAME2 grammar, Function Declarations))
99
$(GRAMMAR
1010
$(GNAME FuncDeclaration):
1111
$(GLINK2 declaration, StorageClasses)$(OPT) $(GLINK2 type, BasicType) $(GLINK FuncDeclarator) $(GLINK FunctionBody)
12+
$(GLINK2 declaration, StorageClasses)$(OPT) $(GLINK2 type, BasicType) $(GLINK FuncDeclarator) $(GLINK MissingFunctionBody)
1213
$(GLINK AutoFuncDeclaration)
1314

1415
$(GNAME AutoFuncDeclaration):
@@ -116,7 +117,6 @@ $(GRAMMAR
116117
$(GNAME FunctionBody):
117118
$(GLINK SpecifiedFunctionBody)
118119
$(GLINK ShortenedFunctionBody)
119-
$(GLINK MissingFunctionBody)
120120

121121
$(GNAME SpecifiedFunctionBody):
122122
$(D do)$(OPT) $(GLINK2 statement, BlockStatement)
@@ -3448,21 +3448,17 @@ $(H2 $(LNAME2 main, $(D main()) Function))
34483448
$(D main()) must be declared as follows:
34493449
)
34503450

3451-
$(GRAMMAR
3452-
$(GNAME MainFunction):
3453-
$(GLINK MainReturnDecl) $(D main$(LPAREN)$(RPAREN)) $(GLINK2 statement, MainFunctionBody)
3454-
$(GLINK MainReturnDecl) $(D main$(LPAREN)string[]) $(GLINK_LEX Identifier)$(D $(RPAREN)) $(GLINK2 statement, MainFunctionBody)
3455-
3456-
$(GNAME MainReturnDecl):
3457-
$(D void)
3458-
$(D int)
3459-
$(GLINK2 type, noreturn)
3460-
$(RELATIVE_LINK2 auto-functions, $(D auto))
3461-
3462-
$(GNAME MainFunctionBody):
3463-
$(GLINK ShortenedFunctionBody)
3464-
$(GLINK SpecifiedFunctionBody)
3465-
)
3451+
$(GRAMMAR
3452+
$(GNAME MainFunction):
3453+
$(GLINK MainReturnDecl) $(D main$(LPAREN)$(RPAREN)) $(GLINK FunctionBody)
3454+
$(GLINK MainReturnDecl) $(D main$(LPAREN)string[]) $(GLINK_LEX Identifier)$(D $(RPAREN)) $(GLINK FunctionBody)
3455+
3456+
$(GNAME MainReturnDecl):
3457+
$(D void)
3458+
$(D int)
3459+
$(GLINK2 type, noreturn)
3460+
$(RELATIVE_LINK2 auto-functions, $(D auto))
3461+
)
34663462

34673463
$(UL
34683464
$(LI If `main` returns `void`, the OS will receive a zero value on success.)
@@ -3493,14 +3489,14 @@ $(H2 $(LNAME2 main, $(D main()) Function))
34933489

34943490
$(P A C $(D main) function must be declared as follows:)
34953491

3496-
$(GRAMMAR
3497-
$(GNAME CMainFunction):
3498-
$(D extern (C)) $(GLINK MainReturnDecl) $(D main$(LPAREN)$(GLINK CmainParameters)$(OPT)$(RPAREN)) $(GLINK2 statement, BlockStatement)
3492+
$(GRAMMAR
3493+
$(GNAME CMainFunction):
3494+
$(D extern (C)) $(GLINK MainReturnDecl) $(D main$(LPAREN)$(GLINK CmainParameters)$(OPT)$(RPAREN)) $(GLINK2 statement, BlockStatement)
34993495

3500-
$(GNAME CmainParameters):
3501-
$(D int) $(GLINK_LEX Identifier), $(D char**) $(GLINK_LEX Identifier)
3502-
$(D int) $(GLINK_LEX Identifier), $(D char**) $(GLINK_LEX Identifier), $(D char**) $(GLINK_LEX Identifier)
3503-
)
3496+
$(GNAME CmainParameters):
3497+
$(D int) $(GLINK_LEX Identifier), $(D char**) $(GLINK_LEX Identifier)
3498+
$(D int) $(GLINK_LEX Identifier), $(D char**) $(GLINK_LEX Identifier), $(D char**) $(GLINK_LEX Identifier)
3499+
)
35043500

35053501
$(P When defined, the first two parameters denote a C-style array (length + pointer)
35063502
that holds the arguments passed to the program by the OS. The third parameter is a POSIX

spec/struct.dd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1379,6 +1379,7 @@ $(H2 $(LEGACY_LNAME2 StructPostblit, struct-postblit, Struct Postblits))
13791379
$(GRAMMAR
13801380
$(GNAME Postblit):
13811381
$(D this $(LPAREN) this $(RPAREN)) $(GLINK2 function, MemberFunctionAttributes)$(OPT) $(GLINK2 function, FunctionBody)
1382+
$(D this $(LPAREN) this $(RPAREN)) $(GLINK2 function, MemberFunctionAttributes)$(OPT) $(GLINK2 function, MissingFunctionBody)
13821383
)
13831384

13841385
$(P $(RED Warning): The postblit is considered legacy and is not recommended for new code.

spec/template.dd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1528,6 +1528,7 @@ $(H2 $(LNAME2 template_ctors, Template Constructors))
15281528
$(GRAMMAR
15291529
$(GNAME ConstructorTemplate):
15301530
$(D this) $(GLINK TemplateParameters) $(GLINK2 function, Parameters) $(GLINK2 function, MemberFunctionAttributes)$(OPT) $(GLINK Constraint)$(OPT) $(GLINK2 function, FunctionBody)
1531+
$(D this) $(GLINK TemplateParameters) $(GLINK2 function, Parameters) $(GLINK2 function, MemberFunctionAttributes)$(OPT) $(GLINK Constraint)$(OPT) $(GLINK2 function, MissingFunctionBody)
15311532
)
15321533

15331534
$(P Templates can be used to form constructors for classes and structs.

0 commit comments

Comments
 (0)