[libcxx-commits] [libcxx] [libc++] Deprecate extension `packaged_task::result_type` (PR #122600)
A. Jiang via libcxx-commits
libcxx-commits at lists.llvm.org
Sat Jan 11 08:39:00 PST 2025
https://github.com/frederick-vs-ja created https://github.com/llvm/llvm-project/pull/122600
This extension is questionable and non-conforming. Perhaps we should deprecate and then remove it.
Towards #112856.
>From da7895d3ef45475fdf32bafe83e44df9716c2c66 Mon Sep 17 00:00:00 2001
From: "A. Jiang" <de34 at live.cn>
Date: Sun, 12 Jan 2025 00:36:39 +0800
Subject: [PATCH] [libc++] Deprecate extension `packaged_task::result_type`
This extension is questionable and non-conforming. Perhaps we should
deprecate and then remove it.
---
libcxx/docs/ReleaseNotes/20.rst | 4 +++
libcxx/include/future | 20 ++++++-------
.../futures/futures.task/type.depr.verify.cpp | 28 +++++++++++++++++++
.../futures/futures.task/types.pass.cpp | 10 +++----
4 files changed, 47 insertions(+), 15 deletions(-)
create mode 100644 libcxx/test/libcxx/thread/futures/futures.task/type.depr.verify.cpp
diff --git a/libcxx/docs/ReleaseNotes/20.rst b/libcxx/docs/ReleaseNotes/20.rst
index 228c3f3432c299..15940948655d7d 100644
--- a/libcxx/docs/ReleaseNotes/20.rst
+++ b/libcxx/docs/ReleaseNotes/20.rst
@@ -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
----------------------------------
@@ -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
---------------------
diff --git a/libcxx/include/future b/libcxx/include/future
index d777ed8d6016f3..72f3ed5ca5d270 100644
--- a/libcxx/include/future
+++ b/libcxx/include/future
@@ -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
@@ -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);
@@ -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
@@ -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);
@@ -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>
diff --git a/libcxx/test/libcxx/thread/futures/futures.task/type.depr.verify.cpp b/libcxx/test/libcxx/thread/futures/futures.task/type.depr.verify.cpp
new file mode 100644
index 00000000000000..4065637e9eb2a0
--- /dev/null
+++ b/libcxx/test/libcxx/thread/futures/futures.task/type.depr.verify.cpp
@@ -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}}
diff --git a/libcxx/test/libcxx/thread/futures/futures.task/types.pass.cpp b/libcxx/test/libcxx/thread/futures/futures.task/types.pass.cpp
index 1f17d745134717..659232caa46ecf 100644
--- a/libcxx/test/libcxx/thread/futures/futures.task/types.pass.cpp
+++ b/libcxx/test/libcxx/thread/futures/futures.task/types.pass.cpp
@@ -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;
}
More information about the libcxx-commits
mailing list