blob: a6f88096226a2cb774059ebb6d52d1689b50c1a5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
/* Test diagnostic messages for invalid lvalues and non-modifiable
lvalues. */
/* Origin: Joseph Myers <jsm@polyomino.org.uk> */
/* { dg-do compile } */
/* { dg-options "" } */
int a, b;
void
f0 (void)
{
(a+b) = 1; /* { dg-error "lvalue required as left operand of assignment" } */
(a+b)++; /* { dg-error "lvalue required as increment operand" } */
++(a+b); /* { dg-error "lvalue required as increment operand" } */
(a+b)--; /* { dg-error "lvalue required as decrement operand" } */
--(a+b); /* { dg-error "lvalue required as decrement operand" } */
&(a+b); /* { dg-error "lvalue required as unary '&' operand" } */
}
const int c;
const struct { int x; } d;
struct { const int x; } e;
const int *f;
void
f1 (void)
{
c = 1; /* { dg-error "assignment of read-only variable 'c'" } */
d.x = 1; /* { dg-error "assignment of read-only variable 'd'" } */
e.x = 1; /* { dg-error "assignment of read-only member 'x'" } */
*f = 1; /* { dg-error "assignment of read-only location" } */
c++; /* { dg-error "increment of read-only variable 'c'" } */
d.x++; /* { dg-error "increment of read-only variable 'd'" } */
e.x++; /* { dg-error "increment of read-only member 'x'" } */
(*f)++; /* { dg-error "increment of read-only location" } */
++c; /* { dg-error "increment of read-only variable 'c'" } */
++d.x; /* { dg-error "increment of read-only variable 'd'" } */
++e.x; /* { dg-error "increment of read-only member 'x'" } */
++(*f); /* { dg-error "increment of read-only location" } */
c--; /* { dg-error "decrement of read-only variable 'c'" } */
d.x--; /* { dg-error "decrement of read-only variable 'd'" } */
e.x--; /* { dg-error "decrement of read-only member 'x'" } */
(*f)--; /* { dg-error "decrement of read-only location" } */
--c; /* { dg-error "decrement of read-only variable 'c'" } */
--d.x; /* { dg-error "decrement of read-only variable 'd'" } */
--e.x; /* { dg-error "decrement of read-only member 'x'" } */
--(*f); /* { dg-error "decrement of read-only location" } */
}
|