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

Nikolas Klauser via libcxx-commits libcxx-commits at lists.llvm.org
Fri Dec 19 07:37:24 PST 2025


================
@@ -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;
+        e |= elem;
----------------
philnik777 wrote:

Could you also assert the returned address (i.e. `assert(&(e |= elem) == &e)`)?

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


More information about the libcxx-commits mailing list