https://dlang.org/spec/traits.html
"2. If the two arguments are expressions made up of literals or enums that evaluate to the same value, true is returned."
enum x = 1;
// this fails because x is treated as symbol
static assert(__traits(isSame, x, 1));
// this passes because now x is an expression
static assert(__traits(isSame, (x), 1));
The spec should be clear about this.
Comment #1 by destructionator — 2020-05-24T17:12:47Z
I'm of the opinion that the current behavior of `static assert(__traits(isSame, x, 1));` is buggy because of that line in the spec. It also affects eponymous templates which are otherwise indistinguishable from the literal (which is a good thing - major optimization opportunity in the compiler by taking advantage of this).
But either way, it needs to be very clearly defined.
Comment #2 by destructionator — 2020-05-24T17:16:16Z
But, on the other hand:
@(1) enum e = 1;
pragma(msg, __traits(getAttributes, e));
is currently legal meaning e indeed has a distinct identity from 1. So perhaps the spec does need clarification rather than the implementation.
Comment #3 by robert.schadek — 2024-12-13T19:08:17Z