This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Bug in gcc: assignment to non-lvalue


Jonathan Wakely wrote:

I believe Andrew's right and the strcpy case is valid, but you do have
a point. I think this should be rejected:

struct A { int i; };
struct B { A get() { return A(); } };

int main ()
{
B b;
b.get().i = 0;
// int& error = b.get().i;
}

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;
}


jonathan.



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]