D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 12533 - instantiated template using __traits(compiles, ...) causes semantic errors when reused
Summary: instantiated template using __traits(compiles, ...) causes semantic errors wh...
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P3 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-04-06 16:39 UTC by det
Modified: 2024-12-13 18:19 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description det 2014-04-06 16:39:50 UTC
compilation fails for no reason in given example involving a template using mixin, static if and __traits(compiles, ...) code reflection. see details in example as it is too complicated to describe.

might be related to issue 12532. however, example fails as well when 'enum' is replaced by 'const'

=== 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 works = valid!"fails";
pragma(msg, "found 'fails' (via 'works')? "~works.stringof );
// compiles but produces 'false': issue 12532

enum dummy = valid!"fails";
pragma(msg, "found 'fails' (via 'dummy')? "~dummy.stringof );
// compiles but produces 'false': issue 12532

enum fails = valid!"fails";
// Error: variable demo.fails had semantic errors when compiling
// NOTE: if you comment out the first two usages of valid!"fails",
// it will work here - but give 'false' again.

//  pragma(msg, "found 'fails' (via 'fails')? "~fails.stringof );

void main(){}
Comment 1 det 2014-04-07 22:50:35 UTC
(In reply to comment #0)

might be caused by issue 12541.
Comment 2 dlangBugzillaToGithub 2024-12-13 18:19:35 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/dmd/issues/17651

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB