[AMDGPU][True16][MC] true16 for v_pack_b32_f16 (#119630)
[llvm-project.git] / clang / test / Parser / cxx-decl.cpp
blob4c4bb87b1b9531bbcdab399e7b4734d86b9137a3
1 // RUN: %clang_cc1 -verify -fsyntax-only -triple i386-linux -Wredundant-parens -pedantic-errors -fcxx-exceptions -fexceptions %s
2 // RUN: %clang_cc1 -verify -fsyntax-only -triple i386-linux -Wredundant-parens -pedantic-errors -fcxx-exceptions -fexceptions -std=c++98 %s
3 // RUN: %clang_cc1 -verify -fsyntax-only -triple i386-linux -Wredundant-parens -pedantic-errors -fcxx-exceptions -fexceptions -std=c++11 %s
5 const char const *x10; // expected-error {{duplicate 'const' declaration specifier}}
7 int x(*g); // expected-error {{use of undeclared identifier 'g'}}
9 private int cplusplus_is_not_opencl; // expected-error {{expected unqualified-id}}
11 struct Type {
12 int Type;
15 typedef char bool; // expected-error {{redeclaration of C++ built-in type 'bool'}}
17 // PR4451 - We should recover well from the typo of '::' as ':' in a2.
18 namespace y {
19 struct a { };
20 typedef int b;
23 y::a a1;
24 y:a a2; // expected-error {{unexpected ':' in nested name specifier}}
25 y::a a3 = a2;
27 // Some valid colons:
28 void foo() {
29 y: // label
30 y::a s;
32 int a = 4;
33 a = a ? a : a+1;
36 struct b : y::a {};
38 template <typename T>
39 class someclass {
41 int bar() {
42 T *P;
43 return 1 ? P->x : P->y;
47 class asm_class_test {
48 void foo() __asm__("baz");
51 enum { fooenum = 1, };
52 #if __cplusplus <= 199711L
53 // expected-error@-2 {{commas at the end of enumerator lists are a C++11 extension}}
54 #endif
56 struct a {
57 int Type : fooenum;
60 void test(struct Type *P) {
61 int Type;
62 Type = 1 ? P->Type : Type;
64 Type = (y:b) 4; // expected-error {{unexpected ':' in nested name specifier}}
65 Type = 1 ? (
66 (y:b) // expected-error {{unexpected ':' in nested name specifier}}
67 4) : 5;
70 struct test4 {
71 int x // expected-error {{expected ';' at end of declaration list}}
72 int y;
73 int z // expected-error {{expected ';' at end of declaration list}}
76 // Make sure we know these are legitimate commas and not typos for ';'.
77 namespace Commas {
78 struct S {
79 static int a;
80 int c,
81 operator()();
84 int global1,
85 __attribute__(()) global2,
86 (global5), // expected-warning {{redundant parentheses surrounding declarator}}
87 *global6,
88 &global7 = global1,
89 &&global8 = static_cast<int&&>(global1),
90 #if __cplusplus <= 199711L
91 // expected-error@-2 2{{rvalue references are a C++11 extension}}
92 #endif
94 S::a,
95 global9,
96 global10 = 0,
97 global11 == 0, // expected-error {{did you mean '='}}
98 global12 __attribute__(()),
99 global13(0),
100 global14[2],
101 global15;
103 void g() {
104 static int a,
105 b __asm__("ebx"), // expected-error {{expected ';' at end of declaration}}
106 Statics:return;
110 // PR5825
111 struct test5 {};
112 ::new(static_cast<void*>(0)) test5; // expected-error {{expected unqualified-id}}
115 // PR6782
116 template<class T>
117 class Class1;
119 class Class2 {
120 } // expected-error {{expected ';' after class}}
122 typedef Class1<Class2> Type1;
124 struct CodeCompleteConsumer {
127 void CodeCompleteConsumer::() { // expected-error {{xpected unqualified-id}}
132 // PR4111
133 void f(sqrgl); // expected-error {{unknown type name 'sqrgl'}}
135 // PR9903
136 struct S {
137 typedef void a() { }; // expected-error {{function definition declared 'typedef'}}
138 typedef void c() try { } catch(...) { } // expected-error {{function definition declared 'typedef'}}
139 int n, m;
140 typedef S() : n(1), m(2) { } // expected-error {{function definition declared 'typedef'}}
144 namespace TestIsValidAfterTypeSpecifier {
145 struct s {} v;
147 namespace a {
148 struct s operator++(struct s a)
149 { return a; }
152 namespace b {
153 // The newline after s should make no difference.
154 struct s
155 operator++(struct s a)
156 { return a; }
159 struct X {
160 struct s
161 friend f();
162 struct s
163 virtual f();
166 struct s
167 &r0 = v;
168 struct s
169 bitand r2 = v;
173 struct DIE {
174 void foo() {}
177 void test (DIE die, DIE *Die, DIE INT, DIE *FLOAT) {
178 DIE.foo(); // expected-error {{cannot use dot operator on a type}}
179 die.foo();
181 DIE->foo(); // expected-error {{cannot use arrow operator on a type}}
182 Die->foo();
184 int.foo(); // expected-error {{cannot use dot operator on a type}}
185 INT.foo();
187 float->foo(); // expected-error {{cannot use arrow operator on a type}}
188 FLOAT->foo();
191 namespace PR15017 {
192 template<typename T = struct X { int i; }> struct S {}; // expected-error {{'PR15017::X' cannot be defined in a type specifier}}
195 // Ensure we produce at least some diagnostic for attributes in C++98.
196 [[]] struct S; // expected-error {{misplaced attributes}}
197 #if __cplusplus < 201103L
198 // expected-error@-2 {{[[]] attributes are a C++11 extension}}
199 #endif
201 namespace test7 {
202 struct Foo {
203 void a();
204 void b();
207 void Foo::
208 // Comment!
209 a() {}
212 void Foo:: // expected-error {{expected unqualified-id}}
213 // Comment!
216 void test8() {
217 struct {} o;
218 // This used to crash.
219 (&o)->(); // expected-error{{expected unqualified-id}}
222 namespace PR5066 {
223 template<typename T> struct X {};
224 X<int N> x; // expected-error {{type-id cannot have a name}}
226 using T = int (*T)(); // expected-error {{type-id cannot have a name}}
227 #if __cplusplus <= 199711L
228 // expected-error@-2 {{alias declarations are a C++11 extensio}}
229 #endif
233 namespace PR17255 {
234 void foo() {
235 typename A::template B<> c; // expected-error {{use of undeclared identifier 'A'}}
236 #if __cplusplus <= 199711L
237 // expected-error@-2 {{'template' keyword outside of a template}}
238 #endif
242 namespace PR17567 {
243 struct Foobar { // expected-note 2{{declared here}}
244 FooBar(); // expected-error {{missing return type for function 'FooBar'; did you mean the constructor name 'Foobar'?}}
245 ~FooBar(); // expected-error {{undeclared identifier 'FooBar' in destructor name}}
247 FooBar::FooBar() {} // expected-error {{undeclared}} expected-error {{missing return type}}
248 FooBar::~FooBar() {} // expected-error 2{{undeclared}}
251 namespace DuplicateFriend {
252 struct A {
253 friend void friend f(); // expected-warning {{duplicate 'friend' declaration specifier}}
254 friend struct B friend; // expected-warning {{duplicate 'friend' declaration specifier}}
258 namespace NNS {
259 struct A {};
260 namespace B { extern A C1, C2, *C3, C4[], C5; }
261 // Do not produce a redundant parentheses warning here; removing these parens
262 // changes the meaning of the program.
263 A (::NNS::B::C1);
264 A (NNS::B::C2); // expected-warning {{redundant parentheses surrounding declarator}}
265 A (*::NNS::B::C3); // expected-warning {{redundant parentheses surrounding declarator}}
266 A (::NNS::B::C4[2]);
267 // Removing one of these sets of parentheses would be reasonable.
268 A ((::NNS::B::C5)); // expected-warning {{redundant parentheses surrounding declarator}}
270 void f() {
271 // FIXME: A vexing-parse warning here would be useful.
272 A(::NNS::B::C1); // expected-error {{definition or redeclaration}}
273 A(NNS::B::C1); // expected-warning {{redundant paren}} expected-error {{definition or redeclaration}}
277 inline namespace ParensAroundFriend { // expected-error 0-1{{C++11}}
278 struct A {};
279 struct B {
280 static A C();
282 namespace X {
283 struct B {};
284 struct D {
285 // No warning here: while this could be written as
286 // friend (::B::C)();
287 // we do need parentheses *somewhere* here.
288 friend A (::B::C());
293 namespace rdar37099386 {
294 class A typename A; // expected-error {{expected a qualified name after 'typename'}}
295 // expected-error@-1 {{cannot combine with previous 'class' declaration specifier}}
298 // PR8380
299 extern "" // expected-error {{unknown linkage language}}
300 test6a { ;// expected-error {{a type specifier is required for all declarations}}
301 #if __cplusplus <= 199711L
302 // expected-error@-2 {{expected ';' after top level declarator}}
303 #else
304 // expected-error@-4 {{expected expression}}
305 // expected-note@-5 {{to match this}}
306 #endif
308 int test6b;
309 #if __cplusplus >= 201103L
310 // expected-error@+3 {{expected}}
311 // expected-error@-3 {{expected ';' after top level declarator}}
312 #endif