[Issue 2704] Constness lost when passing a struct member by alias

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Sep 17 11:38:08 UTC 2019


https://issues.dlang.org/show_bug.cgi?id=2704

--- Comment #3 from RazvanN <razvan.nitu1305 at gmail.com> ---
(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.

--


More information about the Digitalmars-d-bugs mailing list