c++: Implement __is_nothrow_invocable built-in trait
[official-gcc.git] / gcc / testsuite / g++.dg / ext / is_nothrow_invocable.C
blob2f9b40e5538dc060e2b6def95dd7edb189b2b026
1 // { dg-do compile { target c++11 } }
3 #define SA(X) static_assert((X),#X)
5 using func_type = void(*)();
6 SA( ! __is_nothrow_invocable(func_type) );
8 #if __cpp_noexcept_function_type
9 using func_type_nt = void(*)() noexcept;
10 SA(   __is_nothrow_invocable(func_type_nt) );
11 #endif
13 struct X { };
14 using mem_type = int X::*;
16 SA( ! __is_nothrow_invocable(mem_type) );
17 SA( ! __is_nothrow_invocable(mem_type, int) );
18 SA( ! __is_nothrow_invocable(mem_type, int&) );
19 SA(   __is_nothrow_invocable(mem_type, X&) );
21 using memfun_type = int (X::*)();
23 SA( ! __is_nothrow_invocable(memfun_type) );
24 SA( ! __is_nothrow_invocable(memfun_type, int) );
25 SA( ! __is_nothrow_invocable(memfun_type, int&) );
26 SA( ! __is_nothrow_invocable(memfun_type, X&) );
27 SA( ! __is_nothrow_invocable(memfun_type, X*) );
29 #if __cpp_noexcept_function_type
30 using memfun_type_nt = int (X::*)() noexcept;
32 SA( ! __is_nothrow_invocable(memfun_type_nt) );
33 SA( ! __is_nothrow_invocable(memfun_type_nt, int) );
34 SA( ! __is_nothrow_invocable(memfun_type_nt, int&) );
35 SA(   __is_nothrow_invocable(memfun_type_nt, X&) );
36 SA(   __is_nothrow_invocable(memfun_type_nt, X*) );
37 #endif
39 struct F {
40   int& operator()();
41   long& operator()() const noexcept;
42   short& operator()(int) &&;
43   char& operator()(int) const& noexcept;
44 private:
45   void operator()(int, int) noexcept;
47 using CF = const F;
49 SA( ! __is_nothrow_invocable(F ) );
50 SA(   __is_nothrow_invocable(CF) );
52 SA( ! __is_nothrow_invocable(F,   int) );
53 SA(   __is_nothrow_invocable(F&,  int) );
55 SA(   __is_nothrow_invocable(CF,   int) );
56 SA(   __is_nothrow_invocable(CF&,  int) );
57 SA( ! __is_nothrow_invocable(F, int, int) );
59 struct FX {
60   X operator()() const noexcept { return {}; }
62 SA(   __is_nothrow_invocable(FX) );