xref: /llvm-project/clang/test/SemaCXX/nested-name-spec.cpp (revision aa400d83e64afe9b6c8601895a7b27dbfc1cd5fb)
1 // RUN: clang -fsyntax-only -verify -std=c++98 %s
2 // XFAIL
3 // fails due to exact diagnostic matching
4 namespace A {
5   struct C {
6     static int cx;
7   };
8   int ax;
9   void Af();
10 }
11 
12 A:: ; // expected-error {{expected unqualified-id}}
13 ::A::ax::undef ex3; // expected-error {{expected a class or namespace}} expected-error {{expected '=', ',', ';', 'asm', or '__attribute__' after declarator}}
14 A::undef1::undef2 ex4; // expected-error {{no member named 'undef1'}} expected-error {{expected '=', ',', ';', 'asm', or '__attribute__' after declarator}}
15 
16 class C2 {
17   void m(); // expected-note{{member declaration nearly matches}}
18 
19   void f(const int& parm); // expected-note{{member declaration nearly matches}}
20   void f(int) const; // expected-note{{member declaration nearly matches}}
21   void f(float);
22 
23   int x;
24 };
25 
26 void C2::m() const { } // expected-error{{out-of-line definition does not match any declaration in 'C2'}}
27 
28 void C2::f(int) { } // expected-error{{out-of-line definition does not match any declaration in 'C2'}}
29 
30 void C2::m() {
31   x = 0;
32 }
33 
34 namespace B {
35   void ::A::Af() {} // expected-error {{definition or redeclaration of 'Af' not in a namespace enclosing 'A'}}
36 }
37 
38 void f1() {
39   void A::Af(); // expected-error {{definition or redeclaration of 'Af' not allowed inside a function}}
40 }
41 
42 void f2() {
43   A:: ; // expected-error {{expected unqualified-id}}
44   A::C::undef = 0; // expected-error {{no member named 'undef'}}
45   ::A::C::cx = 0;
46   int x = ::A::ax = A::C::cx;
47   x = sizeof(A::C);
48   x = sizeof(::A::C::cx);
49 }
50 
51 A::C c1;
52 struct A::C c2;
53 struct S : public A::C {};
54 struct A::undef; // expected-error {{'undef' does not name a tag member in the specified scope}}
55 
56 namespace A2 {
57   typedef int INT;
58   struct RC;
59   struct CC {
60     struct NC;
61   };
62 }
63 
64 struct A2::RC {
65   INT x;
66 };
67 
68 struct A2::CC::NC {
69   void m() {}
70 };
71 
72 void f3() {
73   N::x = 0; // expected-error {{use of undeclared identifier 'N'}}
74   int N;
75   N::x = 0; // expected-error {{expected a class or namespace}}
76   { int A;           A::ax = 0; }
77   { typedef int A;   A::ax = 0; } // expected-error{{expected a class or namespace}}
78   { int A(); A::ax = 0; }
79   { typedef A::C A;  A::ax = 0; } // expected-error {{no member named 'ax'}}
80   { typedef A::C A;  A::cx = 0; }
81 }
82 
83 // make sure the following doesn't hit any asserts
84 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'}}
85 
86 typedef void C2::f5(int); // expected-error{{typedef declarator cannot be qualified}}
87 
88 void f6(int A2::RC::x); // expected-error{{parameter declarator cannot be qualified}}
89 
90 int A2::RC::x; // expected-error{{non-static data member defined out-of-line}}
91 
92 void A2::CC::NC::m(); // 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