Debian Codegraph @

libstdc++-v3/testsuite/30_threads/packaged_task/cons/lwg4154_neg.cc

raw
1 // { dg-do compile { target c++11 } }
2
3 // LWG 4154. The Mandates for std::packaged_task's constructor from
4 // a callable entity should consider decaying
5
6 #include <future>
7
8 struct F {
9 void operator()() & = delete;
10 void operator()() const & { }
11 };
12
13 // Mandates: is_invocable_r_v<R, decay_t<F>&, ArgTypes...> is true.
14 const F f;
15 std::packaged_task<void()> p(f); // { dg-error "here" "" { target c++17 } }
16 // { dg-error "static assertion failed" "" { target c++17 } 0 }
17 // { dg-error "invoke_r" "" { target *-*-* } 0 }
18 // { dg-prune-output "enable_if<false" }
19
20 // Only callable as rvalue
21 struct Frv {
22 int* operator()() && { return 0; }
23 };
24 std::packaged_task<int*()> p2(Frv{}); // { dg-error "here" "" { target c++17 } }
25
26 // Only callable as non-const lvalue
27 struct Fnc {
28 void operator()() const & = delete;
29 void operator()() & { }
30 };
31
32 // In C++11/14/17/20 std::packaged_task::packaged_task<F>(F&&) incorrectly
33 // required that the callable passed to the constructor can be invoked.
34 // If the type of the parameter is const F& we might not be able to invoke
35 // the parameter, but that's OK because we store and invoke a non-const F.
36 // So this should work without errors:
37 const Fnc fnc;
38 std::packaged_task<void()> p3(fnc);