xref: /llvm-project/clang/test/SemaCXX/nested-name-spec.cpp (revision f7e69d5a77b21fd98e29df84411506527faa62b3)
1 // RUN: clang -fsyntax-only -verify %s
2 namespace A {
3   struct C {
4     static int cx;
5   };
6   int ax;
7   void Af();
8 }
9 
10 A:: ; // expected-error {{expected unqualified-id}}
11 ::A::ax::undef ex3; // expected-error {{expected a class or namespace}} expected-error {{expected '=', ',', ';', 'asm', or '__attribute__' after declarator}}
12 A::undef1::undef2 ex4; // expected-error {{no member named 'undef1'}} expected-error {{expected '=', ',', ';', 'asm', or '__attribute__' after declarator}}
13 
14 class C2 {
15   void m();
16   int x;
17 };
18 
19 void C2::m() {
20   x = 0;
21 }
22 
23 namespace B {
24   void ::A::Af() {} // expected-error {{definition or redeclaration of 'Af' not in a namespace enclosing 'A'}}
25 }
26 
27 void f1() {
28   void A::Af(); // expected-error {{definition or redeclaration of 'Af' not allowed inside a function}}
29 }
30 
31 void f2() {
32   A:: ; // expected-error {{expected unqualified-id}}
33   A::C::undef = 0; // expected-error {{no member named 'undef'}}
34   ::A::C::cx = 0;
35   int x = ::A::ax = A::C::cx;
36   x = sizeof(A::C);
37   x = sizeof(::A::C::cx);
38 }
39 
40 A::C c1;
41 struct A::C c2;
42 struct S : public A::C {};
43 struct A::undef; // expected-error {{'undef' does not name a tag member in the specified scope}}
44 
45 namespace A2 {
46   typedef int INT;
47   struct RC;
48   struct CC {
49     struct NC;
50   };
51 }
52 
53 struct A2::RC {
54   INT x;
55 };
56 
57 struct A2::CC::NC {
58   void m() {}
59 };
60 
61 void f3() {
62   N::x = 0; // expected-error {{use of undeclared identifier 'N'}}
63   int N;
64   N::x = 0; // expected-error {{expected a class or namespace}}
65   { int A;           A::ax = 0; }
66   { enum A {};       A::ax = 0; }
67   { enum A { A };    A::ax = 0; }
68   { typedef int A;   A::ax = 0; }
69   { typedef int A(); A::ax = 0; }
70   { typedef A::C A;  A::ax = 0; } // expected-error {{no member named 'ax'}}
71   { typedef A::C A;  A::cx = 0; }
72 }
73 
74 // make sure the following doesn't hit any asserts
75 void f4(undef::C); // expected-error {{use of undeclared identifier 'undef'}} // expected-error {{expected ')'}} expected-error {{to match this '('}} // expected-error {{variable has incomplete type 'void'}}
76