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 4 5 const char const *x10; // expected-error {{duplicate 'const' declaration specifier}} 6 7 int x(*g); // expected-error {{use of undeclared identifier 'g'}} 8 9 private int cplusplus_is_not_opencl; // expected-error {{expected unqualified-id}} 10 11 struct Type { 12 int Type; 13 }; 14 15 // rdar://8365458 16 // rdar://9132143 17 typedef char bool; // expected-error {{redeclaration of C++ built-in type 'bool'}} 18 19 // PR4451 - We should recover well from the typo of '::' as ':' in a2. 20 namespace y { 21 struct a { }; 22 typedef int b; 23 } 24 25 y::a a1; 26 y:a a2; // expected-error {{unexpected ':' in nested name specifier}} 27 y::a a3 = a2; 28 29 // Some valid colons: 30 void foo() { 31 y: // label 32 y::a s; 33 34 int a = 4; 35 a = a ? a : a+1; 36 } 37 38 struct b : y::a {}; 39 40 template <typename T> 41 class someclass { 42 43 int bar() { 44 T *P; 45 return 1 ? P->x : P->y; 46 } 47 }; 48 49 class asm_class_test { 50 void foo() __asm__("baz"); 51 }; 52 53 enum { fooenum = 1, }; 54 #if __cplusplus <= 199711L 55 // expected-error@-2 {{commas at the end of enumerator lists are a C++11 extension}} 56 #endif 57 58 struct a { 59 int Type : fooenum; 60 }; 61 62 void test(struct Type *P) { 63 int Type; 64 Type = 1 ? P->Type : Type; 65 66 Type = (y:b) 4; // expected-error {{unexpected ':' in nested name specifier}} 67 Type = 1 ? ( 68 (y:b) // expected-error {{unexpected ':' in nested name specifier}} 69 4) : 5; 70 } 71 72 struct test4 { 73 int x // expected-error {{expected ';' at end of declaration list}} 74 int y; 75 int z // expected-error {{expected ';' at end of declaration list}} 76 }; 77 78 // Make sure we know these are legitimate commas and not typos for ';'. 79 namespace Commas { 80 struct S { 81 static int a; 82 int c, 83 operator()(); 84 }; 85 86 int global1, 87 __attribute__(()) global2, 88 (global5), // expected-warning {{redundant parentheses surrounding declarator}} 89 *global6, 90 &global7 = global1, 91 &&global8 = static_cast<int&&>(global1), 92 #if __cplusplus <= 199711L 93 // expected-error@-2 2{{rvalue references are a C++11 extension}} 94 #endif 95 96 S::a, 97 global9, 98 global10 = 0, 99 global11 == 0, // expected-error {{did you mean '='}} 100 global12 __attribute__(()), 101 global13(0), 102 global14[2], 103 global15; 104 105 void g() { 106 static int a, 107 b __asm__("ebx"), // expected-error {{expected ';' at end of declaration}} 108 Statics:return; 109 } 110 } 111 112 // PR5825 113 struct test5 {}; 114 ::new(static_cast<void*>(0)) test5; // expected-error {{expected unqualified-id}} 115 116 117 // PR6782 118 template<class T> 119 class Class1; 120 121 class Class2 { 122 } // expected-error {{expected ';' after class}} 123 124 typedef Class1<Class2> Type1; 125 126 // rdar : // 8307865 127 struct CodeCompleteConsumer { 128 }; 129 130 void CodeCompleteConsumer::() { // expected-error {{xpected unqualified-id}} 131 } 132 133 ; 134 135 // PR4111 136 void f(sqrgl); // expected-error {{unknown type name 'sqrgl'}} 137 138 // PR9903 139 struct S { 140 typedef void a() { }; // expected-error {{function definition declared 'typedef'}} 141 typedef void c() try { } catch(...) { } // expected-error {{function definition declared 'typedef'}} 142 int n, m; 143 typedef S() : n(1), m(2) { } // expected-error {{function definition declared 'typedef'}} 144 }; 145 146 147 namespace TestIsValidAfterTypeSpecifier { 148 struct s {} v; 149 150 namespace a { 151 struct s operator++(struct s a) 152 { return a; } 153 } 154 155 namespace b { 156 // The newline after s should make no difference. 157 struct s 158 operator++(struct s a) 159 { return a; } 160 } 161 162 struct X { 163 struct s 164 friend f(); 165 struct s 166 virtual f(); 167 }; 168 169 struct s 170 &r0 = v; 171 struct s 172 bitand r2 = v; 173 174 } 175 176 struct DIE { 177 void foo() {} 178 }; 179 180 void test (DIE die, DIE *Die, DIE INT, DIE *FLOAT) { 181 DIE.foo(); // expected-error {{cannot use dot operator on a type}} 182 die.foo(); 183 184 DIE->foo(); // expected-error {{cannot use arrow operator on a type}} 185 Die->foo(); 186 187 int.foo(); // expected-error {{cannot use dot operator on a type}} 188 INT.foo(); 189 190 float->foo(); // expected-error {{cannot use arrow operator on a type}} 191 FLOAT->foo(); 192 } 193 194 namespace PR15017 { 195 template<typename T = struct X { int i; }> struct S {}; // expected-error {{'PR15017::X' cannot be defined in a type specifier}} 196 } 197 198 // Ensure we produce at least some diagnostic for attributes in C++98. 199 [[]] struct S; 200 #if __cplusplus <= 199711L 201 // expected-error@-2 {{expected expression}} 202 // expected-error@-3 {{expected unqualified-id}} 203 #else 204 // expected-error@-5 {{misplaced attributes}} 205 #endif 206 207 namespace test7 { 208 struct Foo { 209 void a(); 210 void b(); 211 }; 212 213 void Foo:: 214 // Comment! 215 a() {} 216 217 218 void Foo:: // expected-error {{expected unqualified-id}} 219 // Comment! 220 } 221 222 void test8() { 223 struct {} o; 224 // This used to crash. 225 (&o)->(); // expected-error{{expected unqualified-id}} 226 } 227 228 namespace PR5066 { 229 template<typename T> struct X {}; 230 X<int N> x; // expected-error {{type-id cannot have a name}} 231 232 using T = int (*T)(); // expected-error {{type-id cannot have a name}} 233 #if __cplusplus <= 199711L 234 // expected-error@-2 {{alias declarations are a C++11 extensio}} 235 #endif 236 237 } 238 239 namespace PR17255 { 240 void foo() { 241 typename A::template B<> c; // expected-error {{use of undeclared identifier 'A'}} 242 #if __cplusplus <= 199711L 243 // expected-error@-2 {{'template' keyword outside of a template}} 244 #endif 245 } 246 } 247 248 namespace PR17567 { 249 struct Foobar { // expected-note 2{{declared here}} 250 FooBar(); // expected-error {{missing return type for function 'FooBar'; did you mean the constructor name 'Foobar'?}} 251 ~FooBar(); // expected-error {{undeclared identifier 'FooBar' in destructor name}} 252 }; 253 FooBar::FooBar() {} // expected-error {{undeclared}} expected-error {{missing return type}} 254 FooBar::~FooBar() {} // expected-error 2{{undeclared}} 255 } 256 257 namespace DuplicateFriend { 258 struct A { 259 friend void friend f(); // expected-warning {{duplicate 'friend' declaration specifier}} 260 friend struct B friend; // expected-warning {{duplicate 'friend' declaration specifier}} 261 #if __cplusplus >= 201103L 262 // expected-error@-2 {{'friend' must appear first in a non-function declaration}} 263 #endif 264 }; 265 } 266 267 namespace NNS { 268 struct A {}; 269 namespace B { extern A C1, C2, *C3, C4[], C5; } 270 // Do not produce a redundant parentheses warning here; removing these parens 271 // changes the meaning of the program. 272 A (::NNS::B::C1); 273 A (NNS::B::C2); // expected-warning {{redundant parentheses surrounding declarator}} 274 A (*::NNS::B::C3); // expected-warning {{redundant parentheses surrounding declarator}} 275 A (::NNS::B::C4[2]); 276 // Removing one of these sets of parentheses would be reasonable. 277 A ((::NNS::B::C5)); // expected-warning {{redundant parentheses surrounding declarator}} 278 279 void f() { 280 // FIXME: A vexing-parse warning here would be useful. 281 A(::NNS::B::C1); // expected-error {{definition or redeclaration}} 282 A(NNS::B::C1); // expected-warning {{redundant paren}} expected-error {{definition or redeclaration}} 283 } 284 } 285 286 inline namespace ParensAroundFriend { // expected-error 0-1{{C++11}} 287 struct A {}; 288 struct B { 289 static A C(); 290 }; 291 namespace X { 292 struct B {}; 293 struct D { 294 // No warning here: while this could be written as 295 // friend (::B::C)(); 296 // we do need parentheses *somewhere* here. 297 friend A (::B::C()); 298 }; 299 } 300 } 301 302 namespace rdar37099386 { 303 class A typename A; // expected-error {{expected a qualified name after 'typename'}} 304 // expected-error@-1 {{cannot combine with previous 'class' declaration specifier}} 305 } 306 307 // PR8380 308 extern "" // expected-error {{unknown linkage language}} 309 test6a { ;// expected-error {{a type specifier is required for all declarations}} 310 #if __cplusplus <= 199711L 311 // expected-error@-2 {{expected ';' after top level declarator}} 312 #else 313 // expected-error@-4 {{expected expression}} 314 // expected-note@-5 {{to match this}} 315 #endif 316 317 int test6b; 318 #if __cplusplus >= 201103L 319 // expected-error@+3 {{expected}} 320 // expected-error@-3 {{expected ';' after top level declarator}} 321 #endif 322 323