Skip to content

Commit 019a902

Browse files
[libc++] Deprecate extension packaged_task::result_type (#122600)
This extension is questionable and non-conforming. Perhaps we should deprecate and then remove it. Towards #112856.
1 parent d1a622d commit 019a902

File tree

4 files changed

+47
-15
lines changed

4 files changed

+47
-15
lines changed

libcxx/docs/ReleaseNotes/20.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ Deprecations and Removals
146146
``__undeclare_reachable`` have been removed from the library. These functions were never implemented in a non-trivial
147147
way, making it very unlikely that any binary depends on them.
148148

149+
- Non-conforming extension ``packaged_task::result_type`` is deprecated. It will be removed in LLVM 21.
150+
149151
Upcoming Deprecations and Removals
150152
----------------------------------
151153

@@ -164,6 +166,8 @@ LLVM 21
164166
- The ``_LIBCPP_VERBOSE_ABORT_NOT_NOEXCEPT`` macro will be removed in LLVM 21, making ``std::__libcpp_verbose_abort``
165167
unconditionally ``noexcept``.
166168

169+
- Non-conforming extension ``packaged_task::result_type`` will be removed in LLVM 21.
170+
167171

168172
ABI Affecting Changes
169173
---------------------

libcxx/include/future

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1612,11 +1612,11 @@ inline _Rp __packaged_task_function<_Rp(_ArgTypes...)>::operator()(_ArgTypes...
16121612
template <class _Rp, class... _ArgTypes>
16131613
class _LIBCPP_TEMPLATE_VIS packaged_task<_Rp(_ArgTypes...)> {
16141614
public:
1615-
typedef _Rp result_type; // extension
1615+
using result_type _LIBCPP_DEPRECATED = _Rp; // extension
16161616

16171617
private:
1618-
__packaged_task_function<result_type(_ArgTypes...)> __f_;
1619-
promise<result_type> __p_;
1618+
__packaged_task_function<_Rp(_ArgTypes...)> __f_;
1619+
promise<_Rp> __p_;
16201620

16211621
public:
16221622
// construction and destruction
@@ -1653,7 +1653,7 @@ public:
16531653
_LIBCPP_HIDE_FROM_ABI bool valid() const _NOEXCEPT { return __p_.__state_ != nullptr; }
16541654

16551655
// result retrieval
1656-
_LIBCPP_HIDE_FROM_ABI future<result_type> get_future() { return __p_.get_future(); }
1656+
_LIBCPP_HIDE_FROM_ABI future<_Rp> get_future() { return __p_.get_future(); }
16571657

16581658
// execution
16591659
_LIBCPP_HIDE_FROM_ABI void operator()(_ArgTypes... __args);
@@ -1700,17 +1700,17 @@ template <class _Rp, class... _ArgTypes>
17001700
void packaged_task<_Rp(_ArgTypes...)>::reset() {
17011701
if (!valid())
17021702
__throw_future_error(future_errc::no_state);
1703-
__p_ = promise<result_type>();
1703+
__p_ = promise<_Rp>();
17041704
}
17051705

17061706
template <class... _ArgTypes>
17071707
class _LIBCPP_TEMPLATE_VIS packaged_task<void(_ArgTypes...)> {
17081708
public:
1709-
typedef void result_type; // extension
1709+
using result_type _LIBCPP_DEPRECATED = void; // extension
17101710

17111711
private:
1712-
__packaged_task_function<result_type(_ArgTypes...)> __f_;
1713-
promise<result_type> __p_;
1712+
__packaged_task_function<void(_ArgTypes...)> __f_;
1713+
promise<void> __p_;
17141714

17151715
public:
17161716
// construction and destruction
@@ -1745,7 +1745,7 @@ public:
17451745
_LIBCPP_HIDE_FROM_ABI bool valid() const _NOEXCEPT { return __p_.__state_ != nullptr; }
17461746

17471747
// result retrieval
1748-
_LIBCPP_HIDE_FROM_ABI future<result_type> get_future() { return __p_.get_future(); }
1748+
_LIBCPP_HIDE_FROM_ABI future<void> get_future() { return __p_.get_future(); }
17491749

17501750
// execution
17511751
_LIBCPP_HIDE_FROM_ABI void operator()(_ArgTypes... __args);
@@ -1804,7 +1804,7 @@ template <class... _ArgTypes>
18041804
void packaged_task<void(_ArgTypes...)>::reset() {
18051805
if (!valid())
18061806
__throw_future_error(future_errc::no_state);
1807-
__p_ = promise<result_type>();
1807+
__p_ = promise<void>();
18081808
}
18091809

18101810
template <class _Rp, class... _ArgTypes>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
//
9+
// UNSUPPORTED: no-threads
10+
// UNSUPPORTED: c++03
11+
12+
// <future>
13+
14+
// template<class R, class... ArgTypes>
15+
// class packaged_task<R(ArgTypes...)>
16+
// {
17+
// public:
18+
// typedef R result_type; // extension
19+
20+
// This libc++ extension is deprecated. See https://github.com/llvm/llvm-project/issues/112856.
21+
22+
#include <future>
23+
#include <type_traits>
24+
25+
struct A {};
26+
27+
using RA = std::packaged_task<A(int, char)>::result_type; // expected-warning {{'result_type' is deprecated}}
28+
using RV = std::packaged_task<void(int, char)>::result_type; // expected-warning {{'result_type' is deprecated}}

libcxx/test/libcxx/thread/futures/futures.task/types.pass.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@
1919

2020
// This is a libc++ extension.
2121

22+
// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS
23+
2224
#include <future>
2325
#include <type_traits>
2426

25-
#include "test_macros.h"
26-
2727
struct A {};
2828

29-
int main(int, char**)
30-
{
31-
static_assert((std::is_same<std::packaged_task<A(int, char)>::result_type, A>::value), "");
29+
int main(int, char**) {
30+
static_assert((std::is_same<std::packaged_task<A(int, char)>::result_type, A>::value), "");
31+
static_assert((std::is_same<std::packaged_task<void(int, char)>::result_type, void>::value), "");
3232

3333
return 0;
3434
}

0 commit comments

Comments
 (0)