Skip to content

Commit cfcb8a7

Browse files
authored
[spec/class] Improve constructor call restrictions (#4257)
Add Restrictions heading, as they apply to base constructor calls too.
1 parent e42c209 commit cfcb8a7

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

spec/class.dd

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,8 @@ $(H3 $(LNAME2 delegating-constructors, Delegating Constructors))
538538
}
539539
------
540540

541+
$(H3 $(LNAME2 ctor-restrictions, Restrictions))
542+
541543
$(P The following restrictions apply:)
542544

543545
$(OL
@@ -555,14 +557,16 @@ $(H3 $(LNAME2 delegating-constructors, Delegating Constructors))
555557
calls.)
556558
)
557559

558-
$(LI If a constructor's code contains a delegating constructor call, all
560+
$(LI If a constructor's code contains a delegating/base constructor call, all
559561
possible execution paths through the constructor must make exactly one
560-
delegating constructor call:
562+
of those calls:
561563

562564
------
563-
this() { a || super(); } // illegal
565+
this() { a || super(); } // illegal, 0 or 1 call
566+
567+
this() { (a) ? this(1) : super(); } // OK
564568

565-
this() { (a) ? this(1) : super(); } // ok
569+
this() { super(); this(1); } // illegal, 2 calls
566570

567571
this()
568572
{
@@ -575,11 +579,14 @@ $(H3 $(LNAME2 delegating-constructors, Delegating Constructors))
575579
)
576580

577581
$(LI It is illegal to refer to $(D this) implicitly or explicitly
578-
prior to making a delegating constructor call.)
582+
prior to making a delegating/base constructor call.)
579583

580-
$(LI Delegating constructor calls cannot appear after labels.)
584+
$(LI Delegating/base constructor calls cannot appear after labels.)
581585
)
582586

587+
$(P See also: $(RELATIVE_LINK2 field-init, field initialization).)
588+
589+
583590
$(H3 $(LNAME2 implicit-base-construction, Implicit Base Class Construction))
584591

585592
$(P If there is no constructor for a class, but there is a constructor

0 commit comments

Comments
 (0)