Bug 16468 – __traits(compiles, ...) doesn't work for super, always evaluates false

Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Windows
Creation time
2016-09-05T15:04:00Z
Last change time
2017-01-17T15:36:06Z
Assigned to
nobody
Creator
meapineapple
See also
https://issues.dlang.org/show_bug.cgi?id=15428

Comments

Comment #0 by meapineapple — 2016-09-05T15:04:19Z
It seems that __traits cannot be used to check correctness of a super ctor call, instead always returns false. class Base{ this(int x){} } class Sub: Base{ this(int x){ pragma(msg, __traits(compiles, {super(x);})); // false super(x); // yet compiles } } void main(){ new Sub(10); }
Comment #1 by meapineapple — 2016-09-05T15:07:07Z
I thought to use typeof({super(x);}) as a workaround but this generates a compilation error "Super class constructor call must be in a constructor"
Comment #2 by meapineapple — 2016-09-05T15:08:44Z
Oh, that second error illuminated the first. I was able to get the pragma to output the correct flag by rewriting as `pragma(msg, __traits(compiles, super(x)));` but now I'm just hitting the same error as here https://issues.dlang.org/show_bug.cgi?id=15428
Comment #3 by bitter.taste — 2017-01-17T15:36:06Z
*** This issue has been marked as a duplicate of issue 15428 ***