// { dg-do "compile" } // { dg-options "-std=gnu++0x" } template struct is_same { static const bool value = false; }; template struct is_same { static const bool value = true; }; #define CHECK_DECLTYPE(DECLTYPE,RESULT) \ static_assert(is_same< DECLTYPE , RESULT >::value, #RESULT) template F create_a(); template decltype(create_a()(create_a())) forward(F f, const T1& a1) { return f(a1); } struct identity { template const T& operator()(const T& x) { return x; } }; identity id; int i; float f; CHECK_DECLTYPE(decltype(forward(id, i)), const int&); CHECK_DECLTYPE(decltype(forward(id, f)), const float&);