1 |
298 |
jeremybenn |
/* Test diagnostic messages for invalid lvalues and non-modifiable
|
2 |
|
|
lvalues. */
|
3 |
|
|
/* Origin: Joseph Myers <jsm@polyomino.org.uk> */
|
4 |
|
|
/* { dg-do compile } */
|
5 |
|
|
/* { dg-options "" } */
|
6 |
|
|
|
7 |
|
|
int a, b;
|
8 |
|
|
|
9 |
|
|
void
|
10 |
|
|
f0 (void)
|
11 |
|
|
{
|
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" } */
|
18 |
|
|
}
|
19 |
|
|
|
20 |
|
|
const int c;
|
21 |
|
|
const struct { int x; } d;
|
22 |
|
|
struct { const int x; } e;
|
23 |
|
|
const int *f;
|
24 |
|
|
|
25 |
|
|
void
|
26 |
|
|
f1 (void)
|
27 |
|
|
{
|
28 |
|
|
c = 1; /* { dg-error "assignment of read-only variable 'c'" } */
|
29 |
|
|
d.x = 1; /* { dg-error "assignment of read-only variable 'd'" } */
|
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 read-only variable 'd'" } */
|
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 read-only variable 'd'" } */
|
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 read-only variable 'd'" } */
|
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 read-only variable 'd'" } */
|
46 |
|
|
--e.x; /* { dg-error "decrement of read-only member 'x'" } */
|
47 |
|
|
--(*f); /* { dg-error "decrement of read-only location" } */
|
48 |
|
|
}
|