qual-id-test.cpp revision 2dd078ae50ff7be1fb25ebeedde45e9ab691a4f0
1// RUN: clang-cc -fsyntax-only -verify %s 2namespace A 3{ 4 namespace B 5 { 6 struct base // expected-note{{object type}} 7 { 8 void x() {} 9 void y() {} 10 }; 11 } 12 13 struct member 14 { 15 void foo(); 16 }; 17 18 struct middleman 19 { 20 member * operator->() { return 0; } 21 }; 22 23 struct sub : B::base 24 { 25 void x() {} 26 middleman operator->() { return middleman(); } 27 }; 28} 29 30struct bad 31{ 32 int x(); 33}; 34 35namespace C 36{ 37 void fun() 38 { 39 A::sub a; 40 41 a.x(); 42 43 a.sub::x(); 44 a.base::x(); 45 46 a.B::base::x(); // expected-error{{use of undeclared identifier 'B'}} 47 48 a.A::sub::x(); 49 a.A::B::base::x(); 50 51 a.bad::x(); // expected-error{{type 'struct bad' is not a direct or virtual base of ''struct A::sub''}} 52 53 a->foo(); 54 a->member::foo(); 55 a->A::member::foo(); 56 } 57 58 void fun2() 59 { 60 A::sub *a; 61 62 a->x(); 63 64 a->sub::x(); 65 a->base::x(); 66 67 a->B::base::x(); // expected-error{{use of undeclared identifier 'B'}} 68 69 a->A::sub::x(); 70 a->A::B::base::x(); 71 72 a->bad::x(); // expected-error{{type 'struct bad' is not a direct or virtual base of ''struct A::sub''}} 73 74 (*a)->foo(); 75 (*a)->member::foo(); 76 (*a)->A::member::foo(); 77 } 78 79 void fun3() 80 { 81 int i; 82 i.foo(); // expected-error{{member reference base type 'int' is not a structure or union}} 83 } 84 85 void fun4a() { 86 A::sub *a; 87 88 typedef A::member base; // expected-note{{current scope}} 89 a->base::x(); // expected-error{{ambiguous}} 90 } 91 92 void fun4b() { 93 A::sub *a; 94 95 typedef A::B::base base; 96 a->base::x(); 97 } 98 99 template<typename T> 100 void fun5() 101 { 102 T a; 103 a.x(); 104 a->foo(); 105 106#if 0 107 // FIXME: We need the notion of identifiers as dependent 108 // nested-name-specifiers without a prefix for this code to work. 109 110 // Things that work for the wrong reason 111 a.A::sub::x(); 112 a.A::B::base::x(); 113 a->A::member::foo(); 114 115 // Things that work, but shouldn't 116 a.bad::x(); 117 118 // Things that fail, but shouldn't 119 a.sub::x(); // xpected-error{{use of undeclared identifier 'sub'}} 120 a.base::x(); // xpected-error{{use of undeclared identifier 'base'}} 121 a.B::base::x(); // xpected-error{{use of undeclared identifier 'B'}} 122 a->member::foo(); // xpected-error{{use of undeclared identifier 'member'}} 123#endif 124 } 125} 126 127// PR4703 128struct a { 129 int a; 130 static int sa; 131}; 132 133a a; 134 135int a::sa = a.a; 136