Douglas Gregor | 3dde5a3 | 2008-12-16 06:37:47 +0000 | [diff] [blame] | 1 | // RUN: clang -fsyntax-only -verify -std=c++98 %s |
Sebastian Redl | ddf7e99 | 2009-02-08 10:28:44 +0000 | [diff] [blame] | 2 | // fails due to exact diagnostic matching |
Argyrios Kyrtzidis | ef6e647 | 2008-11-08 17:17:31 +0000 | [diff] [blame] | 3 | namespace A { |
| 4 | struct C { |
| 5 | static int cx; |
| 6 | }; |
| 7 | int ax; |
| 8 | void Af(); |
| 9 | } |
| 10 | |
| 11 | A:: ; // expected-error {{expected unqualified-id}} |
Douglas Gregor | 9fa14a5 | 2009-03-06 19:06:37 +0000 | [diff] [blame] | 12 | ::A::ax::undef ex3; // expected-error {{expected a class or namespace}} expected-error {{invalid token after top level declarator}} |
| 13 | A::undef1::undef2 ex4; // expected-error {{no member named 'undef1'}} expected-error {{invalid token after top level declarator}} |
Argyrios Kyrtzidis | ef6e647 | 2008-11-08 17:17:31 +0000 | [diff] [blame] | 14 | |
| 15 | class C2 { |
Douglas Gregor | 584049d | 2008-12-15 23:53:10 +0000 | [diff] [blame] | 16 | void m(); // expected-note{{member declaration nearly matches}} |
| 17 | |
| 18 | void f(const int& parm); // expected-note{{member declaration nearly matches}} |
| 19 | void f(int) const; // expected-note{{member declaration nearly matches}} |
| 20 | void f(float); |
| 21 | |
Argyrios Kyrtzidis | ef6e647 | 2008-11-08 17:17:31 +0000 | [diff] [blame] | 22 | int x; |
| 23 | }; |
| 24 | |
Douglas Gregor | 584049d | 2008-12-15 23:53:10 +0000 | [diff] [blame] | 25 | void C2::m() const { } // expected-error{{out-of-line definition does not match any declaration in 'C2'}} |
| 26 | |
| 27 | void C2::f(int) { } // expected-error{{out-of-line definition does not match any declaration in 'C2'}} |
| 28 | |
Argyrios Kyrtzidis | ef6e647 | 2008-11-08 17:17:31 +0000 | [diff] [blame] | 29 | void C2::m() { |
| 30 | x = 0; |
| 31 | } |
| 32 | |
| 33 | namespace B { |
Chris Lattner | 011bb4e | 2008-11-23 20:28:15 +0000 | [diff] [blame] | 34 | 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] | 35 | } |
| 36 | |
| 37 | void f1() { |
Douglas Gregor | 584049d | 2008-12-15 23:53:10 +0000 | [diff] [blame] | 38 | 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] | 39 | } |
| 40 | |
| 41 | void f2() { |
| 42 | A:: ; // expected-error {{expected unqualified-id}} |
| 43 | A::C::undef = 0; // expected-error {{no member named 'undef'}} |
| 44 | ::A::C::cx = 0; |
| 45 | int x = ::A::ax = A::C::cx; |
| 46 | x = sizeof(A::C); |
| 47 | x = sizeof(::A::C::cx); |
| 48 | } |
| 49 | |
| 50 | A::C c1; |
| 51 | struct A::C c2; |
| 52 | struct S : public A::C {}; |
| 53 | struct A::undef; // expected-error {{'undef' does not name a tag member in the specified scope}} |
| 54 | |
Argyrios Kyrtzidis | 5239304 | 2008-11-09 23:41:00 +0000 | [diff] [blame] | 55 | namespace A2 { |
| 56 | typedef int INT; |
| 57 | struct RC; |
Argyrios Kyrtzidis | 77407b8 | 2008-11-19 18:01:13 +0000 | [diff] [blame] | 58 | struct CC { |
| 59 | struct NC; |
| 60 | }; |
Argyrios Kyrtzidis | 5239304 | 2008-11-09 23:41:00 +0000 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | struct A2::RC { |
| 64 | INT x; |
| 65 | }; |
| 66 | |
Argyrios Kyrtzidis | 77407b8 | 2008-11-19 18:01:13 +0000 | [diff] [blame] | 67 | struct A2::CC::NC { |
| 68 | void m() {} |
| 69 | }; |
| 70 | |
Argyrios Kyrtzidis | ef6e647 | 2008-11-08 17:17:31 +0000 | [diff] [blame] | 71 | void f3() { |
| 72 | N::x = 0; // expected-error {{use of undeclared identifier 'N'}} |
| 73 | int N; |
| 74 | N::x = 0; // expected-error {{expected a class or namespace}} |
| 75 | { int A; A::ax = 0; } |
Douglas Gregor | 3dde5a3 | 2008-12-16 06:37:47 +0000 | [diff] [blame] | 76 | { typedef int A; A::ax = 0; } // expected-error{{expected a class or namespace}} |
| 77 | { int A(); A::ax = 0; } |
Argyrios Kyrtzidis | ef6e647 | 2008-11-08 17:17:31 +0000 | [diff] [blame] | 78 | { typedef A::C A; A::ax = 0; } // expected-error {{no member named 'ax'}} |
| 79 | { typedef A::C A; A::cx = 0; } |
| 80 | } |
Argyrios Kyrtzidis | 08b2c37 | 2008-11-19 15:22:16 +0000 | [diff] [blame] | 81 | |
| 82 | // make sure the following doesn't hit any asserts |
Chris Lattner | 28eb7e9 | 2008-11-23 23:17:07 +0000 | [diff] [blame] | 83 | void f4(undef::C); // expected-error {{use of undeclared identifier 'undef'}} // expected-error {{expected ')'}} expected-note {{to match this '('}} // expected-error {{variable has incomplete type 'void'}} |
Douglas Gregor | 584049d | 2008-12-15 23:53:10 +0000 | [diff] [blame] | 84 | |
| 85 | typedef void C2::f5(int); // expected-error{{typedef declarator cannot be qualified}} |
| 86 | |
| 87 | void f6(int A2::RC::x); // expected-error{{parameter declarator cannot be qualified}} |
| 88 | |
| 89 | int A2::RC::x; // expected-error{{non-static data member defined out-of-line}} |
| 90 | |
Douglas Gregor | 9fa14a5 | 2009-03-06 19:06:37 +0000 | [diff] [blame] | 91 | void A2::CC::NC::m(); // expected-error{{out-of-line declaration of a member must be a definition}} \ |
| 92 | // 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] | 93 | |
| 94 | |
| 95 | namespace E { |
| 96 | int X = 5; |
| 97 | |
| 98 | namespace Nested { |
| 99 | enum E { |
| 100 | X = 0 |
| 101 | }; |
| 102 | |
| 103 | void f() { |
| 104 | return E::X; // expected-error{{expected a class or namespace}} |
| 105 | } |
| 106 | } |
| 107 | } |
Douglas Gregor | 70316a0 | 2008-12-26 15:00:45 +0000 | [diff] [blame] | 108 | |
| 109 | |
| 110 | class Operators { |
| 111 | Operators operator+(const Operators&) const; // expected-note{{member declaration nearly matches}} |
| 112 | operator bool(); |
| 113 | }; |
| 114 | |
| 115 | Operators Operators::operator+(const Operators&) { // expected-error{{out-of-line definition does not match any declaration in 'Operators'}} |
| 116 | Operators ops; |
| 117 | return ops; |
| 118 | } |
| 119 | |
| 120 | Operators Operators::operator+(const Operators&) const { |
| 121 | Operators ops; |
| 122 | return ops; |
| 123 | } |
| 124 | |
| 125 | Operators::operator bool() { |
| 126 | return true; |
| 127 | } |
Douglas Gregor | 4ce205f | 2009-02-06 17:46:57 +0000 | [diff] [blame] | 128 | |
| 129 | namespace A { |
| 130 | void g(int&); // expected-note{{member declaration nearly matches}} |
| 131 | } |
| 132 | |
| 133 | void A::f() {} // expected-error{{out-of-line definition does not match any declaration in 'A'}} |
| 134 | |
| 135 | void A::g(const int&) { } // expected-error{{out-of-line definition does not match any declaration in 'A'}} |
| 136 | |
| 137 | struct Struct { }; |
| 138 | |
| 139 | void Struct::f() { } // expected-error{{out-of-line definition does not match any declaration in 'Struct'}} |
| 140 | |
| 141 | void global_func(int); |
| 142 | void global_func2(int); |
| 143 | |
| 144 | namespace N { |
| 145 | void ::global_func(int) { } // expected-error{{definition or redeclaration of 'global_func' cannot name the global scope}} |
| 146 | |
| 147 | void f(); |
| 148 | // FIXME: if we move this to a separate definition of N, things break! |
| 149 | } |
| 150 | void ::global_func2(int) { } // expected-error{{definition or redeclaration of 'global_func2' cannot name the global scope}} |
| 151 | |
| 152 | void N::f() { } // okay |
Douglas Gregor | 9fa14a5 | 2009-03-06 19:06:37 +0000 | [diff] [blame] | 153 | |
| 154 | X::X() : a(5) { } // expected-error{{use of undeclared identifier 'X'}} \ |
| 155 | // expected-error{{expected function body after function declarator}} |