111
|
1 /* Test for _Atomic in C11. Test of invalid code. */
|
|
2 /* { dg-do compile } */
|
|
3 /* { dg-options "-std=c11 -pedantic-errors" } */
|
|
4
|
|
5 /* Increment and decrement are invalid for atomic complex types and
|
|
6 atomic pointers to incomplete types, just as for the corresponding
|
|
7 non-atomic types. Likewise for types on which arithmetic is
|
|
8 invalid. */
|
|
9 _Atomic _Complex float acf;
|
|
10 void *_Atomic apv;
|
|
11 struct s *_Atomic aps;
|
|
12 _Atomic struct t { char c; } as;
|
|
13
|
|
14 void
|
|
15 func (void)
|
|
16 {
|
|
17 acf++; /* { dg-error "complex types" } */
|
|
18 acf--; /* { dg-error "complex types" } */
|
|
19 ++acf; /* { dg-error "complex types" } */
|
|
20 --acf; /* { dg-error "complex types" } */
|
|
21 apv++; /* { dg-error "wrong type|pointer of type" } */
|
|
22 apv--; /* { dg-error "wrong type|pointer of type" } */
|
|
23 ++apv; /* { dg-error "wrong type|pointer of type" } */
|
|
24 --apv; /* { dg-error "wrong type|pointer of type" } */
|
|
25 aps++; /* { dg-error "pointer to|invalid use of undefined type" } */
|
|
26 aps--; /* { dg-error "pointer to|invalid use of undefined type" } */
|
|
27 ++aps; /* { dg-error "pointer to|invalid use of undefined type" } */
|
|
28 --aps; /* { dg-error "pointer to|invalid use of undefined type" } */
|
|
29 as++; /* { dg-error "wrong type" } */
|
|
30 as--; /* { dg-error "wrong type" } */
|
|
31 ++as; /* { dg-error "wrong type" } */
|
|
32 --as; /* { dg-error "wrong type" } */
|
|
33 }
|
|
34
|
|
35 /* Pointer subtraction and comparisons differing in _Atomic are
|
|
36 invalid where such subtraction and comparisons differing in
|
|
37 qualifiers are valid. There is no special allowance for equality
|
|
38 comparisons of pointers to atomic void to pointers to object
|
|
39 types. Likewise for conditional expressions. */
|
|
40 int *pi;
|
|
41 _Atomic int *pai;
|
|
42 _Atomic void *pav;
|
|
43 int r;
|
|
44
|
|
45 void
|
|
46 func2 (void)
|
|
47 {
|
|
48 r = pai - pi; /* { dg-error "invalid operands" } */
|
|
49 r = pi - pai; /* { dg-error "invalid operands" } */
|
|
50 r = pi < pai; /* { dg-error "distinct pointer types" } */
|
|
51 r = pi > pai; /* { dg-error "distinct pointer types" } */
|
|
52 r = pi <= pai; /* { dg-error "distinct pointer types" } */
|
|
53 r = pi >= pai; /* { dg-error "distinct pointer types" } */
|
|
54 r = pai < pi; /* { dg-error "distinct pointer types" } */
|
|
55 r = pai > pi; /* { dg-error "distinct pointer types" } */
|
|
56 r = pai <= pi; /* { dg-error "distinct pointer types" } */
|
|
57 r = pai >= pi; /* { dg-error "distinct pointer types" } */
|
|
58 r = pav == pi; /* { dg-error "distinct pointer types" } */
|
|
59 r = pav != pi; /* { dg-error "distinct pointer types" } */
|
|
60 r = pi == pav; /* { dg-error "distinct pointer types" } */
|
|
61 r = pi != pav; /* { dg-error "distinct pointer types" } */
|
|
62 (void) (r ? pai : pi); /* { dg-error "pointer type mismatch" } */
|
|
63 (void) (r ? pi : pai); /* { dg-error "pointer type mismatch" } */
|
|
64 (void) (r ? pai : pav); /* { dg-error "pointer type mismatch" } */
|
|
65 (void) (r ? pav : pai); /* { dg-error "pointer type mismatch" } */
|
|
66 }
|
|
67
|
|
68 /* Likewise for pointer assignment. */
|
|
69 void
|
|
70 func3 (void)
|
|
71 {
|
|
72 pai = pi; /* { dg-error "incompatible pointer type" } */
|
|
73 pi = pai; /* { dg-error "incompatible pointer type" } */
|
|
74 pav = pai; /* { dg-error "incompatible pointer type" } */
|
|
75 pai = pav; /* { dg-error "incompatible pointer type" } */
|
|
76 }
|
|
77
|
|
78 /* Cases that are invalid for normal assignments are just as invalid
|
|
79 (and should not ICE) when the LHS is atomic. */
|
|
80 void
|
|
81 func4 (void)
|
|
82 {
|
|
83 as = acf; /* { dg-error "incompatible types" } */
|
|
84 apv = as; /* { dg-error "incompatible types" } */
|
|
85 as += 1; /* { dg-error "invalid operands" } */
|
|
86 apv -= 1; /* { dg-error "pointer of type" } */
|
|
87 apv *= 1; /* { dg-error "invalid operands" } */
|
|
88 apv /= 1; /* { dg-error "invalid operands" } */
|
|
89 apv %= 1; /* { dg-error "invalid operands" } */
|
|
90 apv <<= 1; /* { dg-error "invalid operands" } */
|
|
91 apv >>= 1; /* { dg-error "invalid operands" } */
|
|
92 apv &= 1; /* { dg-error "invalid operands" } */
|
|
93 apv ^= 1; /* { dg-error "invalid operands" } */
|
|
94 apv |= 1; /* { dg-error "invalid operands" } */
|
|
95 }
|
|
96
|
|
97 /* We don't allow atomic bit-fields in GCC (implementation-defined
|
|
98 whether they are permitted). */
|
|
99 struct abf
|
|
100 {
|
|
101 _Atomic int i : 1; /* { dg-error "atomic type" } */
|
|
102 _Atomic int : 0; /* { dg-error "atomic type" } */
|
|
103 };
|
|
104
|
|
105 /* _Atomic (type-name) may not use a name for an array, function,
|
|
106 qualified or atomic type. */
|
|
107 _Atomic (int [2]) v0; /* { dg-error "array type" } */
|
|
108 _Atomic (void (void)) v1; /* { dg-error "function type" } */
|
|
109 _Atomic (_Atomic int) v2; /* { dg-error "applied to a qualified type" } */
|
|
110 _Atomic (const int) v3; /* { dg-error "applied to a qualified type" } */
|
|
111 _Atomic (volatile int) v4; /* { dg-error "applied to a qualified type" } */
|
|
112 _Atomic (int *restrict) v5; /* { dg-error "applied to a qualified type" } */
|
|
113
|
|
114 /* _Atomic, used as a qualifier, may not be applied to a function or
|
|
115 array type. */
|
|
116 typedef int arraytype[2];
|
|
117 typedef void functiontype (void);
|
|
118 _Atomic arraytype v6; /* { dg-error "array type" } */
|
|
119 _Atomic arraytype *v7; /* { dg-error "array type" } */
|
|
120 typedef _Atomic arraytype v8; /* { dg-error "array type" } */
|
|
121 int v9 = sizeof (_Atomic arraytype); /* { dg-error "array type" } */
|
|
122 void v10 (_Atomic arraytype parm); /* { dg-error "array type" } */
|
|
123 struct v11 { _Atomic arraytype f; }; /* { dg-error "array type" } */
|
|
124 _Atomic functiontype v12; /* { dg-error "function type" } */
|
|
125 _Atomic functiontype *v13; /* { dg-error "function type" } */
|
|
126 typedef _Atomic functiontype *v14; /* { dg-error "function type" } */
|
|
127 void v15 (_Atomic functiontype parm); /* { dg-error "function type" } */
|
|
128
|
|
129 /* Function parameters, when function types are required to be
|
|
130 compatible, may not differ in the presence of _Atomic. See
|
|
131 c11-atomic-1.c for corresponding tests where _Atomic matches. */
|
|
132 void fc0 (int _Atomic); /* { dg-message "previous declaration" } */
|
|
133 void fc0 (int); /* { dg-error "conflicting types" } */
|
|
134 void fc1 (int); /* { dg-message "prototype declaration" } */
|
|
135 void
|
|
136 fc1 (x)
|
|
137 _Atomic int x; /* { dg-error "match prototype" } */
|
|
138 {
|
|
139 }
|
|
140 void
|
|
141 fc2 (x) /* { dg-message "previous definition" } */
|
|
142 _Atomic int x;
|
|
143 {
|
|
144 }
|
|
145 void fc2 (int); /* { dg-error "incompatible type" } */
|
|
146 void fc3 (int); /* { dg-message "prototype declaration" } */
|
|
147 void
|
|
148 fc3 (x)
|
|
149 _Atomic short x; /* { dg-error "match prototype" } */
|
|
150 {
|
|
151 }
|
|
152 void
|
|
153 fc4 (x) /* { dg-message "previous definition" } */
|
|
154 _Atomic short x;
|
|
155 {
|
|
156 }
|
|
157 void fc4 (int); /* { dg-error "incompatible type" } */
|
|
158
|
|
159 /* Arrays of atomic elements cannot be initialized with string
|
|
160 literals. */
|
|
161 _Atomic char si0[] = ""; /* { dg-error "inappropriate type" } */
|
|
162 _Atomic char si1[] = u8""; /* { dg-error "inappropriate type" } */
|
|
163 _Atomic signed char si2[] = ""; /* { dg-error "inappropriate type" } */
|
|
164 _Atomic signed char si3[] = u8""; /* { dg-error "inappropriate type" } */
|
|
165 _Atomic unsigned char si4[] = ""; /* { dg-error "inappropriate type" } */
|
|
166 _Atomic unsigned char si5[] = u8""; /* { dg-error "inappropriate type" } */
|
|
167 _Atomic __WCHAR_TYPE__ si6[] = L""; /* { dg-error "inappropriate type" } */
|
|
168 _Atomic __CHAR16_TYPE__ si7[] = u""; /* { dg-error "inappropriate type" } */
|
|
169 _Atomic __CHAR32_TYPE__ si8[] = U""; /* { dg-error "inappropriate type" } */
|
|
170
|
|
171 /* Anything that is syntactically a qualifier applied to the (void)
|
|
172 parameter list results in undefined behavior, which we
|
|
173 diagnose. */
|
|
174 void fv (_Atomic void); /* { dg-error "may not be qualified" } */
|