Skip to content

Commit

Permalink
fix Issue 1918 - __traits(getVirtualFunctions) returns final functions
Browse files Browse the repository at this point in the history
  • Loading branch information
WalterBright committed Jan 22, 2012
1 parent 366ec0e commit 89f321f
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions traits.dd
Expand Up @@ -26,6 +26,7 @@ $(GNAME TraitsKeyword):
$(GBLINK isStaticArray)
$(GBLINK isUnsigned)
$(GBLINK isVirtualFunction)
$(GBLINK isVirtualMethod)
$(GBLINK isAbstractFunction)
$(GBLINK isFinalFunction)
$(GBLINK isStaticFunction)
Expand All @@ -37,6 +38,7 @@ $(GNAME TraitsKeyword):
$(GBLINK getMember)
$(GBLINK getOverloads)
$(GBLINK getVirtualFunctions)
$(GBLINK getVirtualMethods)
$(GBLINK parent)
$(GBLINK classInstanceSize)
$(GBLINK allMembers)
Expand Down Expand Up @@ -150,9 +152,15 @@ $(H2 $(GNAME isFinalClass))

$(H2 $(GNAME isVirtualFunction))

$(P The same as $(GLINK isVirtualMethod), except
that final functions that don't override anything return true.
)

$(H2 $(GNAME isVirtualMethod))

$(P Takes one argument. If that argument is a virtual function,
$(B true) is returned, otherwise $(B false).
Note that final functions are virtual.
Final functions that don't override anything return false.
)

---
Expand All @@ -167,8 +175,8 @@ class C {
}

void main() {
writeln(__traits(isVirtualFunction, C.bar)); // true
writeln(__traits(isVirtualFunction, S.bar)); // false
writeln(__traits(isVirtualMethod, C.bar)); // true
writeln(__traits(isVirtualMethod, S.bar)); // false
}
---

Expand Down Expand Up @@ -371,12 +379,18 @@ int()

$(H2 $(GNAME getVirtualFunctions))

$(P The same as $(GLINK getVirtualMethods), except that
final functions that do not override anything are included.
)

$(H2 $(GNAME getVirtualMethods))

$(P The first argument is a class type or an expression of
class type.
The second argument is a string that matches the name of
one of the functions of that class.
The result is a tuple of the virtual overloads of that function.
Note that final functions are virtual.
It does not include final functions that do not override anything.
)

---
Expand All @@ -392,14 +406,14 @@ class D {
void main() {
D d = new D();

foreach (t; __traits(getVirtualFunctions, D, "foo"))
foreach (t; __traits(getVirtualMethods, D, "foo"))
writeln(typeid(typeof(t)));

alias typeof(__traits(getVirtualFunctions, D, "foo")) b;
alias typeof(__traits(getVirtualMethods, D, "foo")) b;
foreach (t; b)
writeln(typeid(t));

auto i = __traits(getVirtualFunctions, d, "foo")[1](1);
auto i = __traits(getVirtualMethods, d, "foo")[1](1);
writeln(i);
}
---
Expand Down

0 comments on commit 89f321f

Please sign in to comment.