Merged with mainline at revision 128810.
[official-gcc.git] / gcc / testsuite / g++.dg / cpp0x / decltype2.C
blob65549b4e9b367ddb38365513bc579389f1025b6c
1 // { dg-do "compile" }
2 // { dg-options "-std=gnu++0x" }
4 template<typename T, typename U> 
5 struct is_same 
7   static const bool value = false;
8 };
10 template<typename T>
11 struct is_same<T, T>
13   static const bool value = true;
16 #define CHECK_DECLTYPE(DECLTYPE,RESULT) \
17   static_assert(is_same< DECLTYPE , RESULT >::value, #RESULT)
19 struct A {};
21 int a; 
22 int& b = a; 
23 const int& c = a; 
24 const int d = 5; 
25 const A e = A(); 
26 CHECK_DECLTYPE(decltype(a), int);
27 CHECK_DECLTYPE(decltype(b), int&); 
28 CHECK_DECLTYPE(decltype(c), const int&); 
29 CHECK_DECLTYPE(decltype(d), const int); 
30 CHECK_DECLTYPE(decltype(e), const A); 
32 CHECK_DECLTYPE(decltype(a), int);
33 CHECK_DECLTYPE(decltype((a)), int&);
35 void foo_check(int a, int& b, float& c, int* d) 
36
37   CHECK_DECLTYPE(decltype(a), int);
38   CHECK_DECLTYPE(decltype(b), int&); 
39   CHECK_DECLTYPE(decltype(c), float&);
40   CHECK_DECLTYPE(decltype(d), int*);
41
43 int foo(char); 
44 int bar(char); 
45 int bar(int); 
46 CHECK_DECLTYPE(decltype(foo), int(char));
48 decltype(bar) z; // { dg-error "overload" }
49 // { dg-error "invalid type" "" { target *-*-* } 48 }
51 CHECK_DECLTYPE(decltype(&foo), int(*)(char));
52 CHECK_DECLTYPE(decltype(*&foo), int(&)(char));
54 void array_types()
56   int a[10]; 
57   CHECK_DECLTYPE(decltype(a), int[10]);