I feel like this should work: enum Thing { A, B } enum IsThing(T) = is(T == enum) || (__traits(getLinkage, T) == "C++"); enum Is = IsThing!Thing; > Error: argument to `__traits(getLinkage, Thing)` is not a declaration > Error: template instance `IsThing!(Thing)` error instantiating `is(T == enum)` is true, so it shouldn't attempt to evaluate `getLinkage`.
it never worked with static ifs. i was pretty sure that it was By Design, but i cannot remember if i really read that somewhere in the specs, or simply made it out.
My work-around is to use a `static if()` to split the expression across multiple lines. It's not a good workaround; it's lame and unnecessary.
(In reply to Ketmar Dark from comment #1) > it never worked with static ifs. i was pretty sure that it was By Design, > but i cannot remember if i really read that somewhere in the specs, or > simply made it out. Short circuiting actually works in certain static conditions: ``` static if (false && bogusName) {} static assert(true || bogusName); void foo(T)() if (true ? true : bogusName) {}; alias x = foo!int; ``` This is implemented in staticcond.d, function `evalStaticCondition`: > Semantically analyze and then evaluate a static condition at compile time. > This is special because short circuit operators &&, || and ?: at the top > level are not semantically analyzed if the result of the expression is not > necessary. That function is not used to evaluate enums however.
Right. That's why there is a bug report :)
@benjones updated dlang/dmd pull request #10939 "fix issue 20653 . Short circuit manifest constant evaluation" fixing this issue: - fix issue 20653 . Short circuit manifest constant evaluation https://github.com/dlang/dmd/pull/10939
dlang/dmd pull request #10939 "fix issue 20653 . Short circuit manifest constant evaluation" was merged into master: - 73fab586f68d28b448f3712a28edc024862015b2 by Ben Jones: fix issue 20653 -- apply short circuit evaluation for manifest constants https://github.com/dlang/dmd/pull/10939