Debian Codegraph @

gcc/testsuite/g++.dg/cpp0x/decltype42.C

raw
1 // PR c++/50545
2 // { dg-do compile { target c++11 } }
3
4 template< class T >
5 T&& declval();
6
7 // #1
8 template< class T >
9 auto f( int )
10 -> decltype( int{ declval<T>() } );
11
12 // #2
13 template< class >
14 void f( ... );
15
16
17 #define STATIC_ASSERT( ... ) static_assert( __VA_ARGS__, #__VA_ARGS__ )
18
19 template< class T, class U >
20 struct is_same {
21 static constexpr bool value = false;
22 };
23
24 template< class T >
25 struct is_same<T, T> {
26 static constexpr bool value = true;
27 };
28
29
30 STATIC_ASSERT( is_same< decltype( f<int>(0) ), int >::value ); // OK; f<int>(0) calls #1.
31 STATIC_ASSERT( is_same< decltype( f<int*>(0) ), void >::value ); // static assertion fails; f<int*>(0) should call #2, because int{ (int*)0 } is ill-formed, but calls #1.