Bug 2704 – Constness lost when passing a struct member by alias

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2009-03-02T06:36:21Z
Last change time
2024-12-13T17:49:29Z
Assigned to
No Owner
Creator
Max Samukha
Moved to GitHub: dmd#17902 →

Comments

Comment #0 by samukha — 2009-03-02T06:36:21Z
If we can't access a struct/class member passed by alias (hopefully, this will be fixed some day), we at least should be able to get correct type information. struct S { int x; } template Foo(T, alias u) { static assert(is(typeof(u) == T)); //fails } void main() { immutable s = S(); alias Foo!(typeof(s.x), s.x) foo; } The alias gets stripped of constness when passed to the template.
Comment #1 by razvan.nitu1305 — 2019-09-17T09:57:25Z
I think that passing a runtime variable to an alias parameter should be an error.
Comment #2 by maxsamukha — 2019-09-17T11:34:53Z
Would that break tons of reflective code like this? // any template extracting compile-time info template hasAttr(alias symbol, alias attr) { import std.meta; enum _f(alias s) = __traits(isSame, s, attr); alias hasAttr = anySatisfy!(_f, __traits(getAttributes, symbol)); } struct attr { } int main() { @attr int x; static assert(hasAttr!(x, attr)); // wouldn't work anymore return 0; }
Comment #3 by razvan.nitu1305 — 2019-09-17T11:38:08Z
(In reply to Max Samukha from comment #2) > Would that break tons of reflective code like this? > > // any template extracting compile-time info > template hasAttr(alias symbol, alias attr) { > import std.meta; > enum _f(alias s) = __traits(isSame, s, attr); > alias hasAttr = anySatisfy!(_f, __traits(getAttributes, symbol)); > } > > struct attr { > } > > int main() { > @attr int x; > static assert(hasAttr!(x, attr)); // wouldn't work anymore > return 0; > } Yes. I tried working out a particular solution where only dotId expressions (such as the one on the original bug report) are excluded if the member is not a static one and it still breaks code in the dmd testsuite. It really is a rats nest.
Comment #4 by robert.schadek — 2024-12-13T17:49:29Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/17902 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB