-
-
Notifications
You must be signed in to change notification settings - Fork 664
Labels
Description
void main ()
{
foo() = 42;
}
int foo()
{
return 0;
}
gives the error
q.d(3): Error: cannot modify expression `foo()` because it is not an lvalue
foo() = 42;
^
However,
void main ()
{
foo() = S.init;
}
S foo()
{
return S.init;
}
struct S
{
int i;
void opAssign(S s)
{
this.i = s.i;
}
}
compiles just fine.
I don't see why overloading opAssign should behave any differently in this respect than the built-in assignment does. It just makes it so that you can accidentally assign to an rvalue and have the result disappear on you without getting any errors about doing something nonsensical.
opOpAssign has the same problem: #19061
ntrel