[libcxx-commits] [libcxx] [libc++][tuple][utility] P2968R2: Make `std::ignore` a first-class object (PR #97401)
Hristo Hristov via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Jul 9 11:40:11 PDT 2024
https://github.com/H-G-Hristov updated https://github.com/llvm/llvm-project/pull/97401
>From bd82810eb04cbdfaebeed6ad254831de1b687885 Mon Sep 17 00:00:00 2001
From: Hristo Hristov <hghristov.rmm at gmail.com>
Date: Tue, 2 Jul 2024 10:40:15 +0300
Subject: [PATCH 01/12] [libc++][tuple][utility] P2968R2 Make `std::ignore` a
first-class object
Implements as DR11: https://wg21.link/P2968R2
References:
- https://eel.is/c++draft/tuple.general
- https://eel.is/c++draft/tuple.syn
- https://eel.is/c++draft/tuple.creation
- https://github.com/cplusplus/draft/milestone/31
- https://github.com/cplusplus/papers/issues/1640
- https://cplusplus.github.io/LWG/issue2933
- https://cplusplus.github.io/LWG/issue3978
---
libcxx/docs/ReleaseNotes/19.rst | 1 +
libcxx/include/CMakeLists.txt | 1 +
libcxx/include/__tuple/ignore.h | 32 ++++++++++
libcxx/include/module.modulemap | 1 +
libcxx/include/tuple | 24 +++-----
libcxx/include/utility | 4 ++
.../tuple/tuple.general/ignore.pass.cpp | 61 +++++++++----------
7 files changed, 74 insertions(+), 50 deletions(-)
create mode 100644 libcxx/include/__tuple/ignore.h
diff --git a/libcxx/docs/ReleaseNotes/19.rst b/libcxx/docs/ReleaseNotes/19.rst
index d30021b7eb234..5c3737d79876e 100644
--- a/libcxx/docs/ReleaseNotes/19.rst
+++ b/libcxx/docs/ReleaseNotes/19.rst
@@ -46,6 +46,7 @@ Implemented Papers
- P2872R3 - Remove ``wstring_convert`` From C++26
- P3142R0 - Printing Blank Lines with ``println`` (as DR against C++23)
- P2944R3 - Comparisons for ``reference_wrapper`` (comparison operators for ``reference_wrapper`` only)
+- P2968R2 - Make ``std::ignore`` a first-class object (as DR against C++11)
- P2302R4 - ``std::ranges::contains``
- P1659R3 - ``std::ranges::starts_with`` and ``std::ranges::ends_with``
- P3029R1 - Better ``mdspan``'s CTAD
diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index 8d0ffd6ed725b..07dd25604a9c7 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -710,6 +710,7 @@ set(files
__thread/timed_backoff_policy.h
__tree
__tuple/find_index.h
+ __tuple/ignore.h
__tuple/make_tuple_types.h
__tuple/sfinae_helpers.h
__tuple/tuple_element.h
diff --git a/libcxx/include/__tuple/ignore.h b/libcxx/include/__tuple/ignore.h
new file mode 100644
index 0000000000000..2ddc850efccb3
--- /dev/null
+++ b/libcxx/include/__tuple/ignore.h
@@ -0,0 +1,32 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP___TUPLE_IGNORE_H
+#define _LIBCPP___TUPLE_IGNORE_H
+
+#include <__config>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+# pragma GCC system_header
+#endif
+
+#ifndef _LIBCPP_CXX03_LANG
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+struct __ignore_type {
+ _LIBCPP_HIDE_FROM_ABI constexpr const __ignore_type& operator=(const auto&) const noexcept { return *this; }
+};
+
+inline constexpr __ignore_type ignore;
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP_CXX03_LANG
+
+#endif // _LIBCPP___TUPLE_IGNORE_H
diff --git a/libcxx/include/module.modulemap b/libcxx/include/module.modulemap
index 9ffccf66ff094..4ad506781c489 100644
--- a/libcxx/include/module.modulemap
+++ b/libcxx/include/module.modulemap
@@ -1840,6 +1840,7 @@ module std_private_thread_thread [system] {
module std_private_thread_timed_backoff_policy [system] { header "__thread/timed_backoff_policy.h" }
module std_private_tuple_find_index [system] { header "__tuple/find_index.h" }
+module std_private_tuple_ignore [system] { header "__tuple/ignore.h" }
module std_private_tuple_make_tuple_types [system] { header "__tuple/make_tuple_types.h" }
module std_private_tuple_tuple_like_no_subrange [system] {
header "__tuple/tuple_like_no_subrange.h"
diff --git a/libcxx/include/tuple b/libcxx/include/tuple
index 26652ffe81e9f..d2f6e19ede68d 100644
--- a/libcxx/include/tuple
+++ b/libcxx/include/tuple
@@ -132,7 +132,12 @@ tuple(allocator_arg_t, Alloc, pair<T1, T2>) -> tuple<T1, T2>; // since C++
template <class Alloc, class ...T>
tuple(allocator_arg_t, Alloc, tuple<T...>) -> tuple<T...>; // since C++17
-inline constexpr unspecified ignore;
++struct ignore-type { // exposition only
++ constexpr const ignore-type&
++ operator=(const auto &) const noexcept
++ { return *this; }
++};
+inline constexpr ignore-type ignore;
template <class... T> tuple<V...> make_tuple(T&&...); // constexpr in C++14
template <class... T> tuple<ATypes...> forward_as_tuple(T&&...) noexcept; // constexpr in C++14
@@ -215,6 +220,7 @@ template <class... Types>
#include <__memory/allocator_arg_t.h>
#include <__memory/uses_allocator.h>
#include <__tuple/find_index.h>
+#include <__tuple/ignore.h>
#include <__tuple/make_tuple_types.h>
#include <__tuple/sfinae_helpers.h>
#include <__tuple/tuple_element.h>
@@ -1112,22 +1118,6 @@ inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 tuple<_Tp&...> tie(_T
return tuple<_Tp&...>(__t...);
}
-template <class _Up>
-struct __ignore_t {
- template <class _Tp>
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const __ignore_t& operator=(_Tp&&) const {
- return *this;
- }
-};
-
-# if _LIBCPP_STD_VER >= 17
-inline constexpr __ignore_t<unsigned char> ignore = __ignore_t<unsigned char>();
-# else
-namespace {
-constexpr __ignore_t<unsigned char> ignore = __ignore_t<unsigned char>();
-} // namespace
-# endif
-
template <class... _Tp>
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 tuple<typename __unwrap_ref_decay<_Tp>::type...>
make_tuple(_Tp&&... __t) {
diff --git a/libcxx/include/utility b/libcxx/include/utility
index 90713da621c5d..f2f0052df2755 100644
--- a/libcxx/include/utility
+++ b/libcxx/include/utility
@@ -274,6 +274,10 @@ template <class T>
#include <compare>
#include <initializer_list>
+// [tuple.creation]
+
+#include <__tuple/ignore.h>
+
// [tuple.helper]
#include <__tuple/tuple_element.h>
#include <__tuple/tuple_size.h>
diff --git a/libcxx/test/std/utilities/tuple/tuple.general/ignore.pass.cpp b/libcxx/test/std/utilities/tuple/tuple.general/ignore.pass.cpp
index 769c55e10fc43..a3e62e83bcdc9 100644
--- a/libcxx/test/std/utilities/tuple/tuple.general/ignore.pass.cpp
+++ b/libcxx/test/std/utilities/tuple/tuple.general/ignore.pass.cpp
@@ -6,11 +6,11 @@
//
//===----------------------------------------------------------------------===//
-// <tuple>
+// UNSUPPORTED: c++03
-// constexpr unspecified ignore;
+// <tuple>
-// UNSUPPORTED: c++03
+// inline constexpr ignore-type ignore;
#include <cassert>
#include <tuple>
@@ -18,39 +18,34 @@
#include "test_macros.h"
-constexpr bool test_ignore_constexpr()
-{
-#if TEST_STD_VER > 11
- { // Test that std::ignore provides constexpr converting assignment.
- auto& res = (std::ignore = 42);
- assert(&res == &std::ignore);
- }
- { // Test that std::ignore provides constexpr copy/move constructors
- auto copy = std::ignore;
- auto moved = std::move(copy);
- ((void)moved);
- }
- { // Test that std::ignore provides constexpr copy/move assignment
- auto copy = std::ignore;
- copy = std::ignore;
- auto moved = std::ignore;
- moved = std::move(copy);
- }
-#endif
- return true;
+constexpr bool test() {
+ {
+ constexpr auto& ignore_v = std::ignore;
+ ((void)ignore_v);
+ }
+ { // Test that std::ignore provides constexpr converting assignment.
+ auto& res = (std::ignore = 42);
+ assert(&res == &std::ignore);
+ }
+ { // Test that std::ignore provides constexpr copy/move constructors
+ auto copy = (std::ignore = 42);
+ auto moved = std::move(copy);
+ ((void)moved);
+ }
+ { // Test that std::ignore provides constexpr copy/move assignment
+ auto copy = (std::ignore = 82);
+ copy = std::ignore;
+ auto moved = (std::ignore = 94);
+ moved = std::move(copy);
+ }
+
+ return true;
}
int main(int, char**) {
- {
- constexpr auto& ignore_v = std::ignore;
- ((void)ignore_v);
- }
- {
- static_assert(test_ignore_constexpr(), "");
- }
- {
- LIBCPP_STATIC_ASSERT(std::is_trivial<decltype(std::ignore)>::value, "");
- }
+ test();
+ static_assert(test(), "");
+ LIBCPP_STATIC_ASSERT(std::is_trivial<decltype(std::ignore)>::value, "");
return 0;
}
>From 1aa5e01df162a3cae796cceffb45ca5aa178f3d5 Mon Sep 17 00:00:00 2001
From: Hristo Hristov <hghristov.rmm at gmail.com>
Date: Wed, 3 Jul 2024 07:27:21 +0300
Subject: [PATCH 02/12] Fixed C++11
---
libcxx/include/__tuple/ignore.h | 3 +-
.../tuple/tuple.general/ignore.pass.cpp | 33 ++++++++++++++++---
2 files changed, 31 insertions(+), 5 deletions(-)
diff --git a/libcxx/include/__tuple/ignore.h b/libcxx/include/__tuple/ignore.h
index 2ddc850efccb3..a8261de7d73b4 100644
--- a/libcxx/include/__tuple/ignore.h
+++ b/libcxx/include/__tuple/ignore.h
@@ -20,7 +20,8 @@
_LIBCPP_BEGIN_NAMESPACE_STD
struct __ignore_type {
- _LIBCPP_HIDE_FROM_ABI constexpr const __ignore_type& operator=(const auto&) const noexcept { return *this; }
+ template <class _Tp>
+ _LIBCPP_HIDE_FROM_ABI constexpr const __ignore_type& operator=(const _Tp&) const noexcept { return *this; }
};
inline constexpr __ignore_type ignore;
diff --git a/libcxx/test/std/utilities/tuple/tuple.general/ignore.pass.cpp b/libcxx/test/std/utilities/tuple/tuple.general/ignore.pass.cpp
index a3e62e83bcdc9..34a7607b82afc 100644
--- a/libcxx/test/std/utilities/tuple/tuple.general/ignore.pass.cpp
+++ b/libcxx/test/std/utilities/tuple/tuple.general/ignore.pass.cpp
@@ -18,13 +18,38 @@
#include "test_macros.h"
-constexpr bool test() {
+static_assert(std::is_trivial<decltype(std::ignore)>::value, "");
+
+void test() {
+ {
+ [[maybe_unused]] constexpr auto& ignore_v = std::ignore;
+ }
+ { // Test that std::ignore provides constexpr converting assignment.
+ constexpr auto& res = (std::ignore = 42);
+ static_assert(noexcept(res = (std::ignore = 42)), "Must be noexcept");
+ assert(&res == &std::ignore);
+ }
+ { // Test that std::ignore provides constexpr copy/move constructors
+ constexpr auto copy = std::ignore;
+ [[maybe_unused]] constexpr auto moved = std::move(copy);
+ }
+ { // Test that std::ignore provides constexpr copy/move assignment
+ constexpr auto copy = std::ignore;
+ copy = std::ignore;
+ constexpr auto moved = std::ignore;
+ moved = std::move(copy);
+ }
+}
+
+constexpr bool test_constexpr() {
+#if TEST_STD_VER >= 14
{
- constexpr auto& ignore_v = std::ignore;
+ auto& ignore_v = std::ignore;
((void)ignore_v);
}
{ // Test that std::ignore provides constexpr converting assignment.
auto& res = (std::ignore = 42);
+ static_assert(noexcept(res = (std::ignore = 42)), "Must be noexcept");
assert(&res == &std::ignore);
}
{ // Test that std::ignore provides constexpr copy/move constructors
@@ -38,14 +63,14 @@ constexpr bool test() {
auto moved = (std::ignore = 94);
moved = std::move(copy);
}
+#endif
return true;
}
int main(int, char**) {
test();
- static_assert(test(), "");
- LIBCPP_STATIC_ASSERT(std::is_trivial<decltype(std::ignore)>::value, "");
+ static_assert(test_constexpr(), "");
return 0;
}
>From cf0e266a02ab7cba91caeb9377eae7d454ca28ce Mon Sep 17 00:00:00 2001
From: Hristo Hristov <hghristov.rmm at gmail.com>
Date: Wed, 3 Jul 2024 07:29:38 +0300
Subject: [PATCH 03/12] Updated test
---
.../tuple/tuple.general/ignore.pass.cpp | 42 ++-----------------
1 file changed, 4 insertions(+), 38 deletions(-)
diff --git a/libcxx/test/std/utilities/tuple/tuple.general/ignore.pass.cpp b/libcxx/test/std/utilities/tuple/tuple.general/ignore.pass.cpp
index 34a7607b82afc..22b7b2fdebe41 100644
--- a/libcxx/test/std/utilities/tuple/tuple.general/ignore.pass.cpp
+++ b/libcxx/test/std/utilities/tuple/tuple.general/ignore.pass.cpp
@@ -18,19 +18,17 @@
#include "test_macros.h"
-static_assert(std::is_trivial<decltype(std::ignore)>::value, "");
+int main(int, char**) {
+ static_assert(std::is_trivial<decltype(std::ignore)>::value, "");
-void test() {
- {
- [[maybe_unused]] constexpr auto& ignore_v = std::ignore;
- }
+ { [[maybe_unused]] constexpr auto& ignore_v = std::ignore; }
{ // Test that std::ignore provides constexpr converting assignment.
constexpr auto& res = (std::ignore = 42);
static_assert(noexcept(res = (std::ignore = 42)), "Must be noexcept");
assert(&res == &std::ignore);
}
{ // Test that std::ignore provides constexpr copy/move constructors
- constexpr auto copy = std::ignore;
+ constexpr auto copy = std::ignore;
[[maybe_unused]] constexpr auto moved = std::move(copy);
}
{ // Test that std::ignore provides constexpr copy/move assignment
@@ -39,38 +37,6 @@ void test() {
constexpr auto moved = std::ignore;
moved = std::move(copy);
}
-}
-
-constexpr bool test_constexpr() {
-#if TEST_STD_VER >= 14
- {
- auto& ignore_v = std::ignore;
- ((void)ignore_v);
- }
- { // Test that std::ignore provides constexpr converting assignment.
- auto& res = (std::ignore = 42);
- static_assert(noexcept(res = (std::ignore = 42)), "Must be noexcept");
- assert(&res == &std::ignore);
- }
- { // Test that std::ignore provides constexpr copy/move constructors
- auto copy = (std::ignore = 42);
- auto moved = std::move(copy);
- ((void)moved);
- }
- { // Test that std::ignore provides constexpr copy/move assignment
- auto copy = (std::ignore = 82);
- copy = std::ignore;
- auto moved = (std::ignore = 94);
- moved = std::move(copy);
- }
-#endif
-
- return true;
-}
-
-int main(int, char**) {
- test();
- static_assert(test_constexpr(), "");
return 0;
}
>From dd7e8385dc03bea603a3f8bec41cc76165f04a4e Mon Sep 17 00:00:00 2001
From: Hristo Hristov <hghristov.rmm at gmail.com>
Date: Wed, 3 Jul 2024 07:52:08 +0300
Subject: [PATCH 04/12] Formatting
---
libcxx/include/__tuple/ignore.h | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/libcxx/include/__tuple/ignore.h b/libcxx/include/__tuple/ignore.h
index a8261de7d73b4..a00fc7e7d5b85 100644
--- a/libcxx/include/__tuple/ignore.h
+++ b/libcxx/include/__tuple/ignore.h
@@ -21,7 +21,9 @@ _LIBCPP_BEGIN_NAMESPACE_STD
struct __ignore_type {
template <class _Tp>
- _LIBCPP_HIDE_FROM_ABI constexpr const __ignore_type& operator=(const _Tp&) const noexcept { return *this; }
+ _LIBCPP_HIDE_FROM_ABI constexpr const __ignore_type& operator=(const _Tp&) const noexcept {
+ return *this;
+ }
};
inline constexpr __ignore_type ignore;
>From 99900ba54551053177daefb8def4e1b74f321915 Mon Sep 17 00:00:00 2001
From: Hristo Hristov <hghristov.rmm at gmail.com>
Date: Fri, 5 Jul 2024 14:36:40 +0300
Subject: [PATCH 05/12] Updated tests
---
.../tuple/tuple.general/ignore.pass.cpp | 26 ++++++++++++++++++-
1 file changed, 25 insertions(+), 1 deletion(-)
diff --git a/libcxx/test/std/utilities/tuple/tuple.general/ignore.pass.cpp b/libcxx/test/std/utilities/tuple/tuple.general/ignore.pass.cpp
index 22b7b2fdebe41..49f3249a4e413 100644
--- a/libcxx/test/std/utilities/tuple/tuple.general/ignore.pass.cpp
+++ b/libcxx/test/std/utilities/tuple/tuple.general/ignore.pass.cpp
@@ -13,13 +13,29 @@
// inline constexpr ignore-type ignore;
#include <cassert>
+#include <cstdint>
#include <tuple>
#include <type_traits>
#include "test_macros.h"
+static_assert(std::is_trivial<decltype(std::ignore)>::value, "");
+
+#if TEST_STD_VER >= 17
+[[nodiscard]] constexpr int test_nodiscard() { return 8294; }
+#endif
+
+constexpr bool test() {
+#if TEST_STD_VER >= 17
+ { std::ignore = test_nodiscard(); }
+#endif
+
+ return true;
+}
+
int main(int, char**) {
- static_assert(std::is_trivial<decltype(std::ignore)>::value, "");
+ test();
+ static_assert(test(), "");
{ [[maybe_unused]] constexpr auto& ignore_v = std::ignore; }
{ // Test that std::ignore provides constexpr converting assignment.
@@ -27,6 +43,14 @@ int main(int, char**) {
static_assert(noexcept(res = (std::ignore = 42)), "Must be noexcept");
assert(&res == &std::ignore);
}
+ { // Test bit-field binding.
+ struct S {
+ unsigned int bf : 3;
+ };
+ constexpr S s{0b010};
+ constexpr auto& res = (std::ignore = s.bf);
+ assert(&res == &std::ignore);
+ }
{ // Test that std::ignore provides constexpr copy/move constructors
constexpr auto copy = std::ignore;
[[maybe_unused]] constexpr auto moved = std::move(copy);
>From be73bf4c9644f786fd644f5ee62871029450e7bf Mon Sep 17 00:00:00 2001
From: Hristo Hristov <hghristov.rmm at gmail.com>
Date: Sat, 6 Jul 2024 17:08:09 +0300
Subject: [PATCH 06/12] Added `include<>` tests
---
.../ignore.include.compile.pass.cpp | 19 +++++++++++++++++++
.../ignore/ignore.include.compile.pass.cpp | 19 +++++++++++++++++++
2 files changed, 38 insertions(+)
create mode 100644 libcxx/test/std/utilities/tuple/tuple.general/ignore.include.compile.pass.cpp
create mode 100644 libcxx/test/std/utilities/utility/ignore/ignore.include.compile.pass.cpp
diff --git a/libcxx/test/std/utilities/tuple/tuple.general/ignore.include.compile.pass.cpp b/libcxx/test/std/utilities/tuple/tuple.general/ignore.include.compile.pass.cpp
new file mode 100644
index 0000000000000..049d484408b11
--- /dev/null
+++ b/libcxx/test/std/utilities/tuple/tuple.general/ignore.include.compile.pass.cpp
@@ -0,0 +1,19 @@
+//===----------------------------------------------------------------------===//
+//
+// 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: c++03
+
+// <tuple>
+
+// inline constexpr ignore-type ignore;
+
+#include <tuple>
+
+int main(int, char**) {
+ { [[maybe_unused]] constexpr auto& ignore_v = std::ignore; }
+}
diff --git a/libcxx/test/std/utilities/utility/ignore/ignore.include.compile.pass.cpp b/libcxx/test/std/utilities/utility/ignore/ignore.include.compile.pass.cpp
new file mode 100644
index 0000000000000..be6d61506af01
--- /dev/null
+++ b/libcxx/test/std/utilities/utility/ignore/ignore.include.compile.pass.cpp
@@ -0,0 +1,19 @@
+//===----------------------------------------------------------------------===//
+//
+// 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: c++03
+
+// <utility>
+
+// inline constexpr ignore-type ignore;
+
+#include <utility>
+
+int main(int, char**) {
+ { [[maybe_unused]] constexpr auto& ignore_v = std::ignore; }
+}
>From 4a124c9517828e703693fd470735c9b4482256a4 Mon Sep 17 00:00:00 2001
From: Hristo Hristov <hghristov.rmm at gmail.com>
Date: Sun, 7 Jul 2024 14:13:08 +0300
Subject: [PATCH 07/12] Addressed comments
---
libcxx/docs/ReleaseNotes/19.rst | 5 +-
libcxx/include/__tuple/ignore.h | 5 +-
.../tuple/tuple.general/ignore.pass.cpp | 50 ++++++++++---------
3 files changed, 35 insertions(+), 25 deletions(-)
diff --git a/libcxx/docs/ReleaseNotes/19.rst b/libcxx/docs/ReleaseNotes/19.rst
index 5c3737d79876e..f72e13cf6d9af 100644
--- a/libcxx/docs/ReleaseNotes/19.rst
+++ b/libcxx/docs/ReleaseNotes/19.rst
@@ -46,7 +46,7 @@ Implemented Papers
- P2872R3 - Remove ``wstring_convert`` From C++26
- P3142R0 - Printing Blank Lines with ``println`` (as DR against C++23)
- P2944R3 - Comparisons for ``reference_wrapper`` (comparison operators for ``reference_wrapper`` only)
-- P2968R2 - Make ``std::ignore`` a first-class object (as DR against C++11)
+- P2968R2 - Make ``std::ignore`` a first-class object
- P2302R4 - ``std::ranges::contains``
- P1659R3 - ``std::ranges::starts_with`` and ``std::ranges::ends_with``
- P3029R1 - Better ``mdspan``'s CTAD
@@ -75,6 +75,9 @@ Improvements and New Features
- The formatting library is updated to Unicode 15.1.0.
+- ``std::ignore``\s ``const __ignore_t& operator=(_Tp&&) const`` was changed to
+ ``const __ignore_type& operator=(const _Tp&) const noexcept`` for all language versions.
+
Deprecations and Removals
-------------------------
diff --git a/libcxx/include/__tuple/ignore.h b/libcxx/include/__tuple/ignore.h
index a00fc7e7d5b85..d7c3a18c14775 100644
--- a/libcxx/include/__tuple/ignore.h
+++ b/libcxx/include/__tuple/ignore.h
@@ -26,7 +26,10 @@ struct __ignore_type {
}
};
-inline constexpr __ignore_type ignore;
+# if _LIBCPP_STD_VER >= 17
+inline
+# endif
+ _LIBCPP_CONSTEXPR_SINCE_CXX14 __ignore_type ignore;
_LIBCPP_END_NAMESPACE_STD
diff --git a/libcxx/test/std/utilities/tuple/tuple.general/ignore.pass.cpp b/libcxx/test/std/utilities/tuple/tuple.general/ignore.pass.cpp
index 49f3249a4e413..120a41423eceb 100644
--- a/libcxx/test/std/utilities/tuple/tuple.general/ignore.pass.cpp
+++ b/libcxx/test/std/utilities/tuple/tuple.general/ignore.pass.cpp
@@ -25,21 +25,12 @@ static_assert(std::is_trivial<decltype(std::ignore)>::value, "");
[[nodiscard]] constexpr int test_nodiscard() { return 8294; }
#endif
-constexpr bool test() {
-#if TEST_STD_VER >= 17
- { std::ignore = test_nodiscard(); }
-#endif
- return true;
-}
+TEST_CONSTEXPR_CXX14 bool test() {
+ { [[maybe_unused]] auto& ignore_v = std::ignore; }
-int main(int, char**) {
- test();
- static_assert(test(), "");
-
- { [[maybe_unused]] constexpr auto& ignore_v = std::ignore; }
- { // Test that std::ignore provides constexpr converting assignment.
- constexpr auto& res = (std::ignore = 42);
+ { // Test that std::ignore provides converting assignment.
+ auto& res = (std::ignore = 42);
static_assert(noexcept(res = (std::ignore = 42)), "Must be noexcept");
assert(&res == &std::ignore);
}
@@ -47,20 +38,33 @@ int main(int, char**) {
struct S {
unsigned int bf : 3;
};
- constexpr S s{0b010};
- constexpr auto& res = (std::ignore = s.bf);
+ S s{0b010};
+ auto& res = (std::ignore = s.bf);
assert(&res == &std::ignore);
}
- { // Test that std::ignore provides constexpr copy/move constructors
- constexpr auto copy = std::ignore;
- [[maybe_unused]] constexpr auto moved = std::move(copy);
+ { // Test that std::ignore provides copy/move constructors
+ auto copy = std::ignore;
+ [[maybe_unused]] auto moved = std::move(copy);
}
- { // Test that std::ignore provides constexpr copy/move assignment
- constexpr auto copy = std::ignore;
- copy = std::ignore;
- constexpr auto moved = std::ignore;
- moved = std::move(copy);
+ { // Test that std::ignore provides copy/move assignment
+ auto copy = std::ignore;
+ copy = std::ignore;
+ auto moved = std::ignore;
+ moved = std::move(copy);
}
+#if TEST_STD_VER >= 17
+ { std::ignore = test_nodiscard(); }
+#endif
+
+ return true;
+}
+
+int main(int, char**) {
+ test();
+#if TEST_STD_VER >= 14
+ static_assert(test(), "");
+#endif
+
return 0;
}
>From f79cd96f4da863d8c90ec3c4457b1955a40c314e Mon Sep 17 00:00:00 2001
From: Hristo Hristov <hghristov.rmm at gmail.com>
Date: Sun, 7 Jul 2024 14:19:44 +0300
Subject: [PATCH 08/12] Fixes
---
.../tuple/tuple.general/ignore.include.compile.pass.cpp | 2 +-
libcxx/test/std/utilities/tuple/tuple.general/ignore.pass.cpp | 1 -
.../utilities/utility/ignore/ignore.include.compile.pass.cpp | 2 +-
3 files changed, 2 insertions(+), 3 deletions(-)
diff --git a/libcxx/test/std/utilities/tuple/tuple.general/ignore.include.compile.pass.cpp b/libcxx/test/std/utilities/tuple/tuple.general/ignore.include.compile.pass.cpp
index 049d484408b11..dfa0272ed1248 100644
--- a/libcxx/test/std/utilities/tuple/tuple.general/ignore.include.compile.pass.cpp
+++ b/libcxx/test/std/utilities/tuple/tuple.general/ignore.include.compile.pass.cpp
@@ -15,5 +15,5 @@
#include <tuple>
int main(int, char**) {
- { [[maybe_unused]] constexpr auto& ignore_v = std::ignore; }
+ { [[maybe_unused]] TEST_CONSTEXPR_CXX14 auto& ignore_v = std::ignore; }
}
diff --git a/libcxx/test/std/utilities/tuple/tuple.general/ignore.pass.cpp b/libcxx/test/std/utilities/tuple/tuple.general/ignore.pass.cpp
index 120a41423eceb..525ffde5cf177 100644
--- a/libcxx/test/std/utilities/tuple/tuple.general/ignore.pass.cpp
+++ b/libcxx/test/std/utilities/tuple/tuple.general/ignore.pass.cpp
@@ -25,7 +25,6 @@ static_assert(std::is_trivial<decltype(std::ignore)>::value, "");
[[nodiscard]] constexpr int test_nodiscard() { return 8294; }
#endif
-
TEST_CONSTEXPR_CXX14 bool test() {
{ [[maybe_unused]] auto& ignore_v = std::ignore; }
diff --git a/libcxx/test/std/utilities/utility/ignore/ignore.include.compile.pass.cpp b/libcxx/test/std/utilities/utility/ignore/ignore.include.compile.pass.cpp
index be6d61506af01..1e925adf9cccd 100644
--- a/libcxx/test/std/utilities/utility/ignore/ignore.include.compile.pass.cpp
+++ b/libcxx/test/std/utilities/utility/ignore/ignore.include.compile.pass.cpp
@@ -15,5 +15,5 @@
#include <utility>
int main(int, char**) {
- { [[maybe_unused]] constexpr auto& ignore_v = std::ignore; }
+ { [[maybe_unused]] TEST_CONSTEXPR_CXX14 auto& ignore_v = std::ignore; }
}
>From 6ceb5c7ae6378c4937485641db85f2c0923d84ed Mon Sep 17 00:00:00 2001
From: Hristo Hristov <hghristov.rmm at gmail.com>
Date: Sun, 7 Jul 2024 14:20:20 +0300
Subject: [PATCH 09/12] More fixes
---
.../tuple/tuple.general/ignore.include.compile.pass.cpp | 2 ++
.../utilities/utility/ignore/ignore.include.compile.pass.cpp | 2 ++
2 files changed, 4 insertions(+)
diff --git a/libcxx/test/std/utilities/tuple/tuple.general/ignore.include.compile.pass.cpp b/libcxx/test/std/utilities/tuple/tuple.general/ignore.include.compile.pass.cpp
index dfa0272ed1248..ae550ee1cd578 100644
--- a/libcxx/test/std/utilities/tuple/tuple.general/ignore.include.compile.pass.cpp
+++ b/libcxx/test/std/utilities/tuple/tuple.general/ignore.include.compile.pass.cpp
@@ -14,6 +14,8 @@
#include <tuple>
+#include "test_macros.h"
+
int main(int, char**) {
{ [[maybe_unused]] TEST_CONSTEXPR_CXX14 auto& ignore_v = std::ignore; }
}
diff --git a/libcxx/test/std/utilities/utility/ignore/ignore.include.compile.pass.cpp b/libcxx/test/std/utilities/utility/ignore/ignore.include.compile.pass.cpp
index 1e925adf9cccd..64ebb051ea05d 100644
--- a/libcxx/test/std/utilities/utility/ignore/ignore.include.compile.pass.cpp
+++ b/libcxx/test/std/utilities/utility/ignore/ignore.include.compile.pass.cpp
@@ -14,6 +14,8 @@
#include <utility>
+#include "test_macros.h"
+
int main(int, char**) {
{ [[maybe_unused]] TEST_CONSTEXPR_CXX14 auto& ignore_v = std::ignore; }
}
>From 48132c91cd5387998ab5001cf59cd89b299a236f Mon Sep 17 00:00:00 2001
From: Hristo Hristov <hghristov.rmm at gmail.com>
Date: Sun, 7 Jul 2024 14:55:41 +0300
Subject: [PATCH 10/12] Fixes
---
libcxx/include/__tuple/ignore.h | 7 ++++---
libcxx/include/tuple | 10 +++++-----
2 files changed, 9 insertions(+), 8 deletions(-)
diff --git a/libcxx/include/__tuple/ignore.h b/libcxx/include/__tuple/ignore.h
index d7c3a18c14775..43cce5387411b 100644
--- a/libcxx/include/__tuple/ignore.h
+++ b/libcxx/include/__tuple/ignore.h
@@ -21,15 +21,16 @@ _LIBCPP_BEGIN_NAMESPACE_STD
struct __ignore_type {
template <class _Tp>
- _LIBCPP_HIDE_FROM_ABI constexpr const __ignore_type& operator=(const _Tp&) const noexcept {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const __ignore_type& operator=(const _Tp&) const noexcept {
return *this;
}
};
# if _LIBCPP_STD_VER >= 17
-inline
+inline constexpr __ignore_type ignore;
+# else
+constexpr __ignore_type ignore;
# endif
- _LIBCPP_CONSTEXPR_SINCE_CXX14 __ignore_type ignore;
_LIBCPP_END_NAMESPACE_STD
diff --git a/libcxx/include/tuple b/libcxx/include/tuple
index d2f6e19ede68d..081b90c7bbec5 100644
--- a/libcxx/include/tuple
+++ b/libcxx/include/tuple
@@ -132,11 +132,11 @@ tuple(allocator_arg_t, Alloc, pair<T1, T2>) -> tuple<T1, T2>; // since C++
template <class Alloc, class ...T>
tuple(allocator_arg_t, Alloc, tuple<T...>) -> tuple<T...>; // since C++17
-+struct ignore-type { // exposition only
-+ constexpr const ignore-type&
-+ operator=(const auto &) const noexcept
-+ { return *this; }
-+};
+struct ignore-type { // exposition only // Since C++26
+ constexpr const ignore-type&
+ operator=(const auto &) const noexcept
+ { return *this; }
+};
inline constexpr ignore-type ignore;
template <class... T> tuple<V...> make_tuple(T&&...); // constexpr in C++14
>From 1cacd7119e5298f08249749af49e09a79370bcf8 Mon Sep 17 00:00:00 2001
From: Hristo Hristov <hghristov.rmm at gmail.com>
Date: Sun, 7 Jul 2024 15:03:02 +0300
Subject: [PATCH 11/12] Addressed review comments
---
.../tuple/tuple.general/ignore.include.compile.pass.cpp | 9 ++++-----
.../utility/ignore/ignore.include.compile.pass.cpp | 9 ++++-----
2 files changed, 8 insertions(+), 10 deletions(-)
diff --git a/libcxx/test/std/utilities/tuple/tuple.general/ignore.include.compile.pass.cpp b/libcxx/test/std/utilities/tuple/tuple.general/ignore.include.compile.pass.cpp
index ae550ee1cd578..8960066058a1f 100644
--- a/libcxx/test/std/utilities/tuple/tuple.general/ignore.include.compile.pass.cpp
+++ b/libcxx/test/std/utilities/tuple/tuple.general/ignore.include.compile.pass.cpp
@@ -12,10 +12,9 @@
// inline constexpr ignore-type ignore;
-#include <tuple>
+// std::ignore should be provided by the headers <tuple> and <utility>.
+// This tests validates its presence in <tuple>.
-#include "test_macros.h"
+#include <tuple>
-int main(int, char**) {
- { [[maybe_unused]] TEST_CONSTEXPR_CXX14 auto& ignore_v = std::ignore; }
-}
+[[maybe_unused]] auto& ignore_v = std::ignore;
diff --git a/libcxx/test/std/utilities/utility/ignore/ignore.include.compile.pass.cpp b/libcxx/test/std/utilities/utility/ignore/ignore.include.compile.pass.cpp
index 64ebb051ea05d..5d180141f2a20 100644
--- a/libcxx/test/std/utilities/utility/ignore/ignore.include.compile.pass.cpp
+++ b/libcxx/test/std/utilities/utility/ignore/ignore.include.compile.pass.cpp
@@ -12,10 +12,9 @@
// inline constexpr ignore-type ignore;
-#include <utility>
+// std::ignore should be provided by the headers <tuple> and <utility>.
+// This tests validates its presence in <utility>.
-#include "test_macros.h"
+#include <utility>
-int main(int, char**) {
- { [[maybe_unused]] TEST_CONSTEXPR_CXX14 auto& ignore_v = std::ignore; }
-}
+[[maybe_unused]] auto& ignore_v = std::ignore;
>From 1689a305afbc22fd543bdcb574490630cfa64cdc Mon Sep 17 00:00:00 2001
From: Hristo Hristov <hghristov.rmm at gmail.com>
Date: Sun, 7 Jul 2024 15:04:21 +0300
Subject: [PATCH 12/12] Fixed a typo
---
.../tuple/tuple.general/ignore.include.compile.pass.cpp | 2 +-
.../utilities/utility/ignore/ignore.include.compile.pass.cpp | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/libcxx/test/std/utilities/tuple/tuple.general/ignore.include.compile.pass.cpp b/libcxx/test/std/utilities/tuple/tuple.general/ignore.include.compile.pass.cpp
index 8960066058a1f..0fdf0d0af52b9 100644
--- a/libcxx/test/std/utilities/tuple/tuple.general/ignore.include.compile.pass.cpp
+++ b/libcxx/test/std/utilities/tuple/tuple.general/ignore.include.compile.pass.cpp
@@ -13,7 +13,7 @@
// inline constexpr ignore-type ignore;
// std::ignore should be provided by the headers <tuple> and <utility>.
-// This tests validates its presence in <tuple>.
+// This test validates its presence in <tuple>.
#include <tuple>
diff --git a/libcxx/test/std/utilities/utility/ignore/ignore.include.compile.pass.cpp b/libcxx/test/std/utilities/utility/ignore/ignore.include.compile.pass.cpp
index 5d180141f2a20..3aa74397acf20 100644
--- a/libcxx/test/std/utilities/utility/ignore/ignore.include.compile.pass.cpp
+++ b/libcxx/test/std/utilities/utility/ignore/ignore.include.compile.pass.cpp
@@ -13,7 +13,7 @@
// inline constexpr ignore-type ignore;
// std::ignore should be provided by the headers <tuple> and <utility>.
-// This tests validates its presence in <utility>.
+// This test validates its presence in <utility>.
#include <utility>
More information about the libcxx-commits
mailing list