[libcxx-commits] [libcxx] 789845e - [libc++] Mini-cleanup for `[[nodiscard]]` (#172275)

via libcxx-commits libcxx-commits at lists.llvm.org
Sun Dec 21 08:33:01 PST 2025


Author: A. Jiang
Date: 2025-12-22T00:32:57+08:00
New Revision: 789845e319bbf346d42ee2c0090a9b8e153797a2

URL: https://github.com/llvm/llvm-project/commit/789845e319bbf346d42ee2c0090a9b8e153797a2
DIFF: https://github.com/llvm/llvm-project/commit/789845e319bbf346d42ee2c0090a9b8e153797a2.diff

LOG: [libc++] Mini-cleanup for `[[nodiscard]]` (#172275)

1. Remove incorrect `[[nodiscard]]` from compound assignment operators
in `<__filesystem/copy_options.h>`. Also add regression tests.
2. Add missing `[[nodiscard]]` mark for `mdspan::size` in
`<__mdspan/mdspan.h>` and test it.
3. Enable verifying `[[nodiscard]]` in C++03 for various components.
These components are either present in C++03 or backported by libc++
from C++11/17.

Added: 
    

Modified: 
    libcxx/include/__filesystem/copy_options.h
    libcxx/include/__mdspan/mdspan.h
    libcxx/test/libcxx/containers/views/mdspan/mdspan/assert.size.pass.cpp
    libcxx/test/libcxx/containers/views/mdspan/nodiscard.verify.cpp
    libcxx/test/libcxx/diagnostics/algorithm.nodiscard.verify.cpp
    libcxx/test/libcxx/diagnostics/array.nodiscard.verify.cpp
    libcxx/test/libcxx/diagnostics/cstdlib.nodiscard.verify.cpp
    libcxx/test/libcxx/diagnostics/deque.nodiscard.verify.cpp
    libcxx/test/libcxx/diagnostics/forward_list.nodiscard.verify.cpp
    libcxx/test/libcxx/diagnostics/functional.nodiscard.verify.cpp
    libcxx/test/libcxx/diagnostics/limits.nodiscard.verify.cpp
    libcxx/test/libcxx/diagnostics/list.nodiscard.verify.cpp
    libcxx/test/libcxx/diagnostics/mutex.nodiscard.verify.cpp
    libcxx/test/libcxx/diagnostics/new.nodiscard.verify.cpp
    libcxx/test/libcxx/diagnostics/queue.nodiscard.verify.cpp
    libcxx/test/libcxx/diagnostics/stack.nodiscard.verify.cpp
    libcxx/test/libcxx/diagnostics/string.nodiscard.verify.cpp
    libcxx/test/libcxx/diagnostics/string_view.nodiscard.verify.cpp
    libcxx/test/libcxx/diagnostics/utility.nodiscard.verify.cpp
    libcxx/test/libcxx/diagnostics/vector.nodiscard.verify.cpp
    libcxx/test/libcxx/thread/nodiscard.verify.cpp
    libcxx/test/libcxx/utilities/smartptr/nodiscard.verify.cpp
    libcxx/test/std/input.output/filesystems/fs.enum/enum.copy_options.pass.cpp

Removed: 
    


################################################################################
diff  --git a/libcxx/include/__filesystem/copy_options.h b/libcxx/include/__filesystem/copy_options.h
index cba719dbed1f6..d9039a6492fc2 100644
--- a/libcxx/include/__filesystem/copy_options.h
+++ b/libcxx/include/__filesystem/copy_options.h
@@ -50,15 +50,15 @@ enum class copy_options : unsigned short {
   return static_cast<copy_options>(~static_cast<unsigned short>(__lhs));
 }
 
-[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline copy_options& operator&=(copy_options& __lhs, copy_options __rhs) {
+_LIBCPP_HIDE_FROM_ABI inline copy_options& operator&=(copy_options& __lhs, copy_options __rhs) {
   return __lhs = __lhs & __rhs;
 }
 
-[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline copy_options& operator|=(copy_options& __lhs, copy_options __rhs) {
+_LIBCPP_HIDE_FROM_ABI inline copy_options& operator|=(copy_options& __lhs, copy_options __rhs) {
   return __lhs = __lhs | __rhs;
 }
 
-[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline copy_options& operator^=(copy_options& __lhs, copy_options __rhs) {
+_LIBCPP_HIDE_FROM_ABI inline copy_options& operator^=(copy_options& __lhs, copy_options __rhs) {
   return __lhs = __lhs ^ __rhs;
 }
 

diff  --git a/libcxx/include/__mdspan/mdspan.h b/libcxx/include/__mdspan/mdspan.h
index 9f3139a874ff9..9d3d35cd558a1 100644
--- a/libcxx/include/__mdspan/mdspan.h
+++ b/libcxx/include/__mdspan/mdspan.h
@@ -214,7 +214,7 @@ class mdspan {
     }(make_index_sequence<rank()>()));
   }
 
-  _LIBCPP_HIDE_FROM_ABI constexpr size_type size() const noexcept {
+  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr size_type size() const noexcept {
     // Could leave this as only checked in debug mode: semantically size() is never
     // guaranteed to be related to any accessible range
     _LIBCPP_ASSERT_UNCATEGORIZED(

diff  --git a/libcxx/test/libcxx/containers/views/mdspan/mdspan/assert.size.pass.cpp b/libcxx/test/libcxx/containers/views/mdspan/mdspan/assert.size.pass.cpp
index 9af82701cd4be..739da8ece81d7 100644
--- a/libcxx/test/libcxx/containers/views/mdspan/mdspan/assert.size.pass.cpp
+++ b/libcxx/test/libcxx/containers/views/mdspan/mdspan/assert.size.pass.cpp
@@ -43,7 +43,7 @@ int main(int, char**) {
     assert(map.required_span_size() == static_cast<signed char>(12));
     // 100 x 3 exceeds 256
     {
-      TEST_LIBCPP_ASSERT_FAILURE(([=] { mds.size(); }()), "mdspan: size() is not representable as size_type");
+      TEST_LIBCPP_ASSERT_FAILURE(([=] { (void)mds.size(); }()), "mdspan: size() is not representable as size_type");
     }
   }
   return 0;

diff  --git a/libcxx/test/libcxx/containers/views/mdspan/nodiscard.verify.cpp b/libcxx/test/libcxx/containers/views/mdspan/nodiscard.verify.cpp
index 71f53f8f1f737..d248656ec0ae5 100644
--- a/libcxx/test/libcxx/containers/views/mdspan/nodiscard.verify.cpp
+++ b/libcxx/test/libcxx/containers/views/mdspan/nodiscard.verify.cpp
@@ -33,6 +33,8 @@ void test() {
   mdsp.static_extent(0); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
   mdsp.extent(0);        // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
 
+  mdsp.size(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
+
   mdsp.extents();     // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
   mdsp.data_handle(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
   mdsp.mapping();     // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}

diff  --git a/libcxx/test/libcxx/diagnostics/algorithm.nodiscard.verify.cpp b/libcxx/test/libcxx/diagnostics/algorithm.nodiscard.verify.cpp
index 14febc12a8a2d..d4743f4c404c9 100644
--- a/libcxx/test/libcxx/diagnostics/algorithm.nodiscard.verify.cpp
+++ b/libcxx/test/libcxx/diagnostics/algorithm.nodiscard.verify.cpp
@@ -6,8 +6,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-// UNSUPPORTED: c++03
-
 // check that <algorithm> functions are marked [[nodiscard]]
 
 // clang-format off
@@ -188,11 +186,13 @@ void test() {
   // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
   std::max(1, 2, std::greater<int>());
 
+#if TEST_STD_VER >= 11
   // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
   std::max({1, 2, 3});
 
   // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
   std::max({1, 2, 3}, std::greater<int>());
+#endif
 
   // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
   std::min_element(std::begin(arr), std::end(arr));
@@ -206,11 +206,13 @@ void test() {
   // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
   std::min(1, 2, std::greater<int>());
 
+#if TEST_STD_VER >= 11
   // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
   std::min({1, 2, 3});
 
   // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
   std::min({1, 2, 3}, std::greater<int>());
+#endif
 
   // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
   std::minmax_element(std::begin(arr), std::end(arr));
@@ -224,11 +226,13 @@ void test() {
   // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
   std::minmax(1, 2, std::greater<int>());
 
+#if TEST_STD_VER >= 11
   // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
   std::minmax({1, 2, 3});
 
   // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
   std::minmax({1, 2, 3}, std::greater<int>());
+#endif
 
   // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
   std::mismatch(std::begin(arr), std::end(arr), std::begin(arr));

diff  --git a/libcxx/test/libcxx/diagnostics/array.nodiscard.verify.cpp b/libcxx/test/libcxx/diagnostics/array.nodiscard.verify.cpp
index 8e49807732de7..e51109dcc4e5d 100644
--- a/libcxx/test/libcxx/diagnostics/array.nodiscard.verify.cpp
+++ b/libcxx/test/libcxx/diagnostics/array.nodiscard.verify.cpp
@@ -6,8 +6,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-// UNSUPPORTED: c++03
-
 // check that <array> functions are marked [[nodiscard]]
 
 #include <array>
@@ -18,7 +16,7 @@
 template <std::size_t N>
 void test_members() {
   std::array<int, N> a;
-  const std::array<int, N> ca{};
+  const std::array<int, N> ca = {};
 
   a.begin();    // expected-warning 2 {{ignoring return value of function declared with 'nodiscard' attribute}}
   ca.begin();   // expected-warning 2 {{ignoring return value of function declared with 'nodiscard' attribute}}
@@ -57,7 +55,7 @@ void test_members() {
 
 template <typename ArrT>
 void test_get() {
-  std::array<int, 94> a{};
+  std::array<int, 94> a = {};
 
   // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
   std::get<0>(a);

diff  --git a/libcxx/test/libcxx/diagnostics/cstdlib.nodiscard.verify.cpp b/libcxx/test/libcxx/diagnostics/cstdlib.nodiscard.verify.cpp
index d3c809f22816b..52e897662fef6 100644
--- a/libcxx/test/libcxx/diagnostics/cstdlib.nodiscard.verify.cpp
+++ b/libcxx/test/libcxx/diagnostics/cstdlib.nodiscard.verify.cpp
@@ -6,8 +6,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-// UNSUPPORTED: c++03
-
 // We don't control the implementation of the stdlib.h functions on windows
 // UNSUPPORTED: windows
 

diff  --git a/libcxx/test/libcxx/diagnostics/deque.nodiscard.verify.cpp b/libcxx/test/libcxx/diagnostics/deque.nodiscard.verify.cpp
index a9adb1757b8ef..c10a99afee8fa 100644
--- a/libcxx/test/libcxx/diagnostics/deque.nodiscard.verify.cpp
+++ b/libcxx/test/libcxx/diagnostics/deque.nodiscard.verify.cpp
@@ -6,8 +6,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-// UNSUPPORTED: c++03
-
 // check that <deque> functions are marked [[nodiscard]]
 
 #include <deque>

diff  --git a/libcxx/test/libcxx/diagnostics/forward_list.nodiscard.verify.cpp b/libcxx/test/libcxx/diagnostics/forward_list.nodiscard.verify.cpp
index 671c7f71ab2a2..596dc52cdd7aa 100644
--- a/libcxx/test/libcxx/diagnostics/forward_list.nodiscard.verify.cpp
+++ b/libcxx/test/libcxx/diagnostics/forward_list.nodiscard.verify.cpp
@@ -6,8 +6,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-// UNSUPPORTED: c++03
-
 // check that <forward_list> functions are marked [[nodiscard]]
 
 #include <forward_list>

diff  --git a/libcxx/test/libcxx/diagnostics/functional.nodiscard.verify.cpp b/libcxx/test/libcxx/diagnostics/functional.nodiscard.verify.cpp
index 521870f2484a2..a8337c5e36c72 100644
--- a/libcxx/test/libcxx/diagnostics/functional.nodiscard.verify.cpp
+++ b/libcxx/test/libcxx/diagnostics/functional.nodiscard.verify.cpp
@@ -6,8 +6,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-// UNSUPPORTED: c++03
-
 // check that <functional> functions are marked [[nodiscard]]
 
 #include <cstddef>
@@ -20,7 +18,7 @@ void test() {
 
   // Function wrappers
 
-#if !defined(TEST_HAS_NO_RTTI)
+#if TEST_STD_VER >= 11 && !defined(TEST_HAS_NO_RTTI)
   std::function<void(int)> f;
   const std::function<void(int)> cf;
 
@@ -48,14 +46,16 @@ void test() {
   // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
   std::bind_front([](int a) { return a; }, 94);
 #endif
+#if TEST_STD_VER >= 11
   // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
   std::bind([](int a) { return a; }, 94);
   // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
   std::bind<float>([](int a) { return a; }, 94);
+#endif
 
   // Reference wrappers
 
-  std::reference_wrapper<int> rw{i};
+  std::reference_wrapper<int> rw = i;
   rw.get(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
 
   std::ref(i);  // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}

diff  --git a/libcxx/test/libcxx/diagnostics/limits.nodiscard.verify.cpp b/libcxx/test/libcxx/diagnostics/limits.nodiscard.verify.cpp
index 7a81b84378c52..d3bea9ea031f4 100644
--- a/libcxx/test/libcxx/diagnostics/limits.nodiscard.verify.cpp
+++ b/libcxx/test/libcxx/diagnostics/limits.nodiscard.verify.cpp
@@ -6,8 +6,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-// UNSUPPORTED: c++03
-
 // check that <limits> functions are marked [[nodiscard]]
 
 #include <limits>

diff  --git a/libcxx/test/libcxx/diagnostics/list.nodiscard.verify.cpp b/libcxx/test/libcxx/diagnostics/list.nodiscard.verify.cpp
index bfce9b85ef76c..cff607e738d35 100644
--- a/libcxx/test/libcxx/diagnostics/list.nodiscard.verify.cpp
+++ b/libcxx/test/libcxx/diagnostics/list.nodiscard.verify.cpp
@@ -6,8 +6,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-// UNSUPPORTED: c++03
-
 // check that <list> functions are marked [[nodiscard]]
 
 #include <list>

diff  --git a/libcxx/test/libcxx/diagnostics/mutex.nodiscard.verify.cpp b/libcxx/test/libcxx/diagnostics/mutex.nodiscard.verify.cpp
index b9890ced55bb1..c82a7edadcd06 100644
--- a/libcxx/test/libcxx/diagnostics/mutex.nodiscard.verify.cpp
+++ b/libcxx/test/libcxx/diagnostics/mutex.nodiscard.verify.cpp
@@ -6,8 +6,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-// UNSUPPORTED: c++03
-
 // UNSUPPORTED: no-threads
 
 // check that <mutex> functions are marked [[nodiscard]]
@@ -47,14 +45,14 @@ void test() {
     std::unique_lock<M> other;
 
     // clang-format off
-    std::unique_lock<M>{};                      // expected-warning {{ignoring temporary created by a constructor declared with 'nodiscard' attribute}}
-    std::unique_lock<M>{m};                     // expected-warning {{ignoring temporary created by a constructor declared with 'nodiscard' attribute}}
-    std::unique_lock<M>{m, std::defer_lock};    // expected-warning {{ignoring temporary created by a constructor declared with 'nodiscard' attribute}}
-    std::unique_lock<M>{m, std::try_to_lock};   // expected-warning {{ignoring temporary created by a constructor declared with 'nodiscard' attribute}}
-    std::unique_lock<M>{m, std::adopt_lock};    // expected-warning {{ignoring temporary created by a constructor declared with 'nodiscard' attribute}}
-    std::unique_lock<M>{m, time_point};         // expected-warning {{ignoring temporary created by a constructor declared with 'nodiscard' attribute}}
-    std::unique_lock<M>{m, duration};           // expected-warning {{ignoring temporary created by a constructor declared with 'nodiscard' attribute}}
-    std::unique_lock<M>(std::move(other));      // expected-warning {{ignoring temporary created by a constructor declared with 'nodiscard' attribute}}
+    std::unique_lock<M>();                        // expected-warning {{ignoring temporary created by a constructor declared with 'nodiscard' attribute}}
+    (std::unique_lock<M>)(m);                     // expected-warning {{ignoring temporary created by a constructor declared with 'nodiscard' attribute}}
+    std::unique_lock<M>(m, std::defer_lock_t());  // expected-warning {{ignoring temporary created by a constructor declared with 'nodiscard' attribute}}
+    std::unique_lock<M>(m, std::try_to_lock_t()); // expected-warning {{ignoring temporary created by a constructor declared with 'nodiscard' attribute}}
+    std::unique_lock<M>(m, std::adopt_lock_t());  // expected-warning {{ignoring temporary created by a constructor declared with 'nodiscard' attribute}}
+    std::unique_lock<M>(m, time_point);           // expected-warning {{ignoring temporary created by a constructor declared with 'nodiscard' attribute}}
+    std::unique_lock<M>(m, duration);             // expected-warning {{ignoring temporary created by a constructor declared with 'nodiscard' attribute}}
+    std::unique_lock<M>(std::move(other));        // expected-warning {{ignoring temporary created by a constructor declared with 'nodiscard' attribute}}
     // clang-format on
   }
 
@@ -62,8 +60,8 @@ void test() {
   {
     std::mutex m;
     // clang-format off
-    std::lock_guard<std::mutex>{m};                  // expected-warning {{ignoring temporary created by a constructor declared with 'nodiscard' attribute}}
-    std::lock_guard<std::mutex>{m, std::adopt_lock}; // expected-warning {{ignoring temporary created by a constructor declared with 'nodiscard' attribute}}
+    (std::lock_guard<std::mutex>)(m);                    // expected-warning {{ignoring temporary created by a constructor declared with 'nodiscard' attribute}}
+    std::lock_guard<std::mutex>(m, std::adopt_lock_t()); // expected-warning {{ignoring temporary created by a constructor declared with 'nodiscard' attribute}}
     // clang-format on
   }
 }

diff  --git a/libcxx/test/libcxx/diagnostics/new.nodiscard.verify.cpp b/libcxx/test/libcxx/diagnostics/new.nodiscard.verify.cpp
index 505618c0b88d7..b2af8d4a74027 100644
--- a/libcxx/test/libcxx/diagnostics/new.nodiscard.verify.cpp
+++ b/libcxx/test/libcxx/diagnostics/new.nodiscard.verify.cpp
@@ -6,8 +6,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-// UNSUPPORTED: c++03
-
 // check that <array> functions are marked [[nodiscard]]
 
 // clang-format off

diff  --git a/libcxx/test/libcxx/diagnostics/queue.nodiscard.verify.cpp b/libcxx/test/libcxx/diagnostics/queue.nodiscard.verify.cpp
index da1f9ff3f01f6..d23934cc15053 100644
--- a/libcxx/test/libcxx/diagnostics/queue.nodiscard.verify.cpp
+++ b/libcxx/test/libcxx/diagnostics/queue.nodiscard.verify.cpp
@@ -6,8 +6,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-// UNSUPPORTED: c++03
-
 // check that <queue> functions are marked [[nodiscard]]
 
 #include <queue>
@@ -15,7 +13,7 @@
 void test() {
   {
     std::queue<int> q;
-    const std::queue<int> cq{};
+    const std::queue<int> cq;
 
     q.empty();  // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
     q.size();   // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}

diff  --git a/libcxx/test/libcxx/diagnostics/stack.nodiscard.verify.cpp b/libcxx/test/libcxx/diagnostics/stack.nodiscard.verify.cpp
index a0a5b3c898a8c..d176fd4cf6f68 100644
--- a/libcxx/test/libcxx/diagnostics/stack.nodiscard.verify.cpp
+++ b/libcxx/test/libcxx/diagnostics/stack.nodiscard.verify.cpp
@@ -6,8 +6,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-// UNSUPPORTED: c++03
-
 // check that <stack> functions are marked [[nodiscard]]
 
 #include <stack>

diff  --git a/libcxx/test/libcxx/diagnostics/string.nodiscard.verify.cpp b/libcxx/test/libcxx/diagnostics/string.nodiscard.verify.cpp
index 0ff92cac3a3b2..3a941598e6e68 100644
--- a/libcxx/test/libcxx/diagnostics/string.nodiscard.verify.cpp
+++ b/libcxx/test/libcxx/diagnostics/string.nodiscard.verify.cpp
@@ -6,8 +6,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-// UNSUPPORTED: c++03
-
 // check that <string> functions are marked [[nodiscard]]
 
 #include <string>

diff  --git a/libcxx/test/libcxx/diagnostics/string_view.nodiscard.verify.cpp b/libcxx/test/libcxx/diagnostics/string_view.nodiscard.verify.cpp
index 89e4a5b44ab48..7c282f205e310 100644
--- a/libcxx/test/libcxx/diagnostics/string_view.nodiscard.verify.cpp
+++ b/libcxx/test/libcxx/diagnostics/string_view.nodiscard.verify.cpp
@@ -6,8 +6,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-// UNSUPPORTED: c++03
-
 // check that <string_view> functions are marked [[nodiscard]]
 
 #include <string_view>
@@ -126,7 +124,7 @@ void test_nonmembers() {
 
   std::hash<std::string_view> hash;
   // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
-  hash(std::string_view{});
+  hash(std::string_view());
 
 #if TEST_STD_VER >= 14
   // string_view literals

diff  --git a/libcxx/test/libcxx/diagnostics/utility.nodiscard.verify.cpp b/libcxx/test/libcxx/diagnostics/utility.nodiscard.verify.cpp
index 2f5b3ba0fc642..3d6ff423dc917 100644
--- a/libcxx/test/libcxx/diagnostics/utility.nodiscard.verify.cpp
+++ b/libcxx/test/libcxx/diagnostics/utility.nodiscard.verify.cpp
@@ -6,8 +6,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-// UNSUPPORTED: c++03
-
 // check that <utility> functions are marked [[nodiscard]]
 
 #include <utility>

diff  --git a/libcxx/test/libcxx/diagnostics/vector.nodiscard.verify.cpp b/libcxx/test/libcxx/diagnostics/vector.nodiscard.verify.cpp
index a5cad1a1627e6..161a3c7601328 100644
--- a/libcxx/test/libcxx/diagnostics/vector.nodiscard.verify.cpp
+++ b/libcxx/test/libcxx/diagnostics/vector.nodiscard.verify.cpp
@@ -6,8 +6,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-// UNSUPPORTED: c++03
-
 // check that <vector> functions are marked [[nodiscard]]
 
 #include <type_traits>
@@ -44,11 +42,11 @@ void test_non_vector_bool() {
 }
 
 void instantiate() {
-  test<std::vector<int>>();
-  test<const std::vector<int>>();
-  test<std::vector<bool>>();
-  test<const std::vector<bool>>();
+  test<std::vector<int> >();
+  test<const std::vector<int> >();
+  test<std::vector<bool> >();
+  test<const std::vector<bool> >();
 
-  test_non_vector_bool<std::vector<int>>();
-  test_non_vector_bool<const std::vector<int>>();
+  test_non_vector_bool<std::vector<int> >();
+  test_non_vector_bool<const std::vector<int> >();
 }

diff  --git a/libcxx/test/libcxx/thread/nodiscard.verify.cpp b/libcxx/test/libcxx/thread/nodiscard.verify.cpp
index 19e43f88db700..73e4f932b6369 100644
--- a/libcxx/test/libcxx/thread/nodiscard.verify.cpp
+++ b/libcxx/test/libcxx/thread/nodiscard.verify.cpp
@@ -6,7 +6,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-// UNSUPPORTED: c++03
 // UNSUPPORTED: no-threads
 
 // Check that functions are marked [[nodiscard]]
@@ -65,7 +64,7 @@ void test() {
     // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
     m.try_lock();
     // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
-    m.try_lock_for(std::chrono::nanoseconds{82});
+    m.try_lock_for(std::chrono::nanoseconds(82));
     // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
     m.try_lock_until(timePoint);
   }
@@ -75,7 +74,7 @@ void test() {
     // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
     m.try_lock();
     // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
-    m.try_lock_for(std::chrono::nanoseconds{82});
+    m.try_lock_for(std::chrono::nanoseconds(82));
     // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
     m.try_lock_until(timePoint);
   }
@@ -86,8 +85,10 @@ void test() {
 
     // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
     std::try_lock(m1, m2);
+#if TEST_STD_VER >= 11
     // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
     std::try_lock(m1, m2, m3);
+#endif
   }
 
   // Condition variables

diff  --git a/libcxx/test/libcxx/utilities/smartptr/nodiscard.verify.cpp b/libcxx/test/libcxx/utilities/smartptr/nodiscard.verify.cpp
index 6e713fe5217ba..6943a4002c245 100644
--- a/libcxx/test/libcxx/utilities/smartptr/nodiscard.verify.cpp
+++ b/libcxx/test/libcxx/utilities/smartptr/nodiscard.verify.cpp
@@ -6,8 +6,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-// UNSUPPORTED: c++03
-
 // ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_ENABLE_CXX20_REMOVED_SHARED_PTR_UNIQUE -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS
 
 // <memory>
@@ -42,7 +40,7 @@ void test() {
     std::make_unique_for_overwrite<int[]>(5);
 #endif
 
-    std::hash<std::unique_ptr<int>> hash;
+    std::hash<std::unique_ptr<int> > hash;
     hash(uPtr); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
   }
   { // [util.smartptr.weak.bad]
@@ -127,7 +125,7 @@ void test() {
     std::get_deleter<int[]>(sPtr);
 #endif
 
-    std::hash<std::shared_ptr<int[]>> hash;
+    std::hash<std::shared_ptr<int[]> > hash;
     hash(sPtr); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
   }
   { // [util.smartptr.weak]

diff  --git a/libcxx/test/std/input.output/filesystems/fs.enum/enum.copy_options.pass.cpp b/libcxx/test/std/input.output/filesystems/fs.enum/enum.copy_options.pass.cpp
index 4ef28ee01d8d0..d7bc17a6703ec 100644
--- a/libcxx/test/std/input.output/filesystems/fs.enum/enum.copy_options.pass.cpp
+++ b/libcxx/test/std/input.output/filesystems/fs.enum/enum.copy_options.pass.cpp
@@ -22,6 +22,71 @@ namespace fs = std::filesystem;
 
 constexpr fs::copy_options ME(int val) { return static_cast<fs::copy_options>(val); }
 
+// Verify binary operations on std::filesystem::copy_options bitmask constants.
+// Also verify that compound assignment operators are not incorrectly marked [[nodiscard]],
+// to avoid regression in https://llvm.org/PR171085.
+constexpr bool test_bitmask_binary_operations() {
+  using E = fs::copy_options;
+  constexpr E bitmask_elems[]{
+      // non-empty standard bitmask elements
+      E::skip_existing,
+      E::overwrite_existing,
+      E::update_existing,
+      E::recursive,
+      E::copy_symlinks,
+      E::skip_symlinks,
+      E::directories_only,
+      E::create_symlinks,
+      E::create_hard_links,
+  };
+
+  for (auto elem : bitmask_elems) {
+    assert((E::none | elem) == elem);
+    assert((E::none & elem) == E::none);
+    assert((E::none ^ elem) == elem);
+
+    assert((elem | elem) == elem);
+    assert((elem & elem) == elem);
+    assert((elem ^ elem) == E::none);
+
+    if (!TEST_IS_CONSTANT_EVALUATED) {
+      {
+        auto e = E::none;
+        assert(&(e |= elem) == &e);
+        assert(e == elem);
+      }
+      {
+        auto e = E::none;
+        assert(&(e &= elem) == &e);
+        assert(e == E::none);
+      }
+      {
+        auto e = E::none;
+        assert(&(e ^= elem) == &e);
+        assert(e == elem);
+      }
+
+      {
+        auto e = elem;
+        assert(&(e |= elem) == &e);
+        assert(e == elem);
+      }
+      {
+        auto e = elem;
+        assert(&(e &= elem) == &e);
+        assert(e == elem);
+      }
+      {
+        auto e = elem;
+        assert(&(e ^= elem) == &e);
+        assert(e == E::none);
+      }
+    }
+  }
+
+  return true;
+}
+
 int main(int, char**) {
   typedef fs::copy_options E;
   static_assert(std::is_enum<E>::value, "");
@@ -61,5 +126,8 @@ int main(int, char**) {
           E::create_hard_links   == ME(256),
         "Expected enumeration values do not match");
 
+  test_bitmask_binary_operations();
+  static_assert(test_bitmask_binary_operations());
+
   return 0;
 }


        


More information about the libcxx-commits mailing list