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, #RESULT) 18 19 struct A {}; 20 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); 31 32 CHECK_DECLTYPE(decltype(a), int); 33 CHECK_DECLTYPE(decltype((a)), int&); 34 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 } 42 43 int foo(char); 44 int bar(char); 45 int bar(int); 46 CHECK_DECLTYPE(decltype(foo), int(char)); 47 48 decltype(bar) z; // { dg-error "overload" "overload" } 49 // { dg-error "invalid type" "invalid" { target *-*-* } 48 } 50 51 CHECK_DECLTYPE(decltype(&foo), int(*)(char)); 52 CHECK_DECLTYPE(decltype(*&foo), int(&)(char)); 53 54 void array_types() 55 { 56 int a[10]; 57 CHECK_DECLTYPE(decltype(a), int[10]); 58 } 59 60