]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/20_util/function/cons/noexcept.cc
libstdc++: Disable hosted-only tests [PR103626]
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 20_util / function / cons / noexcept.cc
1 // { dg-do compile { target c++11 } }
2 // { dg-require-effective-target hosted }
3
4 #include <functional>
5
6 struct X
7 {
8 void operator()(X*);
9
10 char bigness[100];
11 };
12
13 using F = std::function<void(X*)>;
14
15 static_assert( std::is_nothrow_constructible<F>::value, "" );
16 static_assert( std::is_nothrow_constructible<F, F>::value, "" );
17 static_assert( ! std::is_nothrow_constructible<F, F&>::value, "" );
18 static_assert( ! std::is_nothrow_constructible<F, const F&>::value, "" );
19 static_assert( std::is_nothrow_constructible<F, std::nullptr_t>::value, "" );
20
21 static_assert( ! std::is_nothrow_constructible<F, X>::value, "" );
22 using R = std::reference_wrapper<X>;
23 static_assert( std::is_nothrow_constructible<F, R>::value, "" );
24
25
26 // The standard requires that construction from a function pointer type
27 // does not throw, but doesn't require that the construction is noexcept.
28 // Strengthening that noexcept for these types is a GCC extension.
29 static_assert( std::is_nothrow_constructible<F, void(*)(X*)>::value, "" );
30 // This is a GCC extension, not required by the standard:
31 static_assert( std::is_nothrow_constructible<F, void(&)(X*)>::value, "" );
32 // This is a GCC extension, not required by the standard:
33 static_assert( std::is_nothrow_constructible<F, void(X::*)()>::value, "" );
34
35 auto c = [](X*){};
36 static_assert( std::is_nothrow_constructible<F, decltype(+c)>::value, "" );
37 // The standard allows this to throw, but as a GCC extenension we store
38 // closures with no captures in the std::function, so this is noexcept too:
39 static_assert( std::is_nothrow_constructible<F, decltype(c)>::value, "" );