1 /* Test diagnostic messages for invalid lvalues and non-modifiable
3 /* Origin: Joseph Myers <jsm@polyomino.org.uk> */
4 /* { dg-do compile } */
5 /* { dg-options "" } */
12 (a
+b
) = 1; /* { dg-error "lvalue required as left operand of assignment" } */
13 (a
+b
)++; /* { dg-error "lvalue required as increment operand" } */
14 ++(a
+b
); /* { dg-error "lvalue required as increment operand" } */
15 (a
+b
)--; /* { dg-error "lvalue required as decrement operand" } */
16 --(a
+b
); /* { dg-error "lvalue required as decrement operand" } */
17 &(a
+b
); /* { dg-error "lvalue required as unary '&' operand" } */
21 const struct { int x
; } d
;
22 struct { const int x
; } e
;
28 c
= 1; /* { dg-error "assignment of read-only variable 'c'" } */
29 d
.x
= 1; /* { dg-error "assignment of member 'x' in read-only object" } */
30 e
.x
= 1; /* { dg-error "assignment of read-only member 'x'" } */
31 *f
= 1; /* { dg-error "assignment of read-only location" } */
32 c
++; /* { dg-error "increment of read-only variable 'c'" } */
33 d
.x
++; /* { dg-error "increment of member 'x' in read-only object" } */
34 e
.x
++; /* { dg-error "increment of read-only member 'x'" } */
35 (*f
)++; /* { dg-error "increment of read-only location" } */
36 ++c
; /* { dg-error "increment of read-only variable 'c'" } */
37 ++d
.x
; /* { dg-error "increment of member 'x' in read-only object" } */
38 ++e
.x
; /* { dg-error "increment of read-only member 'x'" } */
39 ++(*f
); /* { dg-error "increment of read-only location" } */
40 c
--; /* { dg-error "decrement of read-only variable 'c'" } */
41 d
.x
--; /* { dg-error "decrement of member 'x' in read-only object" } */
42 e
.x
--; /* { dg-error "decrement of read-only member 'x'" } */
43 (*f
)--; /* { dg-error "decrement of read-only location" } */
44 --c
; /* { dg-error "decrement of read-only variable 'c'" } */
45 --d
.x
; /* { dg-error "decrement of member 'x' in read-only object" } */
46 --e
.x
; /* { dg-error "decrement of read-only member 'x'" } */
47 --(*f
); /* { dg-error "decrement of read-only location" } */