Warning: statement is not reachable

Edwin van Leeuwen via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Mar 1 13:51:21 PST 2016


On Tuesday, 1 March 2016 at 21:30:44 UTC, Tamas wrote:
>           foreach(attr; __traits(getAttributes, S)) {
>             static if (is(attr == Tag)) {
>               return true;
>             }
>           }
>           return false;
>         }();
>     }
>
>     void main() {
>       static @Tag struct MyStruct {}
>       static struct VanillaStruct {}
>       static assert(isTagged!MyStruct);
>       static assert(!isTagged!VanillaStruct);
>     }

Sorry forgot to add the fix to the email. The following should 
work:

           bool tag = false;
           foreach(attr; __traits(getAttributes, S)) {
              static if (is(attr == Tag)) {
                tag = true;
              }
            }
            return tag;



More information about the Digitalmars-d-learn mailing list