[libcxx-commits] [libcxx] [libc++][tuple][utility] P2968R2 Make `std::ignore` a first-class object (PR #97401)

Mark de Wever via libcxx-commits libcxx-commits at lists.llvm.org
Fri Jul 5 11:16:02 PDT 2024


================
@@ -6,51 +6,61 @@
 //
 //===----------------------------------------------------------------------===//
 
+// UNSUPPORTED: c++03
+
 // <tuple>
 
-// constexpr unspecified ignore;
-
-// UNSUPPORTED: c++03
+// inline constexpr ignore-type ignore;
 
 #include <cassert>
+#include <cstdint>
 #include <tuple>
 #include <type_traits>
 
 #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);
-    }
+static_assert(std::is_trivial<decltype(std::ignore)>::value, "");
+
+#if TEST_STD_VER >= 17
+[[nodiscard]] constexpr int test_nodiscard() { return 8294; }
 #endif
-    return true;
+
+constexpr bool test() {
+#if TEST_STD_VER >= 17
+  { std::ignore = test_nodiscard(); }
+#endif
+
+  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(), "");
+
+  { [[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 bit-field binding.
----------------
mordante wrote:

I really like to see you added a test for bit-fields! 

https://github.com/llvm/llvm-project/pull/97401


More information about the libcxx-commits mailing list