[Issue 3546] Aliasing an element of a static array should be legal if the index is a compile time constant
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sun Jun 14 16:54:25 UTC 2020
https://issues.dlang.org/show_bug.cgi?id=3546
Nick Treleaven <nick at geany.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |nick at geany.org
--- Comment #2 from Nick Treleaven <nick at geany.org> ---
> It works with tuples
I was a bit confused how that applied to runtime data until I thought of a type
sequence instance:
auto f(T...)(T s)
{
alias a = s[0];
a = 3; // OK, s is an lvalue sequence
return s[0];
}
static assert(f(1) == 3);
This is a bit surprising. So I suppose your example aliasing a compile-time
known element of a static array of runtime data could also work. But I noticed
aliasing a struct .tupleof doesn't work:
struct S {int i;}
auto f(){
S s;
s.tupleof[0] = 5; // OK, .tupleof appears to be an lvalue sequence
alias seq = s.tupleof; // error
alias a = s.tupleof[0]; // error
alias a = s.i; // OK
a = 4; // Error: need `this` for `i` of type `int`
return s.i;
}
static assert(f(1) == 5);
--
More information about the Digitalmars-d-bugs
mailing list