1 // { dg-do compile { target c++11 } }
2 
3 template<typename T, typename U>
4 struct is_same
5 {
6   static const bool value = false;
7 };
8 
9 template<typename T>
10 struct is_same<T, T>
11 {
12   static const bool value = true;
13 };
14 
15 #define CHECK_DECLTYPE(DECLTYPE,RESULT) \
16   static_assert(is_same< DECLTYPE , RESULT >::value, #RESULT)
17 
18 struct A {};
19 
20 int a;
21 int& b = a;
22 const int& c = a;
23 const int d = 5;
24 const A e = A();
25 CHECK_DECLTYPE(decltype(a), int);
26 CHECK_DECLTYPE(decltype(b), int&);
27 CHECK_DECLTYPE(decltype(c), const int&);
28 CHECK_DECLTYPE(decltype(d), const int);
29 CHECK_DECLTYPE(decltype(e), const A);
30 
31 CHECK_DECLTYPE(decltype(a), int);
32 CHECK_DECLTYPE(decltype((a)), int&);
33 
34 void foo_check(int a, int& b, float& c, int* d)
35 {
36   CHECK_DECLTYPE(decltype(a), int);
37   CHECK_DECLTYPE(decltype(b), int&);
38   CHECK_DECLTYPE(decltype(c), float&);
39   CHECK_DECLTYPE(decltype(d), int*);
40 }
41 
42 int foo(char);
43 int bar(char);
44 int bar(int);
45 CHECK_DECLTYPE(decltype(foo), int(char));
46 
47 decltype(bar) z; // { dg-error "overload" "overload" }
48 
49 CHECK_DECLTYPE(decltype(&foo), int(*)(char));
50 CHECK_DECLTYPE(decltype(*&foo), int(&)(char));
51 
52 void array_types()
53 {
54   int a[10];
55   CHECK_DECLTYPE(decltype(a), int[10]);
56 }
57 
58