1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -verify %s 2*f4a2713aSLionel Sambuc 3*f4a2713aSLionel Sambuc // This is just the test for [namespace.udecl]p4 with 'using' 4*f4a2713aSLionel Sambuc // uniformly stripped out. 5*f4a2713aSLionel Sambuc 6*f4a2713aSLionel Sambuc // C++03 [namespace.udecl]p4: 7*f4a2713aSLionel Sambuc // A using-declaration used as a member-declaration shall refer to a 8*f4a2713aSLionel Sambuc // member of a base class of the class being defined, shall refer to 9*f4a2713aSLionel Sambuc // a member of an anonymous union that is a member of a base class 10*f4a2713aSLionel Sambuc // of the class being defined, or shall refer to an enumerator for 11*f4a2713aSLionel Sambuc // an enumeration type that is a member of a base class of the class 12*f4a2713aSLionel Sambuc // being defined. 13*f4a2713aSLionel Sambuc 14*f4a2713aSLionel Sambuc // There is no directly analogous paragraph in C++0x, and the feature 15*f4a2713aSLionel Sambuc // works sufficiently differently there that it needs a separate test. 16*f4a2713aSLionel Sambuc 17*f4a2713aSLionel Sambuc namespace test0 { 18*f4a2713aSLionel Sambuc namespace NonClass { 19*f4a2713aSLionel Sambuc typedef int type; 20*f4a2713aSLionel Sambuc struct hiding {}; 21*f4a2713aSLionel Sambuc int hiding; 22*f4a2713aSLionel Sambuc static union { double union_member; }; 23*f4a2713aSLionel Sambuc enum tagname { enumerator }; 24*f4a2713aSLionel Sambuc } 25*f4a2713aSLionel Sambuc 26*f4a2713aSLionel Sambuc class Test0 { 27*f4a2713aSLionel Sambuc NonClass::type; // expected-error {{not a class}} expected-warning {{access declarations are deprecated}} 28*f4a2713aSLionel Sambuc NonClass::hiding; // expected-error {{not a class}} expected-warning {{access declarations are deprecated}} 29*f4a2713aSLionel Sambuc NonClass::union_member; // expected-error {{not a class}} expected-warning {{access declarations are deprecated}} 30*f4a2713aSLionel Sambuc NonClass::enumerator; // expected-error {{not a class}} expected-warning {{access declarations are deprecated}} 31*f4a2713aSLionel Sambuc }; 32*f4a2713aSLionel Sambuc } 33*f4a2713aSLionel Sambuc 34*f4a2713aSLionel Sambuc struct Opaque0 {}; 35*f4a2713aSLionel Sambuc 36*f4a2713aSLionel Sambuc namespace test1 { 37*f4a2713aSLionel Sambuc struct A { 38*f4a2713aSLionel Sambuc typedef int type; 39*f4a2713aSLionel Sambuc struct hiding {}; // expected-note {{previous use is here}} 40*f4a2713aSLionel Sambuc Opaque0 hiding; 41*f4a2713aSLionel Sambuc union { double union_member; }; 42*f4a2713aSLionel Sambuc enum tagname { enumerator }; 43*f4a2713aSLionel Sambuc }; 44*f4a2713aSLionel Sambuc 45*f4a2713aSLionel Sambuc struct B : A { 46*f4a2713aSLionel Sambuc A::type; // expected-warning {{access declarations are deprecated}} 47*f4a2713aSLionel Sambuc A::hiding; // expected-warning {{access declarations are deprecated}} 48*f4a2713aSLionel Sambuc A::union_member; // expected-warning {{access declarations are deprecated}} 49*f4a2713aSLionel Sambuc A::enumerator; // expected-warning {{access declarations are deprecated}} 50*f4a2713aSLionel Sambuc A::tagname; // expected-warning {{access declarations are deprecated}} 51*f4a2713aSLionel Sambuc test0test1::B52*f4a2713aSLionel Sambuc void test0() { 53*f4a2713aSLionel Sambuc type t = 0; 54*f4a2713aSLionel Sambuc } 55*f4a2713aSLionel Sambuc test1test1::B56*f4a2713aSLionel Sambuc void test1() { 57*f4a2713aSLionel Sambuc typedef struct A::hiding local; 58*f4a2713aSLionel Sambuc struct hiding _ = local(); 59*f4a2713aSLionel Sambuc } 60*f4a2713aSLionel Sambuc test2test1::B61*f4a2713aSLionel Sambuc void test2() { 62*f4a2713aSLionel Sambuc union hiding _; // expected-error {{tag type that does not match previous}} 63*f4a2713aSLionel Sambuc } 64*f4a2713aSLionel Sambuc test3test1::B65*f4a2713aSLionel Sambuc void test3() { 66*f4a2713aSLionel Sambuc char array[sizeof(union_member) == sizeof(double) ? 1 : -1]; 67*f4a2713aSLionel Sambuc } 68*f4a2713aSLionel Sambuc test4test1::B69*f4a2713aSLionel Sambuc void test4() { 70*f4a2713aSLionel Sambuc enum tagname _ = enumerator; 71*f4a2713aSLionel Sambuc } 72*f4a2713aSLionel Sambuc test5test1::B73*f4a2713aSLionel Sambuc void test5() { 74*f4a2713aSLionel Sambuc Opaque0 _ = hiding; 75*f4a2713aSLionel Sambuc } 76*f4a2713aSLionel Sambuc }; 77*f4a2713aSLionel Sambuc } 78*f4a2713aSLionel Sambuc 79*f4a2713aSLionel Sambuc namespace test2 { 80*f4a2713aSLionel Sambuc struct A { 81*f4a2713aSLionel Sambuc typedef int type; 82*f4a2713aSLionel Sambuc struct hiding {}; // expected-note {{previous use is here}} 83*f4a2713aSLionel Sambuc int hiding; 84*f4a2713aSLionel Sambuc union { double union_member; }; 85*f4a2713aSLionel Sambuc enum tagname { enumerator }; 86*f4a2713aSLionel Sambuc }; 87*f4a2713aSLionel Sambuc 88*f4a2713aSLionel Sambuc template <class T> struct B : A { 89*f4a2713aSLionel Sambuc A::type; // expected-warning {{access declarations are deprecated}} 90*f4a2713aSLionel Sambuc A::hiding; // expected-warning {{access declarations are deprecated}} 91*f4a2713aSLionel Sambuc A::union_member; // expected-warning {{access declarations are deprecated}} 92*f4a2713aSLionel Sambuc A::enumerator; // expected-warning {{access declarations are deprecated}} 93*f4a2713aSLionel Sambuc A::tagname; // expected-warning {{access declarations are deprecated}} 94*f4a2713aSLionel Sambuc test0test2::B95*f4a2713aSLionel Sambuc void test0() { 96*f4a2713aSLionel Sambuc type t = 0; 97*f4a2713aSLionel Sambuc } 98*f4a2713aSLionel Sambuc test1test2::B99*f4a2713aSLionel Sambuc void test1() { 100*f4a2713aSLionel Sambuc typedef struct A::hiding local; 101*f4a2713aSLionel Sambuc struct hiding _ = local(); 102*f4a2713aSLionel Sambuc } 103*f4a2713aSLionel Sambuc test2test2::B104*f4a2713aSLionel Sambuc void test2() { 105*f4a2713aSLionel Sambuc union hiding _; // expected-error {{tag type that does not match previous}} 106*f4a2713aSLionel Sambuc } 107*f4a2713aSLionel Sambuc test3test2::B108*f4a2713aSLionel Sambuc void test3() { 109*f4a2713aSLionel Sambuc char array[sizeof(union_member) == sizeof(double) ? 1 : -1]; 110*f4a2713aSLionel Sambuc } 111*f4a2713aSLionel Sambuc test4test2::B112*f4a2713aSLionel Sambuc void test4() { 113*f4a2713aSLionel Sambuc enum tagname _ = enumerator; 114*f4a2713aSLionel Sambuc } 115*f4a2713aSLionel Sambuc test5test2::B116*f4a2713aSLionel Sambuc void test5() { 117*f4a2713aSLionel Sambuc Opaque0 _ = hiding; 118*f4a2713aSLionel Sambuc } 119*f4a2713aSLionel Sambuc }; 120*f4a2713aSLionel Sambuc } 121*f4a2713aSLionel Sambuc 122*f4a2713aSLionel Sambuc namespace test3 { 123*f4a2713aSLionel Sambuc struct hiding {}; 124*f4a2713aSLionel Sambuc 125*f4a2713aSLionel Sambuc template <class T> struct A { 126*f4a2713aSLionel Sambuc typedef int type; // expected-note {{target of using declaration}} 127*f4a2713aSLionel Sambuc struct hiding {}; 128*f4a2713aSLionel Sambuc Opaque0 hiding; 129*f4a2713aSLionel Sambuc union { double union_member; }; 130*f4a2713aSLionel Sambuc enum tagname { enumerator }; // expected-note {{target of using declaration}} 131*f4a2713aSLionel Sambuc }; 132*f4a2713aSLionel Sambuc 133*f4a2713aSLionel Sambuc template <class T> struct B : A<T> { 134*f4a2713aSLionel Sambuc A<T>::type; // expected-error {{dependent using declaration resolved to type without 'typename'}} // expected-warning {{access declarations are deprecated}} 135*f4a2713aSLionel Sambuc A<T>::hiding; // expected-warning {{access declarations are deprecated}} 136*f4a2713aSLionel Sambuc A<T>::union_member; // expected-warning {{access declarations are deprecated}} 137*f4a2713aSLionel Sambuc A<T>::enumerator; // expected-warning {{access declarations are deprecated}} 138*f4a2713aSLionel Sambuc A<T>::tagname; // expected-error {{dependent using declaration resolved to type without 'typename'}} // expected-warning {{access declarations are deprecated}} 139*f4a2713aSLionel Sambuc 140*f4a2713aSLionel Sambuc // FIXME: re-enable these when the various bugs involving tags are fixed 141*f4a2713aSLionel Sambuc #if 0 142*f4a2713aSLionel Sambuc void test1() { 143*f4a2713aSLionel Sambuc typedef struct A<T>::hiding local; 144*f4a2713aSLionel Sambuc struct hiding _ = local(); 145*f4a2713aSLionel Sambuc } 146*f4a2713aSLionel Sambuc 147*f4a2713aSLionel Sambuc void test2() { 148*f4a2713aSLionel Sambuc typedef struct A<T>::hiding local; 149*f4a2713aSLionel Sambuc union hiding _ = local(); 150*f4a2713aSLionel Sambuc } 151*f4a2713aSLionel Sambuc #endif 152*f4a2713aSLionel Sambuc test3test3::B153*f4a2713aSLionel Sambuc void test3() { 154*f4a2713aSLionel Sambuc char array[sizeof(union_member) == sizeof(double) ? 1 : -1]; 155*f4a2713aSLionel Sambuc } 156*f4a2713aSLionel Sambuc 157*f4a2713aSLionel Sambuc #if 0 158*f4a2713aSLionel Sambuc void test4() { 159*f4a2713aSLionel Sambuc enum tagname _ = enumerator; 160*f4a2713aSLionel Sambuc } 161*f4a2713aSLionel Sambuc #endif 162*f4a2713aSLionel Sambuc test5test3::B163*f4a2713aSLionel Sambuc void test5() { 164*f4a2713aSLionel Sambuc Opaque0 _ = hiding; 165*f4a2713aSLionel Sambuc } 166*f4a2713aSLionel Sambuc }; 167*f4a2713aSLionel Sambuc 168*f4a2713aSLionel Sambuc template struct B<int>; // expected-note {{in instantiation}} 169*f4a2713aSLionel Sambuc } 170*f4a2713aSLionel Sambuc 171*f4a2713aSLionel Sambuc namespace test4 { 172*f4a2713aSLionel Sambuc struct Base { 173*f4a2713aSLionel Sambuc int foo(); 174*f4a2713aSLionel Sambuc }; 175*f4a2713aSLionel Sambuc 176*f4a2713aSLionel Sambuc struct Unrelated { 177*f4a2713aSLionel Sambuc int foo(); 178*f4a2713aSLionel Sambuc }; 179*f4a2713aSLionel Sambuc 180*f4a2713aSLionel Sambuc struct Subclass : Base { 181*f4a2713aSLionel Sambuc }; 182*f4a2713aSLionel Sambuc 183*f4a2713aSLionel Sambuc namespace InnerNS { 184*f4a2713aSLionel Sambuc int foo(); 185*f4a2713aSLionel Sambuc } 186*f4a2713aSLionel Sambuc 187*f4a2713aSLionel Sambuc // We should be able to diagnose these without instantiation. 188*f4a2713aSLionel Sambuc template <class T> struct C : Base { 189*f4a2713aSLionel Sambuc InnerNS::foo; // expected-error {{not a class}} expected-warning {{access declarations are deprecated}} 190*f4a2713aSLionel Sambuc Base::bar; // expected-error {{no member named 'bar'}} expected-warning {{access declarations are deprecated}} 191*f4a2713aSLionel Sambuc Unrelated::foo; // expected-error {{not a base class}} expected-warning {{access declarations are deprecated}} 192*f4a2713aSLionel Sambuc C::foo; // legal in C++03 // expected-warning {{access declarations are deprecated}} 193*f4a2713aSLionel Sambuc Subclass::foo; // legal in C++03 // expected-warning {{access declarations are deprecated}} 194*f4a2713aSLionel Sambuc 195*f4a2713aSLionel Sambuc int bar(); //expected-note {{target of using declaration}} 196*f4a2713aSLionel Sambuc C::bar; // expected-error {{refers to its own class}} expected-warning {{access declarations are deprecated}} 197*f4a2713aSLionel Sambuc }; 198*f4a2713aSLionel Sambuc } 199*f4a2713aSLionel Sambuc 200