[Issue 12532] New: __traits(compiles, ...) fails to see valid enum symbols

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Apr 6 16:23:43 PDT 2014


https://d.puremagic.com/issues/show_bug.cgi?id=12532

           Summary: __traits(compiles, ...)  fails to see valid enum
                    symbols
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: 2krnk at gmx.net


--- Comment #0 from det <2krnk at gmx.net> 2014-04-06 16:23:40 PDT ---
under certain circumstances, eg when called from a template using mixin and
static if, __traits(compiles, ...)  fails to see valid enum symbols. (if 'enum'
in following example is replaced by 'const bool' or 'immutable bool' all
symbols are found.)

=== EXAMPLE ===

template valid(string mem){
    pragma(msg, "instantiation of 'valid' with: "~mem);
    static if( !__traits( compiles, mixin(mem) ) ){
        enum valid = false;
    }else{
        enum valid =  true;
     }
}

enum ok = valid!"works";
pragma(msg, "found 'works'? "~ok.stringof );
// true - fine, recognizes 'works' later in module scope

enum foo = valid!"bar";
pragma(msg, "found 'bar'? "~foo.stringof );
// true - fine, recognizes 'bar' laterin module scope

enum bar = valid!"foo";
pragma(msg, "found 'foo'? "~bar.stringof );
// false - fails to see 'foo' earlier in module scope!

enum works = true;

void main(){}

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list