https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66341

            Bug ID: 66341
           Summary: Some casts wrongly produce a lvalue
           Product: gcc
           Version: 5.1.0
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: kp.lehrmann+gcc at gmail dot com
  Target Milestone: ---

Created attachment 35653
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=35653&action=edit
gcc compiles ok instead of producing a "error: lvalue required as left operand
of assignment"

Hello,

gcc (any version that I tried) allows some casts to produce a lvalue, whereas
"error: lvalue required as left operand of assignment" would be expected.

Basically, cast of the following form wrongly compile:

    struct B{ int *c;};
    struct A{ struct B b;};
    struct A  a;

    int d = 5;
    (int*)((struct A *)(&a)->b.c) = &d;

Note that if the first cast (int*) is replaced by a cast to any type but the
type of the member in struct B, the expected error message is produced.

For instance, 
    (char*)((struct A *)(&a)->b.c) = &d;
produce the expected error.

Best regards

Reply via email to