OSDN Git Service

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