D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 21839 - Strange output at Compile time
Summary: Strange output at Compile time
Status: RESOLVED INVALID
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 Windows
: P1 enhancement
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-04-17 16:59 UTC by Menshikov Konstantin
Modified: 2021-04-17 18:35 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Menshikov Konstantin 2021-04-17 16:59:39 UTC
import std.stdio;

alias Sample = inter!q{
  void sample();
};

void main(){}

template inter(string a){
  enum inter = {
      struct Dummy{mixin(a);}
      foreach(member_name; __traits(allMembers, Dummy)){
        if(member_name != `this`){
          pragma(msg, "WHYYYY ", member_name != `this`);
        }
      }
      return 0;
    }();
}

output: 
WHYYYY true
WHYYYY false

version: DMD32 D Compiler v2.096.0-dirty
Comment 1 Vladimir Panteleev 2021-04-17 17:11:48 UTC
What output are you expecting/

(In reply to Menshikov Konstantin from comment #0)
>         if(member_name != `this`){

Did you mean to use "static if" instead of "if"?
Comment 2 Boris Carvajal 2021-04-17 18:35:29 UTC
Nested structs have a hidden 'this' pointer to the enclosing context.
It seems isn't that hidden after all.