Skip to content

Commit 887f574

Browse files
committed
Merge remote-tracking branch 'upstream/master' into stable
2 parents b36200f + cfcb8a7 commit 887f574

File tree

8 files changed

+155
-58
lines changed

8 files changed

+155
-58
lines changed

areas-of-d-usage.dd

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ $(AREA_SECTION3 $(LNAME2 games, Games), $(ARTICLE_FA_ICON gamepad),
9292
Many pure-D open source projects show the rising popularity
9393
of D among game developers.
9494
Examples are the 3D game engine
95-
$(HTTP https://github.com/gecko0307/dagon, Dagon) and the cross-platform D game development engine
96-
$(HTTPS https://github.com/MrcSnm/HipremeEngine, HipremeEngine).
95+
$(HTTPS github.com/gecko0307/dagon, Dagon) and the cross-platform D game development engine
96+
$(HTTPS github.com/MrcSnm/HipremeEngine, HipremeEngine).
9797
)
9898

9999
$(AREA_SECTION3 $(LNAME2 web, Web applications), $(ARTICLE_FA_ICON cloud),
@@ -157,7 +157,7 @@ $(AREA_SECTION3 $(LNAME2 embedded, Embedded applications), $(ARTICLE_FA_ICON gea
157157

158158
Using $(HTTPS github.com/ldc-developers/ldc, LDC) (the LLVM D compiler)
159159
enables targeting most popular CPU architectures,
160-
starting from ARM and MIPS-based embedded systems and smartphones,
160+
starting from ARM, RISC-V and MIPS-based embedded systems and smartphones,
161161
ranging to server systems based on POWER and Sparc, and up to the "big iron" z Systems.
162162

163163
))

spec/attribute.dd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,8 @@ $(GNAME AlignAttribute):
259259
$(LI struct, union, and class types)
260260
)
261261

262-
$(P $(D align $(LPAREN) default $(RPAREN)) (re)sets it to the default, which matches the default member alignment
263-
of the companion C compiler. $(D align) by itself is the same as $(D align $(LPAREN) default $(RPAREN)).)
262+
$(P $(D align$(LPAREN)default$(RPAREN)) (re)sets it to the default, which matches the default member alignment
263+
of the companion C compiler. $(D align) by itself is the same as $(D align$(LPAREN)default$(RPAREN)).)
264264

265265
$(SPEC_RUNNABLE_EXAMPLE_COMPILE
266266
--------

spec/class.dd

Lines changed: 52 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -253,11 +253,30 @@ $(H3 $(LNAME2 field_properties, Field Properties))
253253

254254
$(H2 $(LNAME2 member-functions, Member Functions (a.k.a. Methods)))
255255

256-
$(P Non-static member functions have an extra hidden parameter
256+
$(P Non-static member functions must be called on an instance of their class.
257+
They have an extra hidden parameter
257258
called $(DDSUBLINK spec/expression, this, `this`) through which the class object's other members
258259
can be accessed.
260+
Inside the function body, the class instance members are in scope.
259261
)
260262

263+
$(SPEC_RUNNABLE_EXAMPLE_RUN
264+
---
265+
class C
266+
{
267+
int a;
268+
269+
void foo()
270+
{
271+
a = 3; // assign to `this.a`
272+
}
273+
}
274+
275+
auto c = new C;
276+
c.foo();
277+
assert(c.a == 3);
278+
---
279+
)
261280
$(P Non-static member functions can have, in addition to the usual
262281
$(GLINK2 function, FunctionAttribute)s, the attributes
263282
$(D const), $(D immutable), $(D shared), $(D inout), $(D scope) or $(D return scope).
@@ -268,6 +287,7 @@ $(SPEC_RUNNABLE_EXAMPLE_FAIL
268287
class C
269288
{
270289
int a;
290+
271291
void foo() const
272292
{
273293
a = 3; // error, 'this' is const
@@ -430,22 +450,31 @@ $(H2 $(LNAME2 class-instantiation, Class Instantiation))
430450

431451
$(H3 $(LNAME2 constructors, Constructors))
432452

453+
$(P A constructor is a special $(RELATIVE_LINK2 member-functions, member function)
454+
which is normally $(RELATIVE_LINK2 instantiation-process, invoked by the compiler)
455+
when the class instance is created.)
456+
433457
$(GRAMMAR
434458
$(GNAME Constructor):
435459
$(D this) $(GLINK2 function, Parameters) $(GLINK2 function, MemberFunctionAttributes)$(OPT) $(GLINK2 function, FunctionBody)
436460
$(D this) $(GLINK2 function, Parameters) $(GLINK2 function, MemberFunctionAttributes)$(OPT) $(GLINK2 function, MissingFunctionBody)
437461
$(GLINK2 template, ConstructorTemplate)
438462
)
439463

440-
$(P Constructors are defined with a function name of $(D this)
441-
and have no return value:)
464+
$(P A constructor is declared with a function name of $(D this)
465+
and no return type:)
442466

443467
$(SPEC_RUNNABLE_EXAMPLE_RUN
444468
------
445469
class A
446470
{
447471
int i;
448472

473+
this() // constructor taking no arguments
474+
{
475+
i = 2; // initialize `this.i`
476+
}
477+
449478
this(int i) // constructor taking an int argument
450479
{
451480
this.i = i; // initialize field `i` from parameter `i`
@@ -454,11 +483,17 @@ $(GNAME Constructor):
454483

455484
void main()
456485
{
457-
A a = new A(3);
486+
A a = new A; // instantiate A and call `A.this()`
487+
assert(a.i == 2);
488+
489+
a = new A(3); // instantiate A and call `A.this(3)`
458490
assert(a.i == 3);
459491
}
460492
------
461493
)
494+
$(P Explicitly returning a value in a constructor is not allowed,
495+
however `return;` may be used to exit the function early.)
496+
462497

463498
$(H3 $(LNAME2 base-construction, Base Class Construction))
464499

@@ -503,6 +538,8 @@ $(H3 $(LNAME2 delegating-constructors, Delegating Constructors))
503538
}
504539
------
505540

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

508545
$(OL
@@ -520,14 +557,16 @@ $(H3 $(LNAME2 delegating-constructors, Delegating Constructors))
520557
calls.)
521558
)
522559

523-
$(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
524561
possible execution paths through the constructor must make exactly one
525-
delegating constructor call:
562+
of those calls:
526563

527564
------
528-
this() { a || super(); } // illegal
565+
this() { a || super(); } // illegal, 0 or 1 call
529566

530-
this() { (a) ? this(1) : super(); } // ok
567+
this() { (a) ? this(1) : super(); } // OK
568+
569+
this() { super(); this(1); } // illegal, 2 calls
531570

532571
this()
533572
{
@@ -540,11 +579,14 @@ $(H3 $(LNAME2 delegating-constructors, Delegating Constructors))
540579
)
541580

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

545-
$(LI Delegating constructor calls cannot appear after labels.)
584+
$(LI Delegating/base constructor calls cannot appear after labels.)
546585
)
547586

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

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

spec/expression.dd

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2084,7 +2084,8 @@ $(TROW `(` *Expression* `)`, Evaluate an expression - useful as a
20842084

20852085
$(H3 $(LNAME2 this, this))
20862086

2087-
$(P Within a constructor or non-static member function, $(D this) resolves to
2087+
$(P Within a constructor or $(DDSUBLINK spec/class, member-functions,
2088+
non-static member function), $(D this) resolves to
20882089
a reference to the object for which the function was called.
20892090
)
20902091
$(P $(DDSUBLINK spec/type, typeof-this, `typeof(this)`) is valid anywhere
@@ -3269,9 +3270,16 @@ static assert(!is(immutable int == const));
32693270
)
32703271
$(SPEC_RUNNABLE_EXAMPLE_COMPILE
32713272
---
3273+
Object o;
3274+
static assert(!is(o == class)); // `o` is not a type
32723275
static assert(is(Object == class));
32733276
static assert(is(ModuleInfo == struct));
32743277
static assert(!is(int == class));
3278+
3279+
void f();
3280+
static assert(!is(f == function)); // `f` is not a type
3281+
static assert(is(typeof(f) == function));
3282+
static assert(!is(typeof(&f) == function)); // function pointer is not a function
32753283
---
32763284
)
32773285
$(P The `module` and `package` forms are satisfied when *Type* is a symbol, not a *type*,

spec/function.dd

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3600,17 +3600,16 @@ void main()
36003600
---
36013601
)
36023602

3603-
$(P The function must have a $(GLINK SpecifiedFunctionBody).)
3603+
$(P The function must have a $(GLINK FunctionBody).)
36043604

36053605
$(P CTFE is subject to the following restrictions:)
36063606

36073607
$(OL
3608-
$(LI Expressions may not reference any global or local
3609-
static variables.)
3608+
$(LI Expressions may not reference any mutable static variables.)
36103609

36113610
$(LI $(DDSUBLINK spec/iasm, asmstatements, AsmStatements) are not permitted)
36123611

3613-
$(LI Non-portable casts (eg, from $(D int[]) to $(D float[])), including
3612+
$(LI Non-portable casts (e.g., from $(D int[]) to $(D float[])), including
36143613
casts which depend on endianness, are not permitted.
36153614
Casts between signed and unsigned types are permitted.)
36163615

@@ -3656,7 +3655,7 @@ void main()
36563655
)
36573656

36583657
$(LI
3659-
Equality comparisons (==, !=, $(D_KEYWORD is), $(D_KEYWORD !is)) are
3658+
Equality comparisons ($(D ==), $(D !=), $(D is), $(D !is)) are
36603659
permitted between all pointers, without restriction.
36613660
)
36623661

@@ -3668,7 +3667,7 @@ void main()
36683667
)
36693668

36703669
$(P The above restrictions apply only to expressions which are
3671-
actually executed. For example:
3670+
actually evaluated. For example:
36723671
)
36733672
---
36743673
static int y = 0;
@@ -3703,7 +3702,7 @@ static assert(countTen(12) == 12); // invalid, modifies y.
37033702

37043703
$(IMPLEMENTATION_DEFINED
37053704
Functions executed via CTFE can give different results
3706-
from run time when implementation-defined occurs.
3705+
from run time when implementation-defined behavior occurs.
37073706
)
37083707

37093708

spec/hash-map.dd

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ $(H2 $(LNAME2 testing_membership, Testing Membership))
8181

8282
$(H2 $(LNAME2 using_classes_as_key, Using Classes as the KeyType))
8383

84-
$(P Classes can be used as the $(I KeyType). For this to work,
85-
the class definition must override the following member functions
84+
$(P Classes can be used as the $(I KeyType). The behavior is controlled by the following member functions
8685
of class $(D Object):)
8786

8887
$(UL
@@ -109,6 +108,8 @@ $(H2 $(LNAME2 using_classes_as_key, Using Classes as the KeyType))
109108
}
110109
}
111110
---
111+
The default implementation of $(D opEquals) uses the address of the instance for comparisons,
112+
and the default implementation of $(D toHash) hashes the address of the instance.
112113

113114
$(IMPLEMENTATION_DEFINED
114115
`opCmp` is not used to check for equality by the

0 commit comments

Comments
 (0)