You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Example program:
--- test.d
struct A
{
static if (__traits(compiles, hasFoo!A)) {
void foo() {}
}
}
enum hasFoo(T) = __traits(hasMember, T, "foo");
void main()
{
import std.stdio;
writeln(hasFoo!A); // false (should be true)writeln(__traits(hasMember, A, "foo")); // true
}
---
Output:
$ dmd test.d && ./test
false
true
When `hasFoo!A` is instantiated in the `__traits(compiles)` expression, it evaluates to false, because the body of the `static if` statement has not been compiled yet. The same instantiation is then re-used in `main`, even though it is no longer semantically correct.
Possibly related to issue 14803.
The text was updated successfully, but these errors were encountered:
Paul Backus (@pbackus) reported this on 2018-12-01T03:21:09Z
Transferred from https://issues.dlang.org/show_bug.cgi?id=19458
CC List
Description
Example program: --- test.d struct A { static if (__traits(compiles, hasFoo!A)) { void foo() {} } } enum hasFoo(T) = __traits(hasMember, T, "foo"); void main() { import std.stdio; writeln(hasFoo!A); // false (should be true) writeln(__traits(hasMember, A, "foo")); // true } --- Output: $ dmd test.d && ./test false true When `hasFoo!A` is instantiated in the `__traits(compiles)` expression, it evaluates to false, because the body of the `static if` statement has not been compiled yet. The same instantiation is then re-used in `main`, even though it is no longer semantically correct. Possibly related to issue 14803.The text was updated successfully, but these errors were encountered: