Richard Smith | c0a5d5b | 2014-01-10 21:27:55 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -verify -fsyntax-only -triple i386-linux -pedantic-errors -fcxx-exceptions -fexceptions %s |
Charles Li | 1a88adb | 2016-04-14 23:47:07 +0000 | [diff] [blame] | 2 | // RUN: %clang_cc1 -verify -fsyntax-only -triple i386-linux -pedantic-errors -fcxx-exceptions -fexceptions -std=c++98 %s |
| 3 | // RUN: %clang_cc1 -verify -fsyntax-only -triple i386-linux -pedantic-errors -fcxx-exceptions -fexceptions -std=c++11 %s |
Chris Lattner | 869c661 | 2009-04-12 22:23:27 +0000 | [diff] [blame] | 4 | |
Richard Smith | c0a5d5b | 2014-01-10 21:27:55 +0000 | [diff] [blame] | 5 | const char const *x10; // expected-error {{duplicate 'const' declaration specifier}} |
Aaron Ballman | 3731b33 | 2012-08-28 20:55:40 +0000 | [diff] [blame] | 6 | |
Chris Lattner | 869c661 | 2009-04-12 22:23:27 +0000 | [diff] [blame] | 7 | int x(*g); // expected-error {{use of undeclared identifier 'g'}} |
Chris Lattner | 1c42803 | 2009-12-07 01:36:53 +0000 | [diff] [blame] | 8 | |
Chris Lattner | 244b96b | 2009-12-10 02:02:58 +0000 | [diff] [blame] | 9 | struct Type { |
| 10 | int Type; |
| 11 | }; |
Chris Lattner | 17c3b1f | 2009-12-10 01:59:24 +0000 | [diff] [blame] | 12 | |
Argyrios Kyrtzidis | 20ee5ae | 2010-11-16 18:18:13 +0000 | [diff] [blame] | 13 | // rdar://8365458 |
Fariborz Jahanian | 2b05999 | 2011-04-19 21:42:37 +0000 | [diff] [blame] | 14 | // rdar://9132143 |
| 15 | typedef char bool; // expected-error {{redeclaration of C++ built-in type 'bool'}} |
Chris Lattner | 1c42803 | 2009-12-07 01:36:53 +0000 | [diff] [blame] | 16 | |
| 17 | // PR4451 - We should recover well from the typo of '::' as ':' in a2. |
| 18 | namespace y { |
Chris Lattner | 3c674cf | 2009-12-10 02:08:07 +0000 | [diff] [blame] | 19 | struct a { }; |
| 20 | typedef int b; |
Chris Lattner | 1c42803 | 2009-12-07 01:36:53 +0000 | [diff] [blame] | 21 | } |
| 22 | |
| 23 | y::a a1; |
| 24 | y:a a2; // expected-error {{unexpected ':' in nested name specifier}} |
| 25 | y::a a3 = a2; |
| 26 | |
| 27 | // Some valid colons: |
| 28 | void foo() { |
| 29 | y: // label |
| 30 | y::a s; |
| 31 | |
| 32 | int a = 4; |
| 33 | a = a ? a : a+1; |
| 34 | } |
| 35 | |
| 36 | struct b : y::a {}; |
| 37 | |
| 38 | template <typename T> |
| 39 | class someclass { |
| 40 | |
| 41 | int bar() { |
| 42 | T *P; |
| 43 | return 1 ? P->x : P->y; |
| 44 | } |
| 45 | }; |
Chris Lattner | 17c3b1f | 2009-12-10 01:59:24 +0000 | [diff] [blame] | 46 | |
Chris Lattner | f3d3b36 | 2010-06-13 05:34:18 +0000 | [diff] [blame] | 47 | class asm_class_test { |
| 48 | void foo() __asm__("baz"); |
| 49 | }; |
| 50 | |
Charles Li | 1a88adb | 2016-04-14 23:47:07 +0000 | [diff] [blame] | 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 |
Chris Lattner | 17c3b1f | 2009-12-10 01:59:24 +0000 | [diff] [blame] | 55 | |
| 56 | struct a { |
| 57 | int Type : fooenum; |
| 58 | }; |
| 59 | |
Chris Lattner | 244b96b | 2009-12-10 02:02:58 +0000 | [diff] [blame] | 60 | void test(struct Type *P) { |
| 61 | int Type; |
| 62 | Type = 1 ? P->Type : Type; |
Chris Lattner | 3c674cf | 2009-12-10 02:08:07 +0000 | [diff] [blame] | 63 | |
| 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; |
Daniel Dunbar | 8fbe78f | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 68 | } |
Chris Lattner | 916dbf1 | 2010-02-02 00:43:15 +0000 | [diff] [blame] | 69 | |
| 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}} |
| 74 | }; |
John McCall | 8bc2a70 | 2010-03-01 18:20:46 +0000 | [diff] [blame] | 75 | |
Richard Smith | 09f76ee | 2011-10-19 21:33:05 +0000 | [diff] [blame] | 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()(); |
| 82 | }; |
| 83 | |
| 84 | int global1, |
| 85 | __attribute__(()) global2, |
| 86 | (global5), |
| 87 | *global6, |
| 88 | &global7 = global1, |
Charles Li | 1a88adb | 2016-04-14 23:47:07 +0000 | [diff] [blame] | 89 | &&global8 = static_cast<int&&>(global1), |
| 90 | #if __cplusplus <= 199711L |
| 91 | // expected-error@-2 2{{rvalue references are a C++11 extension}} |
| 92 | #endif |
| 93 | |
Richard Smith | 09f76ee | 2011-10-19 21:33:05 +0000 | [diff] [blame] | 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; |
| 102 | |
| 103 | void g() { |
| 104 | static int a, |
| 105 | b __asm__("ebx"), // expected-error {{expected ';' at end of declaration}} |
| 106 | Statics:return; |
| 107 | } |
| 108 | } |
| 109 | |
John McCall | 8bc2a70 | 2010-03-01 18:20:46 +0000 | [diff] [blame] | 110 | // PR5825 |
| 111 | struct test5 {}; |
| 112 | ::new(static_cast<void*>(0)) test5; // expected-error {{expected unqualified-id}} |
Chris Lattner | 005fc1b | 2010-04-05 18:18:31 +0000 | [diff] [blame] | 113 | |
| 114 | |
| 115 | // PR6782 |
| 116 | template<class T> |
| 117 | class Class1; |
| 118 | |
| 119 | class Class2 { |
Richard Smith | 404dfb4 | 2013-11-19 22:47:36 +0000 | [diff] [blame] | 120 | } // expected-error {{expected ';' after class}} |
Chris Lattner | 005fc1b | 2010-04-05 18:18:31 +0000 | [diff] [blame] | 121 | |
Richard Smith | 404dfb4 | 2013-11-19 22:47:36 +0000 | [diff] [blame] | 122 | typedef Class1<Class2> Type1; |
Fariborz Jahanian | 055068d | 2010-08-16 17:58:53 +0000 | [diff] [blame] | 123 | |
| 124 | // rdar : // 8307865 |
| 125 | struct CodeCompleteConsumer { |
| 126 | }; |
| 127 | |
| 128 | void CodeCompleteConsumer::() { // expected-error {{xpected unqualified-id}} |
| 129 | } |
Chris Lattner | 0786544 | 2010-11-09 20:14:26 +0000 | [diff] [blame] | 130 | |
| 131 | ; |
| 132 | |
Richard Smith | 4f605af | 2012-08-18 00:55:03 +0000 | [diff] [blame] | 133 | // PR4111 |
| 134 | void f(sqrgl); // expected-error {{unknown type name 'sqrgl'}} |
| 135 | |
Richard Smith | 2603b09 | 2012-11-15 22:54:20 +0000 | [diff] [blame] | 136 | // PR9903 |
| 137 | struct S { |
| 138 | typedef void a() { }; // expected-error {{function definition declared 'typedef'}} |
| 139 | typedef void c() try { } catch(...) { } // expected-error {{function definition declared 'typedef'}} |
| 140 | int n, m; |
| 141 | typedef S() : n(1), m(2) { } // expected-error {{function definition declared 'typedef'}} |
| 142 | }; |
| 143 | |
Nico Weber | 0bba2d1 | 2013-01-18 18:41:42 +0000 | [diff] [blame] | 144 | |
| 145 | namespace TestIsValidAfterTypeSpecifier { |
Richard Smith | 1ac67d1 | 2013-01-19 03:48:05 +0000 | [diff] [blame] | 146 | struct s {} v; |
Nico Weber | 0bba2d1 | 2013-01-18 18:41:42 +0000 | [diff] [blame] | 147 | |
| 148 | namespace a { |
| 149 | struct s operator++(struct s a) |
| 150 | { return a; } |
| 151 | } |
| 152 | |
| 153 | namespace b { |
| 154 | // The newline after s should make no difference. |
| 155 | struct s |
| 156 | operator++(struct s a) |
| 157 | { return a; } |
| 158 | } |
| 159 | |
Richard Smith | 1ac67d1 | 2013-01-19 03:48:05 +0000 | [diff] [blame] | 160 | struct X { |
| 161 | struct s |
| 162 | friend f(); |
| 163 | struct s |
| 164 | virtual f(); |
| 165 | }; |
| 166 | |
| 167 | struct s |
| 168 | &r0 = v; |
| 169 | struct s |
| 170 | bitand r2 = v; |
| 171 | |
Nico Weber | 0bba2d1 | 2013-01-18 18:41:42 +0000 | [diff] [blame] | 172 | } |
| 173 | |
Richard Trieu | 9c67267 | 2013-01-26 02:31:38 +0000 | [diff] [blame] | 174 | struct DIE { |
| 175 | void foo() {} |
| 176 | }; |
| 177 | |
| 178 | void test (DIE die, DIE *Die, DIE INT, DIE *FLOAT) { |
| 179 | DIE.foo(); // expected-error {{cannot use dot operator on a type}} |
| 180 | die.foo(); |
| 181 | |
| 182 | DIE->foo(); // expected-error {{cannot use arrow operator on a type}} |
| 183 | Die->foo(); |
| 184 | |
| 185 | int.foo(); // expected-error {{cannot use dot operator on a type}} |
| 186 | INT.foo(); |
| 187 | |
| 188 | float->foo(); // expected-error {{cannot use arrow operator on a type}} |
| 189 | FLOAT->foo(); |
| 190 | } |
| 191 | |
Richard Smith | 52c5b87 | 2013-01-29 04:13:32 +0000 | [diff] [blame] | 192 | namespace PR15017 { |
Ismail Pazarbasi | 025f428 | 2014-03-07 22:36:23 +0000 | [diff] [blame] | 193 | template<typename T = struct X { int i; }> struct S {}; // expected-error {{'PR15017::X' cannot be defined in a type specifier}} |
Richard Smith | 52c5b87 | 2013-01-29 04:13:32 +0000 | [diff] [blame] | 194 | } |
| 195 | |
Richard Smith | 4cabd04 | 2013-02-22 09:15:49 +0000 | [diff] [blame] | 196 | // Ensure we produce at least some diagnostic for attributes in C++98. |
Charles Li | 1a88adb | 2016-04-14 23:47:07 +0000 | [diff] [blame] | 197 | [[]] struct S; |
| 198 | #if __cplusplus <= 199711L |
| 199 | // expected-error@-2 {{expected expression}} |
| 200 | // expected-error@-3 {{expected unqualified-id}} |
| 201 | #else |
| 202 | // expected-error@-5 {{an attribute list cannot appear here}} |
| 203 | #endif |
Richard Smith | 4cabd04 | 2013-02-22 09:15:49 +0000 | [diff] [blame] | 204 | |
Richard Trieu | 2f58696 | 2013-09-05 02:31:33 +0000 | [diff] [blame] | 205 | namespace test7 { |
| 206 | struct Foo { |
| 207 | void a(); |
| 208 | void b(); |
| 209 | }; |
| 210 | |
| 211 | void Foo:: |
| 212 | // Comment! |
| 213 | a() {} |
| 214 | |
| 215 | |
| 216 | void Foo:: // expected-error {{expected unqualified-id}} |
| 217 | // Comment! |
| 218 | } |
| 219 | |
Benjamin Kramer | 5fc787f | 2013-10-10 12:24:40 +0000 | [diff] [blame] | 220 | void test8() { |
| 221 | struct {} o; |
| 222 | // This used to crash. |
| 223 | (&o)->(); // expected-error{{expected unqualified-id}} |
| 224 | } |
| 225 | |
Richard Smith | 9ce302e | 2013-07-11 05:10:21 +0000 | [diff] [blame] | 226 | namespace PR5066 { |
| 227 | template<typename T> struct X {}; |
| 228 | X<int N> x; // expected-error {{type-id cannot have a name}} |
| 229 | |
Charles Li | 1a88adb | 2016-04-14 23:47:07 +0000 | [diff] [blame] | 230 | using T = int (*T)(); // expected-error {{type-id cannot have a name}} |
| 231 | #if __cplusplus <= 199711L |
| 232 | // expected-error@-2 {{alias declarations are a C++11 extensio}} |
| 233 | #endif |
| 234 | |
Richard Smith | 9ce302e | 2013-07-11 05:10:21 +0000 | [diff] [blame] | 235 | } |
| 236 | |
David Majnemer | a5e9255 | 2013-09-22 01:24:26 +0000 | [diff] [blame] | 237 | namespace PR17255 { |
| 238 | void foo() { |
Charles Li | 1a88adb | 2016-04-14 23:47:07 +0000 | [diff] [blame] | 239 | typename A::template B<>; // expected-error {{use of undeclared identifier 'A'}} |
| 240 | #if __cplusplus <= 199711L |
| 241 | // expected-error@-2 {{'template' keyword outside of a template}} |
| 242 | #endif |
| 243 | // expected-error@-4 {{expected a qualified name after 'typename'}} |
David Majnemer | a5e9255 | 2013-09-22 01:24:26 +0000 | [diff] [blame] | 244 | } |
| 245 | } |
| 246 | |
Richard Smith | fb8b7b9 | 2013-10-15 00:00:26 +0000 | [diff] [blame] | 247 | namespace PR17567 { |
| 248 | struct Foobar { // expected-note 2{{declared here}} |
| 249 | FooBar(); // expected-error {{missing return type for function 'FooBar'; did you mean the constructor name 'Foobar'?}} |
| 250 | ~FooBar(); // expected-error {{expected the class name after '~' to name a destructor}} |
| 251 | }; |
| 252 | FooBar::FooBar() {} // expected-error {{undeclared}} expected-error {{missing return type}} |
| 253 | FooBar::~FooBar() {} // expected-error {{undeclared}} expected-error {{expected the class name}} |
| 254 | } |
| 255 | |
Richard Smith | c0a5d5b | 2014-01-10 21:27:55 +0000 | [diff] [blame] | 256 | namespace DuplicateFriend { |
| 257 | struct A { |
| 258 | friend void friend f(); // expected-warning {{duplicate 'friend' declaration specifier}} |
| 259 | friend struct B friend; // expected-warning {{duplicate 'friend' declaration specifier}} |
Charles Li | 1a88adb | 2016-04-14 23:47:07 +0000 | [diff] [blame] | 260 | #if __cplusplus >= 201103L |
| 261 | // expected-error@-2 {{'friend' must appear first in a non-function declaration}} |
| 262 | #endif |
Richard Smith | c0a5d5b | 2014-01-10 21:27:55 +0000 | [diff] [blame] | 263 | }; |
| 264 | } |
| 265 | |
Chris Lattner | 0786544 | 2010-11-09 20:14:26 +0000 | [diff] [blame] | 266 | // PR8380 |
| 267 | extern "" // expected-error {{unknown linkage language}} |
Charles Li | 1a88adb | 2016-04-14 23:47:07 +0000 | [diff] [blame] | 268 | test6a { ;// expected-error {{C++ requires a type specifier for all declarations}} |
| 269 | #if __cplusplus <= 199711L |
| 270 | // expected-error@-2 {{expected ';' after top level declarator}} |
| 271 | #else |
| 272 | // expected-error@-4 {{expected expression}} |
| 273 | // expected-note@-5 {{to match this}} |
| 274 | #endif |
Chris Lattner | 0786544 | 2010-11-09 20:14:26 +0000 | [diff] [blame] | 275 | |
| 276 | int test6b; |
Charles Li | 1a88adb | 2016-04-14 23:47:07 +0000 | [diff] [blame] | 277 | #if __cplusplus >= 201103L |
| 278 | // expected-error@+3 {{expected}} |
| 279 | // expected-error@-3 {{expected ';' after top level declarator}} |
| 280 | #endif |
| 281 | |