OSDN Git Service

PR c++/36628
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / g++.dg / cpp0x / decltype5.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, #RESULT)
18
19 template<typename F> F create_a();
20
21 template<typename F, typename T1>
22 decltype(create_a<F&>()(create_a<const T1&>())) forward(F f, const T1& a1)
23 {
24   return f(a1);
25 }
26
27 struct identity {
28   template<typename T>
29   const T& operator()(const T& x) { return x; }
30 };
31
32
33 identity id;
34 int i;
35 float f;
36
37 CHECK_DECLTYPE(decltype(forward(id, i)), const int&);
38 CHECK_DECLTYPE(decltype(forward(id, f)), const float&);