This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Bug in gcc: assignment to non-lvalue
On 24/09/2007, Jonathan Adamczewski <jadamcze@utas.edu.au> wrote:
>
> What about something like the following?
>
> struct proxy {
> T& t;
> proxy(T& t_) : t(t_) {}
> proxy& operator=(const T& r) { foo(t, r); return *this; }
> };
>
> struct B { proxy get() { return proxy(bar); } };
>
> int main ()
> {
> B b;
> b.get() = 0;
> }
That is legal, 3.10 paragraph 10 says:
An lvalue for an object is necessary in order to modify the object
except that an rvalue of class type can also be used to modify its
referent under certain circumstances. [Example: a member function
called for an object (9.3) can modify the object. ]
The example I posted doesn't use any member functions, but it's not
clear what other circumstances allow it. I'm pretty sure assigning to
rvalues of builtin type shouldn't compile though.
Jon