]> git.ipfire.org Git - thirdparty/gcc.git/commit
libstdc++: Improve diagnostics for std::packaged_task invocable checks
authorJonathan Wakely <jwakely@redhat.com>
Thu, 24 Apr 2025 20:55:16 +0000 (21:55 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Fri, 25 Apr 2025 10:47:12 +0000 (11:47 +0100)
commit901900bc37566c59b4eb62c1427f3150b800d8a0
treedfb367afe60c6d670e5578d8fc7b46a885840c4b
parent876d1a22dfaf873d167bd2ffad190a1d07a81b22
libstdc++: Improve diagnostics for std::packaged_task invocable checks

Moving the static_assert that checks is_invocable_r_v into _Task_state
means it is checked when we instantiate that class template.

Replacing the __create_task_state function with a static member function
_Task_state::_S_create ensures we instantiate _Task_state and trigger
the static_assert immediately, not deep inside the implementation of
std::allocate_shared. This results in shorter diagnostics that don't
show deeply-nested template instantiations before the static_assert
failure.

Placing the static_assert at class scope also helps us to fail earlier
than waiting until when the _Task_state::_M_run virtual function is
instantiated. That also makes the diagnostics shorter and easier to read
(although for C++11 and C++14 modes the class-scope static_assert
doesn't check is_invocable_r, so dangling references aren't detected
until _M_run is instantiated).

libstdc++-v3/ChangeLog:

* include/std/future (__future_base::_Task_state): Check
invocable requirement here.
(__future_base::_Task_state::_S_create): New static member
function.
(__future_base::_Task_state::_M_reset): Use _S_create.
(__create_task_state): Remove.
(packaged_task): Use _Task_state::_S_create instead of
__create_task_state.
* testsuite/30_threads/packaged_task/cons/dangling_ref.cc:
Adjust dg-error patterns.
* testsuite/30_threads/packaged_task/cons/lwg4154_neg.cc:
Likewise.

Reviewed-by: Tomasz KamiƄski <tkaminsk@redhat.com>
libstdc++-v3/include/std/future
libstdc++-v3/testsuite/30_threads/packaged_task/cons/dangling_ref.cc
libstdc++-v3/testsuite/30_threads/packaged_task/cons/lwg4154_neg.cc