Skip to content

Commit

Permalink
[libc++] Deprecate extension packaged_task::result_type
Browse files Browse the repository at this point in the history
This extension is questionable and non-conforming. Perhaps we should
deprecate and then remove it.
  • Loading branch information
frederick-vs-ja committed Jan 11, 2025
1 parent ab9a80a commit da7895d
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 15 deletions.
4 changes: 4 additions & 0 deletions libcxx/docs/ReleaseNotes/20.rst
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ Deprecations and Removals
``__undeclare_reachable`` have been removed from the library. These functions were never implemented in a non-trivial
way, making it very unlikely that any binary depends on them.

- Non-conforming extension ``packaged_task::result_type`` is deprecated. It will be removed in LLVM 21.

Upcoming Deprecations and Removals
----------------------------------

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

- Non-conforming extension ``packaged_task::result_type`` will be removed in LLVM 21.


ABI Affecting Changes
---------------------
Expand Down
20 changes: 10 additions & 10 deletions libcxx/include/future
Original file line number Diff line number Diff line change
Expand Up @@ -1612,11 +1612,11 @@ inline _Rp __packaged_task_function<_Rp(_ArgTypes...)>::operator()(_ArgTypes...
template <class _Rp, class... _ArgTypes>
class _LIBCPP_TEMPLATE_VIS packaged_task<_Rp(_ArgTypes...)> {
public:
typedef _Rp result_type; // extension
using result_type _LIBCPP_DEPRECATED = _Rp; // extension

private:
__packaged_task_function<result_type(_ArgTypes...)> __f_;
promise<result_type> __p_;
__packaged_task_function<_Rp(_ArgTypes...)> __f_;
promise<_Rp> __p_;

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

// result retrieval
_LIBCPP_HIDE_FROM_ABI future<result_type> get_future() { return __p_.get_future(); }
_LIBCPP_HIDE_FROM_ABI future<_Rp> get_future() { return __p_.get_future(); }

// execution
_LIBCPP_HIDE_FROM_ABI void operator()(_ArgTypes... __args);
Expand Down Expand Up @@ -1700,17 +1700,17 @@ template <class _Rp, class... _ArgTypes>
void packaged_task<_Rp(_ArgTypes...)>::reset() {
if (!valid())
__throw_future_error(future_errc::no_state);
__p_ = promise<result_type>();
__p_ = promise<_Rp>();
}

template <class... _ArgTypes>
class _LIBCPP_TEMPLATE_VIS packaged_task<void(_ArgTypes...)> {
public:
typedef void result_type; // extension
using result_type _LIBCPP_DEPRECATED = void; // extension

private:
__packaged_task_function<result_type(_ArgTypes...)> __f_;
promise<result_type> __p_;
__packaged_task_function<void(_ArgTypes...)> __f_;
promise<void> __p_;

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

// result retrieval
_LIBCPP_HIDE_FROM_ABI future<result_type> get_future() { return __p_.get_future(); }
_LIBCPP_HIDE_FROM_ABI future<void> get_future() { return __p_.get_future(); }

// execution
_LIBCPP_HIDE_FROM_ABI void operator()(_ArgTypes... __args);
Expand Down Expand Up @@ -1804,7 +1804,7 @@ template <class... _ArgTypes>
void packaged_task<void(_ArgTypes...)>::reset() {
if (!valid())
__throw_future_error(future_errc::no_state);
__p_ = promise<result_type>();
__p_ = promise<void>();
}

template <class _Rp, class... _ArgTypes>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// UNSUPPORTED: no-threads
// UNSUPPORTED: c++03

// <future>

// template<class R, class... ArgTypes>
// class packaged_task<R(ArgTypes...)>
// {
// public:
// typedef R result_type; // extension

// This libc++ extension is deprecated. See https://github.com/llvm/llvm-project/issues/112856.

#include <future>
#include <type_traits>

struct A {};

using RA = std::packaged_task<A(int, char)>::result_type; // expected-warning {{'result_type' is deprecated}}
using RV = std::packaged_task<void(int, char)>::result_type; // expected-warning {{'result_type' is deprecated}}
10 changes: 5 additions & 5 deletions libcxx/test/libcxx/thread/futures/futures.task/types.pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@

// This is a libc++ extension.

// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS

#include <future>
#include <type_traits>

#include "test_macros.h"

struct A {};

int main(int, char**)
{
static_assert((std::is_same<std::packaged_task<A(int, char)>::result_type, A>::value), "");
int main(int, char**) {
static_assert((std::is_same<std::packaged_task<A(int, char)>::result_type, A>::value), "");
static_assert((std::is_same<std::packaged_task<void(int, char)>::result_type, void>::value), "");

return 0;
}

0 comments on commit da7895d

Please sign in to comment.