Daniel Dunbar | a75a92d | 2009-11-29 09:31:53 +0000 | [diff] [blame] | 1 | // RUN: clang-cc -fsyntax-only -std=c++98 -verify %s |
Argyrios Kyrtzidis | ef6e647 | 2008-11-08 17:17:31 +0000 | [diff] [blame] | 2 | namespace A { |
| 3 | struct C { |
| 4 | static int cx; |
Douglas Gregor | 656de63 | 2009-03-11 23:52:16 +0000 | [diff] [blame] | 5 | |
| 6 | static int cx2; |
| 7 | |
| 8 | static int Ag1(); |
| 9 | static int Ag2(); |
Argyrios Kyrtzidis | ef6e647 | 2008-11-08 17:17:31 +0000 | [diff] [blame] | 10 | }; |
| 11 | int ax; |
| 12 | void Af(); |
| 13 | } |
| 14 | |
| 15 | A:: ; // expected-error {{expected unqualified-id}} |
Douglas Gregor | a786fdb | 2009-10-13 23:27:22 +0000 | [diff] [blame] | 16 | ::A::ax::undef ex3; // expected-error {{no member named}} |
| 17 | A::undef1::undef2 ex4; // expected-error {{no member named 'undef1'}} |
Argyrios Kyrtzidis | ef6e647 | 2008-11-08 17:17:31 +0000 | [diff] [blame] | 18 | |
Douglas Gregor | 656de63 | 2009-03-11 23:52:16 +0000 | [diff] [blame] | 19 | int A::C::Ag1() { return 0; } |
| 20 | |
Douglas Gregor | a3a8351 | 2009-04-01 23:51:29 +0000 | [diff] [blame] | 21 | static int A::C::Ag2() { return 0; } // expected-error{{'static' can}} |
Douglas Gregor | 656de63 | 2009-03-11 23:52:16 +0000 | [diff] [blame] | 22 | |
| 23 | int A::C::cx = 17; |
| 24 | |
| 25 | |
Douglas Gregor | a3a8351 | 2009-04-01 23:51:29 +0000 | [diff] [blame] | 26 | static int A::C::cx2 = 17; // expected-error{{'static' can}} |
Douglas Gregor | 656de63 | 2009-03-11 23:52:16 +0000 | [diff] [blame] | 27 | |
Argyrios Kyrtzidis | ef6e647 | 2008-11-08 17:17:31 +0000 | [diff] [blame] | 28 | class C2 { |
Douglas Gregor | 584049d | 2008-12-15 23:53:10 +0000 | [diff] [blame] | 29 | void m(); // expected-note{{member declaration nearly matches}} |
| 30 | |
| 31 | void f(const int& parm); // expected-note{{member declaration nearly matches}} |
| 32 | void f(int) const; // expected-note{{member declaration nearly matches}} |
| 33 | void f(float); |
| 34 | |
Argyrios Kyrtzidis | ef6e647 | 2008-11-08 17:17:31 +0000 | [diff] [blame] | 35 | int x; |
| 36 | }; |
| 37 | |
Douglas Gregor | 3f09327 | 2009-10-13 21:16:44 +0000 | [diff] [blame] | 38 | void C2::m() const { } // expected-error{{out-of-line definition of 'm' does not match any declaration in 'class C2'}} |
Douglas Gregor | 584049d | 2008-12-15 23:53:10 +0000 | [diff] [blame] | 39 | |
Douglas Gregor | 3f09327 | 2009-10-13 21:16:44 +0000 | [diff] [blame] | 40 | void C2::f(int) { } // expected-error{{out-of-line definition of 'f' does not match any declaration in 'class C2'}} |
Douglas Gregor | 584049d | 2008-12-15 23:53:10 +0000 | [diff] [blame] | 41 | |
Argyrios Kyrtzidis | ef6e647 | 2008-11-08 17:17:31 +0000 | [diff] [blame] | 42 | void C2::m() { |
| 43 | x = 0; |
| 44 | } |
| 45 | |
| 46 | namespace B { |
Chris Lattner | 011bb4e | 2008-11-23 20:28:15 +0000 | [diff] [blame] | 47 | void ::A::Af() {} // expected-error {{definition or redeclaration of 'Af' not in a namespace enclosing 'A'}} |
Argyrios Kyrtzidis | ef6e647 | 2008-11-08 17:17:31 +0000 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | void f1() { |
Douglas Gregor | 584049d | 2008-12-15 23:53:10 +0000 | [diff] [blame] | 51 | void A::Af(); // expected-error {{definition or redeclaration of 'Af' not allowed inside a function}} |
Argyrios Kyrtzidis | ef6e647 | 2008-11-08 17:17:31 +0000 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | void f2() { |
| 55 | A:: ; // expected-error {{expected unqualified-id}} |
| 56 | A::C::undef = 0; // expected-error {{no member named 'undef'}} |
| 57 | ::A::C::cx = 0; |
| 58 | int x = ::A::ax = A::C::cx; |
| 59 | x = sizeof(A::C); |
| 60 | x = sizeof(::A::C::cx); |
| 61 | } |
| 62 | |
| 63 | A::C c1; |
| 64 | struct A::C c2; |
| 65 | struct S : public A::C {}; |
| 66 | struct A::undef; // expected-error {{'undef' does not name a tag member in the specified scope}} |
| 67 | |
Argyrios Kyrtzidis | 5239304 | 2008-11-09 23:41:00 +0000 | [diff] [blame] | 68 | namespace A2 { |
| 69 | typedef int INT; |
| 70 | struct RC; |
Argyrios Kyrtzidis | 77407b8 | 2008-11-19 18:01:13 +0000 | [diff] [blame] | 71 | struct CC { |
| 72 | struct NC; |
| 73 | }; |
Argyrios Kyrtzidis | 5239304 | 2008-11-09 23:41:00 +0000 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | struct A2::RC { |
| 77 | INT x; |
| 78 | }; |
| 79 | |
Argyrios Kyrtzidis | 77407b8 | 2008-11-19 18:01:13 +0000 | [diff] [blame] | 80 | struct A2::CC::NC { |
| 81 | void m() {} |
| 82 | }; |
| 83 | |
Argyrios Kyrtzidis | ef6e647 | 2008-11-08 17:17:31 +0000 | [diff] [blame] | 84 | void f3() { |
| 85 | N::x = 0; // expected-error {{use of undeclared identifier 'N'}} |
| 86 | int N; |
| 87 | N::x = 0; // expected-error {{expected a class or namespace}} |
| 88 | { int A; A::ax = 0; } |
Douglas Gregor | 3dde5a3 | 2008-12-16 06:37:47 +0000 | [diff] [blame] | 89 | { typedef int A; A::ax = 0; } // expected-error{{expected a class or namespace}} |
Argyrios Kyrtzidis | ef6e647 | 2008-11-08 17:17:31 +0000 | [diff] [blame] | 90 | { typedef A::C A; A::ax = 0; } // expected-error {{no member named 'ax'}} |
| 91 | { typedef A::C A; A::cx = 0; } |
| 92 | } |
Argyrios Kyrtzidis | 08b2c37 | 2008-11-19 15:22:16 +0000 | [diff] [blame] | 93 | |
| 94 | // make sure the following doesn't hit any asserts |
Chris Lattner | 8129edb | 2009-04-12 22:23:27 +0000 | [diff] [blame] | 95 | void f4(undef::C); // expected-error {{use of undeclared identifier 'undef'}} \ |
| 96 | expected-error {{variable has incomplete type 'void'}} |
Douglas Gregor | 584049d | 2008-12-15 23:53:10 +0000 | [diff] [blame] | 97 | |
| 98 | typedef void C2::f5(int); // expected-error{{typedef declarator cannot be qualified}} |
| 99 | |
| 100 | void f6(int A2::RC::x); // expected-error{{parameter declarator cannot be qualified}} |
| 101 | |
| 102 | int A2::RC::x; // expected-error{{non-static data member defined out-of-line}} |
| 103 | |
Douglas Gregor | 2dc0e64 | 2009-03-23 23:06:20 +0000 | [diff] [blame] | 104 | void A2::CC::NC::m(); // expected-error{{out-of-line declaration of a member must be a definition}} |
Douglas Gregor | 3dde5a3 | 2008-12-16 06:37:47 +0000 | [diff] [blame] | 105 | |
| 106 | |
| 107 | namespace E { |
| 108 | int X = 5; |
| 109 | |
| 110 | namespace Nested { |
| 111 | enum E { |
| 112 | X = 0 |
| 113 | }; |
| 114 | |
| 115 | void f() { |
| 116 | return E::X; // expected-error{{expected a class or namespace}} |
| 117 | } |
| 118 | } |
| 119 | } |
Douglas Gregor | 70316a0 | 2008-12-26 15:00:45 +0000 | [diff] [blame] | 120 | |
| 121 | |
| 122 | class Operators { |
| 123 | Operators operator+(const Operators&) const; // expected-note{{member declaration nearly matches}} |
| 124 | operator bool(); |
| 125 | }; |
| 126 | |
Douglas Gregor | 3f09327 | 2009-10-13 21:16:44 +0000 | [diff] [blame] | 127 | Operators Operators::operator+(const Operators&) { // expected-error{{out-of-line definition of 'operator+' does not match any declaration in 'class Operators'}} |
Douglas Gregor | 70316a0 | 2008-12-26 15:00:45 +0000 | [diff] [blame] | 128 | Operators ops; |
| 129 | return ops; |
| 130 | } |
| 131 | |
| 132 | Operators Operators::operator+(const Operators&) const { |
| 133 | Operators ops; |
| 134 | return ops; |
| 135 | } |
| 136 | |
| 137 | Operators::operator bool() { |
| 138 | return true; |
| 139 | } |
Douglas Gregor | 4ce205f | 2009-02-06 17:46:57 +0000 | [diff] [blame] | 140 | |
| 141 | namespace A { |
| 142 | void g(int&); // expected-note{{member declaration nearly matches}} |
| 143 | } |
| 144 | |
Douglas Gregor | 3f09327 | 2009-10-13 21:16:44 +0000 | [diff] [blame] | 145 | void A::f() {} // expected-error{{out-of-line definition of 'f' does not match any declaration in namespace 'A'}} |
Douglas Gregor | 4ce205f | 2009-02-06 17:46:57 +0000 | [diff] [blame] | 146 | |
Douglas Gregor | 3f09327 | 2009-10-13 21:16:44 +0000 | [diff] [blame] | 147 | void A::g(const int&) { } // expected-error{{out-of-line definition of 'g' does not match any declaration in namespace 'A'}} |
Douglas Gregor | 4ce205f | 2009-02-06 17:46:57 +0000 | [diff] [blame] | 148 | |
| 149 | struct Struct { }; |
| 150 | |
Douglas Gregor | 3f09327 | 2009-10-13 21:16:44 +0000 | [diff] [blame] | 151 | void Struct::f() { } // expected-error{{out-of-line definition of 'f' does not match any declaration in 'struct Struct'}} |
Douglas Gregor | 4ce205f | 2009-02-06 17:46:57 +0000 | [diff] [blame] | 152 | |
| 153 | void global_func(int); |
| 154 | void global_func2(int); |
| 155 | |
| 156 | namespace N { |
| 157 | void ::global_func(int) { } // expected-error{{definition or redeclaration of 'global_func' cannot name the global scope}} |
| 158 | |
| 159 | void f(); |
| 160 | // FIXME: if we move this to a separate definition of N, things break! |
| 161 | } |
| 162 | void ::global_func2(int) { } // expected-error{{definition or redeclaration of 'global_func2' cannot name the global scope}} |
| 163 | |
| 164 | void N::f() { } // okay |
Douglas Gregor | 9fa14a5 | 2009-03-06 19:06:37 +0000 | [diff] [blame] | 165 | |
Douglas Gregor | 4fdf1fa | 2009-03-11 16:48:53 +0000 | [diff] [blame] | 166 | struct Y; // expected-note{{forward declaration of 'struct Y'}} |
| 167 | Y::foo y; // expected-error{{incomplete type 'struct Y' named in nested name specifier}} \ |
Douglas Gregor | a786fdb | 2009-10-13 23:27:22 +0000 | [diff] [blame] | 168 | // expected-error{{no type named 'foo' in}} |
Douglas Gregor | 4fdf1fa | 2009-03-11 16:48:53 +0000 | [diff] [blame] | 169 | |
Douglas Gregor | 9fa14a5 | 2009-03-06 19:06:37 +0000 | [diff] [blame] | 170 | X::X() : a(5) { } // expected-error{{use of undeclared identifier 'X'}} \ |
Anders Carlsson | a7b3521 | 2009-03-25 02:58:17 +0000 | [diff] [blame] | 171 | // expected-error{{C++ requires a type specifier for all declarations}} \ |
| 172 | // expected-error{{only constructors take base initializers}} |
Chris Lattner | c8e27cc | 2009-06-26 04:27:47 +0000 | [diff] [blame] | 173 | |
Argyrios Kyrtzidis | f37006b | 2009-07-21 06:43:26 +0000 | [diff] [blame] | 174 | struct foo_S { |
| 175 | static bool value; |
| 176 | }; |
| 177 | bool (foo_S::value); |
Chris Lattner | c8e27cc | 2009-06-26 04:27:47 +0000 | [diff] [blame] | 178 | |
| 179 | |
| 180 | namespace somens { |
| 181 | struct a { }; |
| 182 | } |
| 183 | |
| 184 | template <typename T> |
| 185 | class foo { |
| 186 | }; |
| 187 | |
| 188 | |
Chris Lattner | 1ade4ca | 2009-12-06 20:58:07 +0000 | [diff] [blame^] | 189 | // PR4452 |
| 190 | // FIXME: This error recovery sucks. |
| 191 | foo<somens:a> a2; // expected-error {{unexpected namespace name 'somens': expected expression}} \ |
| 192 | expected-error {{C++ requires a type specifier for all declarations}} |
Chris Lattner | c8e27cc | 2009-06-26 04:27:47 +0000 | [diff] [blame] | 193 | |
Chris Lattner | 1ade4ca | 2009-12-06 20:58:07 +0000 | [diff] [blame^] | 194 | somens::a a3 = a2; |
Chris Lattner | c8e27cc | 2009-06-26 04:27:47 +0000 | [diff] [blame] | 195 | |
| 196 | |
| 197 | |
| 198 | |