* decl.c (make_typename_type): s/parameters/arguments/.
[official-gcc.git] / gcc / testsuite / g++.dg / cpp0x / decltype4.C
blobc14e156465d1d57fd5384a60f105334550a6499b
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 struct A {
19   int x; 
20   int& y; 
21   int foo(char); 
22   int& bar() const; 
23 }; 
25 CHECK_DECLTYPE(decltype(&A::x), int A::*);
26 decltype(&A::y) Ay; // { dg-error "cannot create pointer to reference member|invalid type" }
27 CHECK_DECLTYPE(decltype(&A::foo), int (A::*) (char));
28 CHECK_DECLTYPE(decltype(&A::bar), int& (A::*) () const);
30 CHECK_DECLTYPE(decltype("decltype"), const char(&)[9]);
31 CHECK_DECLTYPE(decltype(1), int);
33 int an_int = 5;
34 int& i = an_int; 
35 const int j = an_int; 
37 CHECK_DECLTYPE(decltype(i)&, int&);
38 CHECK_DECLTYPE(const decltype(j), const int);
40 int foo(); 
41 CHECK_DECLTYPE(decltype(foo()), int);
42 float& bar(int); 
43 CHECK_DECLTYPE(decltype (bar(1)), float&);
44 const A bar(); 
45 CHECK_DECLTYPE(decltype (bar()), const A);
46 const A& bar2(); 
47 CHECK_DECLTYPE(decltype (bar2()), const A&);
49 void wibble() {
50   CHECK_DECLTYPE(decltype(1+2), int);
51   int* p; 
52   CHECK_DECLTYPE(decltype(*p), int&);
53   int a[10]; 
54   CHECK_DECLTYPE(decltype(a[3]), int&);
55   int i; int& j = i; 
56   CHECK_DECLTYPE(decltype (i = 5), int&);
57   CHECK_DECLTYPE(decltype (j = 5), int&);
59   CHECK_DECLTYPE(decltype (++i), int&); 
60   CHECK_DECLTYPE(decltype (i++), int);
63 struct B {
64   B () : bit(), cbit() {} 
65   int bit : 2;
66   const int cbit : 3;
68   void foo()
69   {
70     CHECK_DECLTYPE(decltype(bit), int);
71     CHECK_DECLTYPE(decltype((bit)), int&);
72     CHECK_DECLTYPE(decltype(cbit), const int);
73     CHECK_DECLTYPE(decltype((cbit)), const int&);
74   }
77 B b;
78 const B& bc = b;
79 CHECK_DECLTYPE(decltype(b.bit), int);
80 CHECK_DECLTYPE(decltype(bc.bit), int);
81 CHECK_DECLTYPE(decltype((b.bit)), int&);
82 CHECK_DECLTYPE(decltype((bc.bit)), const int&);