Debian Codegraph @

libstdc++-v3/testsuite/experimental/propagate_const/swap/lwg3413.cc

raw
1 // { dg-do compile { target c++14 } }
2
3 // LWG 3413
4 // propagate_const's swap's noexcept specification needs to be constrained
5 // and use a trait
6
7 #include <experimental/propagate_const>
8
9 using std::experimental::propagate_const;
10
11 propagate_const<int*> i;
12 static_assert( noexcept(i.swap(i)), "member swap is noexcept" );
13 static_assert( noexcept(swap(i, i)), "non-member swap is noexcept" );
14
15 struct P
16 {
17 int i = 0;
18 int& operator*() const;
19 };
20
21 void swap(P&, P&) noexcept(false);
22
23 propagate_const<P> p;
24 static_assert( ! noexcept(p.swap(p)), "member swap is conditionally noexcept" );
25 static_assert( ! noexcept(swap(p, p)), "non-member swap is conditionally noexcept" );
26
27 // std::is_swappable not available for -std=c++14
28 #if __cplusplus > 201402L || !defined(__STRICT_ANSI__)
29 struct Q
30 {
31 int i = 0;
32 int& operator*() const;
33
34 Q& operator=(Q&&) = delete;
35 };
36
37 static_assert( ! std::is_swappable<Q>::value, "" );
38
39 static_assert( ! std::is_swappable<propagate_const<Q>>::value,
40 "non-member swap is constrained" );
41 #endif