Bug 20762 – __traits(isSame) is underspecified for enums and literals

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
x86
OS
All
Creation time
2020-04-23T08:43:06Z
Last change time
2024-12-13T19:08:17Z
Keywords
spec
Assigned to
No Owner
Creator
Max Samukha
See also
https://issues.dlang.org/show_bug.cgi?id=22269
Moved to GitHub: dmd#19695 →

Comments

Comment #0 by maxsamukha — 2020-04-23T08:43:06Z
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
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/19695 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB