Home | History | Annotate | Download | only in SemaCXX
      1 // RUN: %clang_cc1 -fsyntax-only -verify %s
      2 namespace 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 
     30 struct bad
     31 {
     32   int x();
     33 };
     34 
     35 namespace 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{{'bad::x' is not a member of class '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{{'bad::x' is not a member of class '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         a.A::sub::x();
    107         a.A::B::base::x();
    108         a->A::member::foo();
    109 
    110         a.bad::x(); // expected-error{{'bad::x' is not a member of class 'A::sub'}}
    111     }
    112 
    113   void test_fun5() {
    114     fun5<A::sub>(); // expected-note{{instantiation}}
    115   }
    116 
    117   template<typename T>
    118   void fun6() {
    119     T a;
    120     a.sub::x();
    121     a.base::x();
    122     a->member::foo();
    123     a.B::base::x(); // expected-error{{use of undeclared identifier 'B'}}
    124    }
    125 
    126   void test_fun6() {
    127     fun6<A::sub>(); // expected-note{{instantiation}}
    128   }
    129 
    130 }
    131 
    132 // PR4703
    133 struct a {
    134   int a;
    135   static int sa;
    136 };
    137 
    138 a a;
    139 
    140 int a::sa = a.a; // expected-error {{invalid use of non-static data member 'a'}}
    141 
    142 
    143 namespace PR6645 {
    144   typedef int foo;
    145   namespace Inner {
    146     typedef int PR6645::foo; // expected-error{{typedef declarator cannot be qualified}} \
    147     // expected-error{{cannot define or redeclare 'foo' here because namespace 'Inner' does not enclose namespace 'PR6645'}}
    148   }
    149 }
    150