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

A. Jiang via libcxx-commits libcxx-commits at lists.llvm.org
Fri Dec 19 01:51:00 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) {
----------------
frederick-vs-ja wrote:

I found it very weird that these compound assignment operators are not `constexpr`. Opened #172979 for this. I think we should handle lack of `constexpr` in some future PR(s).

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


More information about the libcxx-commits mailing list