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


Using strings to show my point was not a good idea. You can add a field "int number" to the struct and perform similar operations (with = instead of strcpy).

But even with strings, gcc should give an error like: "strcpy(const char*, const char*) does not exists". In case of a "typedef char string100[100]", gcc behaves correctly by ringing alarm bells. So it seems to be the . operator that behaves incorrectly.

If you replace /*&*/ by & in the SuperArray class, the program becomes correct (in my opinion), but also the effect of the program becomes different.

Regards, Michiel


Andrew Pinski schreef:
On 9/20/07, Michiel de Bondt <debondt@math.ru.nl> wrote:
struct string100 { char value[100]; };

strcpy (a[0].value, "Non-lvalue assignment."); // illegal

So you basically have: a.operator[](0).value

Where value ia an array, I cannot remember the specific rules here but
value decays to &value[0] which is considered a rvalue but value[0] is
a lvalue even if a.operator[](0) is an rvalue.
So I think GCC is correct in accepting this code.

Thanks,
Andrew Pinski


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