Home | History | Annotate | Download | only in expr.prim.general
      1 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
      2 
      3 struct global {
      4 };
      5 
      6 namespace PR10127 {
      7   struct outer {
      8     struct middle {
      9       struct inner {
     10         int func();
     11         int i;
     12       };
     13       struct inner2 {
     14       };
     15       struct inner3 {
     16       };
     17       int mfunc();
     18     };
     19     typedef int td_int;
     20   };
     21 
     22   struct str {
     23     operator decltype(outer::middle::inner()) ();
     24     operator decltype(outer::middle())::inner2 ();
     25     operator decltype(outer())::middle::inner3 ();
     26     str(int (decltype(outer::middle::inner())::*n)(),
     27              int (decltype(outer::middle())::inner::*o)(),
     28              int (decltype(outer())::middle::inner::*p)());
     29   };
     30 
     31   decltype(outer::middle::inner()) a;
     32   void scope() {
     33     a.decltype(outer::middle())::mfunc(); // expected-error{{'PR10127::outer::middle::mfunc' is not a member of class 'decltype(outer::middle::inner())'}}
     34     a.decltype(outer::middle::inner())::func();
     35     a.decltype(outer::middle())::inner::func();
     36     a.decltype(outer())::middle::inner::func();
     37 
     38     a.decltype(outer())::middle::inner::~inner();
     39 
     40     decltype(outer())::middle::inner().func();
     41   }
     42   decltype(outer::middle())::inner b;
     43   decltype(outer())::middle::inner c;
     44   decltype(outer())::fail d; // expected-error{{no type named 'fail' in 'PR10127::outer'}}
     45   decltype(outer())::fail::inner e; // expected-error{{no member named 'fail' in 'PR10127::outer'}}
     46   decltype()::fail f; // expected-error{{expected expression}}
     47   decltype()::middle::fail g; // expected-error{{expected expression}}
     48 
     49   decltype(int()) h;
     50   decltype(int())::PR10127::outer i; // expected-error{{'decltype(int())' (aka 'int') is not a class, namespace, or scoped enumeration}}
     51   decltype(int())::global j; // expected-error{{'decltype(int())' (aka 'int') is not a class, namespace, or scoped enumeration}}
     52 
     53   outer::middle k = decltype(outer())::middle();
     54   outer::middle::inner l = decltype(outer())::middle::inner();
     55 
     56   template<typename T>
     57   struct templ {
     58     typename decltype(T())::middle::inner x; // expected-error{{type 'decltype(int())' (aka 'int') cannot be used prior to '::' because it has no members}}
     59   };
     60 
     61   template class templ<int>; // expected-note{{in instantiation of template class 'PR10127::templ<int>' requested here}}
     62   template class templ<outer>;
     63 
     64   enum class foo {
     65     bar,
     66     baz
     67   };
     68 
     69   foo m = decltype(foo::bar)::baz;
     70 
     71   enum E {
     72   };
     73   struct bar {
     74     enum E : decltype(outer())::td_int(4);
     75     enum F : decltype(outer())::td_int;
     76     enum G : decltype; // expected-error{{expected '(' after 'decltype'}}
     77   };
     78 }
     79