Skip to content

Commit 78883de

Browse files
authored
Merge pull request #3377 from ntrel/this
[spec/expression] Improve docs for `this` and `super` Signed-off-by: Dennis <[email protected]> Merged-on-behalf-of: Dennis <[email protected]>
2 parents 378eec7 + 6c9e057 commit 78883de

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

spec/expression.dd

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1524,9 +1524,10 @@ $(H3 $(LNAME2 this, this))
15241524

15251525
$(P Within a non-static member function, $(D this) resolves to
15261526
a reference to the object for which the function was called.
1527-
If the object is an instance of a struct, $(D this) will
1528-
be a pointer to that instance.
1529-
If a member function is called with an explicit reference
1527+
)
1528+
$(P `typeof(this)` is valid anywhere inside an aggregate type
1529+
definition.
1530+
If a class member function is called with an explicit reference
15301531
to $(D typeof(this)), a non-virtual call is made:)
15311532

15321533
-------------
@@ -1552,14 +1553,14 @@ $(H3 $(LNAME2 this, this))
15521553
}
15531554
-------------
15541555

1555-
$(P Assignment to $(D this) is not allowed.)
1556+
$(P Assignment to $(D this) is not allowed for classes.)
15561557

15571558
$(H3 $(LNAME2 super, super))
15581559

15591560
$(P $(D super) is identical to $(D this), except that it is
15601561
cast to $(D this)'s base class.
15611562
It is an error if there is no base class.
1562-
It is an error to use $(D super) within a struct member function.
1563+
It is an error to use the $(D super) reference outside a non-static class member function.
15631564
(Only class $(D Object) has no base class.)
15641565
If a member function is called with an explicit reference
15651566
to $(D super), a non-virtual call is made.

spec/function.dd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,6 +1019,8 @@ void main()
10191019
}
10201020
------
10211021
)
1022+
$(P Base class methods can also be called through the
1023+
$(DDSUBLINK spec/expression, super, `super`) reference.)
10221024

10231025
$(IMPLEMENTATION_DEFINED Normally calling a virtual function implies getting the
10241026
address of the function at runtime by indexing into the class's `vtbl[]`.

0 commit comments

Comments
 (0)