Bug 9319 – Unexpected compiles __traits behaviour in a certain situation

Status
RESOLVED
Resolution
FIXED
Severity
critical
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-01-14T11:12:00Z
Last change time
2013-07-16T18:48:24Z
Assigned to
nobody
Creator
puneet

Comments

Comment #0 by puneet — 2013-01-14T11:12:38Z
"static if" on the line number 3 should take the else branch, but it does not and compilation actually fails on line number 6, giving me error: Error: this for foo needs to be type Derived not type Base BTW, it is failing for nested (inside base class) template, but seems to work fine for function template (line 16). class Base { // 1 template Bar(alias F) { // 2 static if(__traits(compiles, F())) { // 3 pragma(msg, F.stringof ~ " compiles here"); // prints this // 4 class Bar { // 5 this() { F(); } // but actual compilation fails // 6 } // 7 } else { // 8 pragma(msg, F.stringof ~ " does not compile"); // 9 class Bar { // 10 this() { } // 11 } // 12 } // 13 } // 14 // 15 public void bar(alias F)() { // 16 static if(__traits(compiles, F())) { // works as expected // 17 F(); // 18 } // 19 } // 20 } // 21 // 22 class Derived: Base { // 23 public void foo() {} // 24 public Bar!foo boo; // 25 public void frop() { // 26 bar!foo; // 27 boo = new Bar!foo; // 28 } // 29 } // 30 // 31 void main() { // 32 auto obj = new Derived; // 33 obj.frop(); // 34 } // 35
Comment #1 by k.hara.pg — 2013-07-16T18:48:24Z
Fixed in 2.063.