1 // RUN: clang -fsyntax-only -verify -std=c++98 %s 2 // fails due to exact diagnostic matching 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}} 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}} 14 15 class C2 { 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 22 int x; 23 }; 24 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 29 void C2::m() { 30 x = 0; 31 } 32 33 namespace B { 34 void ::A::Af() {} // expected-error {{definition or redeclaration of 'Af' not in a namespace enclosing 'A'}} 35 } 36 37 void f1() { 38 void A::Af(); // expected-error {{definition or redeclaration of 'Af' not allowed inside a function}} 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 55 namespace A2 { 56 typedef int INT; 57 struct RC; 58 struct CC { 59 struct NC; 60 }; 61 } 62 63 struct A2::RC { 64 INT x; 65 }; 66 67 struct A2::CC::NC { 68 void m() {} 69 }; 70 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; } 76 { typedef int A; A::ax = 0; } // expected-error{{expected a class or namespace}} 77 { int A(); A::ax = 0; } 78 { typedef A::C A; A::ax = 0; } // expected-error {{no member named 'ax'}} 79 { typedef A::C A; A::cx = 0; } 80 } 81 82 // make sure the following doesn't hit any asserts 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'}} 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 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}} 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 } 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 } 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 153 154 X::X() : a(5) { } // expected-error{{use of undeclared identifier 'X'}} \ 155 // expected-error{{expected function body after function declarator}} 156