Richard Smith | 6f9a445 | 2012-11-15 22:54:20 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -verify -fsyntax-only -triple i386-linux -pedantic -fcxx-exceptions -fexceptions %s |
Chris Lattner | 8129edb | 2009-04-12 22:23:27 +0000 | [diff] [blame] | 2 | |
Aaron Ballman | c828620 | 2012-08-28 20:55:40 +0000 | [diff] [blame] | 3 | const char const *x10; // expected-warning {{duplicate 'const' declaration specifier}} |
| 4 | |
Chris Lattner | 8129edb | 2009-04-12 22:23:27 +0000 | [diff] [blame] | 5 | int x(*g); // expected-error {{use of undeclared identifier 'g'}} |
Chris Lattner | 4664649 | 2009-12-07 01:36:53 +0000 | [diff] [blame] | 6 | |
Chris Lattner | a69d0ed | 2009-12-10 02:02:58 +0000 | [diff] [blame] | 7 | struct Type { |
| 8 | int Type; |
| 9 | }; |
Chris Lattner | a1efc8c | 2009-12-10 01:59:24 +0000 | [diff] [blame] | 10 | |
Argyrios Kyrtzidis | 4383e18 | 2010-11-16 18:18:13 +0000 | [diff] [blame] | 11 | // rdar://8365458 |
Fariborz Jahanian | e106a0b | 2011-04-19 21:42:37 +0000 | [diff] [blame] | 12 | // rdar://9132143 |
| 13 | typedef char bool; // expected-error {{redeclaration of C++ built-in type 'bool'}} |
Chris Lattner | 4664649 | 2009-12-07 01:36:53 +0000 | [diff] [blame] | 14 | |
| 15 | // PR4451 - We should recover well from the typo of '::' as ':' in a2. |
| 16 | namespace y { |
Chris Lattner | 932dff7 | 2009-12-10 02:08:07 +0000 | [diff] [blame] | 17 | struct a { }; |
| 18 | typedef int b; |
Chris Lattner | 4664649 | 2009-12-07 01:36:53 +0000 | [diff] [blame] | 19 | } |
| 20 | |
| 21 | y::a a1; |
| 22 | y:a a2; // expected-error {{unexpected ':' in nested name specifier}} |
| 23 | y::a a3 = a2; |
| 24 | |
| 25 | // Some valid colons: |
| 26 | void foo() { |
| 27 | y: // label |
| 28 | y::a s; |
| 29 | |
| 30 | int a = 4; |
| 31 | a = a ? a : a+1; |
| 32 | } |
| 33 | |
| 34 | struct b : y::a {}; |
| 35 | |
| 36 | template <typename T> |
| 37 | class someclass { |
| 38 | |
| 39 | int bar() { |
| 40 | T *P; |
| 41 | return 1 ? P->x : P->y; |
| 42 | } |
| 43 | }; |
Chris Lattner | a1efc8c | 2009-12-10 01:59:24 +0000 | [diff] [blame] | 44 | |
Chris Lattner | e656325 | 2010-06-13 05:34:18 +0000 | [diff] [blame] | 45 | class asm_class_test { |
| 46 | void foo() __asm__("baz"); |
| 47 | }; |
| 48 | |
Richard Smith | eab9d6f | 2012-07-23 05:45:25 +0000 | [diff] [blame] | 49 | enum { fooenum = 1, }; // expected-warning {{commas at the end of enumerator lists are a C++11 extension}} |
Chris Lattner | a1efc8c | 2009-12-10 01:59:24 +0000 | [diff] [blame] | 50 | |
| 51 | struct a { |
| 52 | int Type : fooenum; |
| 53 | }; |
| 54 | |
Chris Lattner | a69d0ed | 2009-12-10 02:02:58 +0000 | [diff] [blame] | 55 | void test(struct Type *P) { |
| 56 | int Type; |
| 57 | Type = 1 ? P->Type : Type; |
Chris Lattner | 932dff7 | 2009-12-10 02:08:07 +0000 | [diff] [blame] | 58 | |
| 59 | Type = (y:b) 4; // expected-error {{unexpected ':' in nested name specifier}} |
| 60 | Type = 1 ? ( |
| 61 | (y:b) // expected-error {{unexpected ':' in nested name specifier}} |
| 62 | 4) : 5; |
Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 63 | } |
Chris Lattner | ae50d50 | 2010-02-02 00:43:15 +0000 | [diff] [blame] | 64 | |
| 65 | struct test4 { |
| 66 | int x // expected-error {{expected ';' at end of declaration list}} |
| 67 | int y; |
| 68 | int z // expected-error {{expected ';' at end of declaration list}} |
| 69 | }; |
John McCall | 2e0a715 | 2010-03-01 18:20:46 +0000 | [diff] [blame] | 70 | |
Richard Smith | 0706df4 | 2011-10-19 21:33:05 +0000 | [diff] [blame] | 71 | // Make sure we know these are legitimate commas and not typos for ';'. |
| 72 | namespace Commas { |
| 73 | struct S { |
| 74 | static int a; |
| 75 | int c, |
| 76 | operator()(); |
| 77 | }; |
| 78 | |
| 79 | int global1, |
| 80 | __attribute__(()) global2, |
| 81 | (global5), |
| 82 | *global6, |
| 83 | &global7 = global1, |
| 84 | &&global8 = static_cast<int&&>(global1), // expected-warning 2{{rvalue reference}} |
| 85 | S::a, |
| 86 | global9, |
| 87 | global10 = 0, |
| 88 | global11 == 0, // expected-error {{did you mean '='}} |
| 89 | global12 __attribute__(()), |
| 90 | global13(0), |
| 91 | global14[2], |
| 92 | global15; |
| 93 | |
| 94 | void g() { |
| 95 | static int a, |
| 96 | b __asm__("ebx"), // expected-error {{expected ';' at end of declaration}} |
| 97 | Statics:return; |
| 98 | } |
| 99 | } |
| 100 | |
John McCall | 2e0a715 | 2010-03-01 18:20:46 +0000 | [diff] [blame] | 101 | // PR5825 |
| 102 | struct test5 {}; |
| 103 | ::new(static_cast<void*>(0)) test5; // expected-error {{expected unqualified-id}} |
Chris Lattner | 5c5db55 | 2010-04-05 18:18:31 +0000 | [diff] [blame] | 104 | |
| 105 | |
| 106 | // PR6782 |
| 107 | template<class T> |
| 108 | class Class1; |
| 109 | |
| 110 | class Class2 { |
| 111 | } // no ; |
| 112 | |
| 113 | typedef Class1<Class2> Type1; // expected-error {{cannot combine with previous 'class' declaration specifier}} |
Fariborz Jahanian | d657742 | 2010-08-16 17:58:53 +0000 | [diff] [blame] | 114 | |
| 115 | // rdar : // 8307865 |
| 116 | struct CodeCompleteConsumer { |
| 117 | }; |
| 118 | |
| 119 | void CodeCompleteConsumer::() { // expected-error {{xpected unqualified-id}} |
| 120 | } |
Chris Lattner | 729ad83 | 2010-11-09 20:14:26 +0000 | [diff] [blame] | 121 | |
| 122 | ; |
| 123 | |
Richard Smith | 0576681 | 2012-08-18 00:55:03 +0000 | [diff] [blame] | 124 | // PR4111 |
| 125 | void f(sqrgl); // expected-error {{unknown type name 'sqrgl'}} |
| 126 | |
Richard Smith | 6f9a445 | 2012-11-15 22:54:20 +0000 | [diff] [blame] | 127 | // PR9903 |
| 128 | struct S { |
| 129 | typedef void a() { }; // expected-error {{function definition declared 'typedef'}} |
| 130 | typedef void c() try { } catch(...) { } // expected-error {{function definition declared 'typedef'}} |
| 131 | int n, m; |
| 132 | typedef S() : n(1), m(2) { } // expected-error {{function definition declared 'typedef'}} |
| 133 | }; |
| 134 | |
Nico Weber | 55fc3a7 | 2013-01-18 18:41:42 +0000 | [diff] [blame] | 135 | |
| 136 | namespace TestIsValidAfterTypeSpecifier { |
Richard Smith | ba65f50 | 2013-01-19 03:48:05 +0000 | [diff] [blame] | 137 | struct s {} v; |
Nico Weber | 55fc3a7 | 2013-01-18 18:41:42 +0000 | [diff] [blame] | 138 | |
| 139 | namespace a { |
| 140 | struct s operator++(struct s a) |
| 141 | { return a; } |
| 142 | } |
| 143 | |
| 144 | namespace b { |
| 145 | // The newline after s should make no difference. |
| 146 | struct s |
| 147 | operator++(struct s a) |
| 148 | { return a; } |
| 149 | } |
| 150 | |
Richard Smith | ba65f50 | 2013-01-19 03:48:05 +0000 | [diff] [blame] | 151 | struct X { |
| 152 | struct s |
| 153 | friend f(); |
| 154 | struct s |
| 155 | virtual f(); |
| 156 | }; |
| 157 | |
| 158 | struct s |
| 159 | &r0 = v; |
| 160 | struct s |
| 161 | bitand r2 = v; |
| 162 | |
Nico Weber | 55fc3a7 | 2013-01-18 18:41:42 +0000 | [diff] [blame] | 163 | } |
| 164 | |
Richard Trieu | db55c04c | 2013-01-26 02:31:38 +0000 | [diff] [blame] | 165 | struct DIE { |
| 166 | void foo() {} |
| 167 | }; |
| 168 | |
| 169 | void test (DIE die, DIE *Die, DIE INT, DIE *FLOAT) { |
| 170 | DIE.foo(); // expected-error {{cannot use dot operator on a type}} |
| 171 | die.foo(); |
| 172 | |
| 173 | DIE->foo(); // expected-error {{cannot use arrow operator on a type}} |
| 174 | Die->foo(); |
| 175 | |
| 176 | int.foo(); // expected-error {{cannot use dot operator on a type}} |
| 177 | INT.foo(); |
| 178 | |
| 179 | float->foo(); // expected-error {{cannot use arrow operator on a type}} |
| 180 | FLOAT->foo(); |
| 181 | } |
| 182 | |
Richard Smith | 8338a9d | 2013-01-29 04:13:32 +0000 | [diff] [blame] | 183 | namespace PR15017 { |
| 184 | template<typename T = struct X { int i; }> struct S {}; // expected-error {{'PR15017::X' can not be defined in a type specifier}} |
| 185 | } |
| 186 | |
Richard Smith | 672edb0 | 2013-02-22 09:15:49 +0000 | [diff] [blame] | 187 | // Ensure we produce at least some diagnostic for attributes in C++98. |
| 188 | [[]] struct S; // expected-error 2{{}} |
| 189 | |
Richard Smith | a38253c | 2013-07-11 05:10:21 +0000 | [diff] [blame] | 190 | namespace PR5066 { |
| 191 | template<typename T> struct X {}; |
| 192 | X<int N> x; // expected-error {{type-id cannot have a name}} |
| 193 | |
| 194 | using T = int (*T)(); // expected-error {{type-id cannot have a name}} expected-warning {{C++11}} |
| 195 | } |
| 196 | |
Chris Lattner | 729ad83 | 2010-11-09 20:14:26 +0000 | [diff] [blame] | 197 | // PR8380 |
| 198 | extern "" // expected-error {{unknown linkage language}} |
| 199 | test6a { ;// expected-error {{C++ requires a type specifier for all declarations}} \ |
| 200 | // expected-error {{expected ';' after top level declarator}} |
| 201 | |
| 202 | int test6b; |