* decl.c (make_typename_type): s/parameters/arguments/.
[official-gcc.git] / gcc / testsuite / g++.dg / cpp0x / decltype3.C
blobb921dd6d899cda0bbd323162fdccdbd79d4bb8fd
1 // { dg-do compile { target c++11 } }
3 template<typename T, typename U> 
4 struct is_same 
6   static const bool value = false;
7 };
9 template<typename T>
10 struct is_same<T, T>
12   static const bool value = true;
15 #define CHECK_DECLTYPE(DECLTYPE,RESULT) \
16   static_assert(is_same< DECLTYPE , RESULT >::value, #DECLTYPE " should be " #RESULT)
18 class A { 
19 public:
20   int a; 
21   int& b; 
22   static int c; 
24   A(int& b) : b(b) { }
26   void foo() { 
27     CHECK_DECLTYPE(decltype(a), int);
28     CHECK_DECLTYPE(decltype(this->a), int);
29     CHECK_DECLTYPE(decltype((*this).a), int);
30     CHECK_DECLTYPE(decltype(b), int&);
31     CHECK_DECLTYPE(decltype(c), int);
32   } 
33   void bar() const {
34     CHECK_DECLTYPE(decltype(a), int);
35     CHECK_DECLTYPE(decltype(b), int&);
36     CHECK_DECLTYPE(decltype(c), int);
37   } 
38 }; 
40 int b;
41 A aa(b); 
42 const A& caa = aa; 
43 CHECK_DECLTYPE(decltype(aa.a), int);
44 CHECK_DECLTYPE(decltype(aa.b), int&);
45 CHECK_DECLTYPE(decltype(caa.a), int);
47 class B { 
48 public:
49   int a;
50   enum B_enum { b }; 
51   decltype(a) c;
52   decltype(a) foo() { return 0; }
53   decltype(b) enums_are_in_scope() { return b; } // ok 
54 }; 
56 CHECK_DECLTYPE(decltype(aa.*&A::a), int&);
57 decltype(aa.*&A::b) zz; // { dg-error "cannot create pointer to reference member" "cannot" }
59 CHECK_DECLTYPE(decltype(caa.*&A::a), const int&);
61 class X { 
62   void foo() { 
63     CHECK_DECLTYPE(decltype(this), X*);
64     CHECK_DECLTYPE(decltype(*this), X&);
65   } 
66   void bar() const { 
67     CHECK_DECLTYPE(decltype(this), const X*);
68     CHECK_DECLTYPE(decltype(*this), const X&);
69   }