Bug 21896 – static if test fails after alias assignment

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2021-05-06T15:22:17Z
Last change time
2024-12-13T19:16:14Z
Assigned to
No Owner
Creator
Andrei Alexandrescu
Moved to GitHub: dmd#19922 →

Comments

Comment #0 by andrei — 2021-05-06T15:22:17Z
Consider the code below. The first static assert passes, the second fails: template Works(T) { static if (is(T U == const U)) { pragma(msg, "is const"); alias Works = U; } else { alias Works = T; } } template Fails(T) { alias Fails = T; static if (is(T U == const U)) { pragma(msg, "assigning"); Fails = U; } } static assert(is(Works!(const int) == int)); static assert(is(Fails!(const int) == int));
Comment #1 by destructionator — 2021-05-06T15:43:08Z
I think this is undefined in the language.... at declaration level, there is no real order of operations. So the static if and assign conceptually happen simultaneously (this is why D doesn't need forward declarations). Obviously the alias assign thing does not follow this rule. But then we need to decide: does the rule change or does alias assign change? And i don't know yet.
Comment #2 by andrei — 2021-05-06T16:19:43Z
@Walter if that's the case, is there a possibility for the compiler to always mark invalid uses as errors?
Comment #3 by robert.schadek — 2024-12-13T19:16:14Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/19922 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB