[libc-commits] [libc] [libc] Mark operator== const to avoid ambiguity in C++20. (PR #73954)

via libc-commits libc-commits at lists.llvm.org
Thu Nov 30 07:57:40 PST 2023


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libc

Author: Samira Bazuzi (bazuzi)

<details>
<summary>Changes</summary>

C++20 will automatically generate an operator== with reversed operand order, which is ambiguous with the written operator== when one argument is marked const and the other isn't.

This operator currently triggers -Wambiguous-reversed-operator at several usage sites in libc/test/src/__support/CPP/bitset_test.cpp, starting with line 153.

---
Full diff: https://github.com/llvm/llvm-project/pull/73954.diff


1 Files Affected:

- (modified) libc/src/__support/CPP/bitset.h (+2-1) 


``````````diff
diff --git a/libc/src/__support/CPP/bitset.h b/libc/src/__support/CPP/bitset.h
index cfac749e0d84e3a..30a7fa796cb4b36 100644
--- a/libc/src/__support/CPP/bitset.h
+++ b/libc/src/__support/CPP/bitset.h
@@ -65,7 +65,8 @@ template <size_t NumberOfBits> struct bitset {
     }
   }
 
-  LIBC_INLINE constexpr bool operator==(const bitset<NumberOfBits> &other) {
+  LIBC_INLINE constexpr bool
+  operator==(const bitset<NumberOfBits> &other) const {
     for (size_t i = 0; i < NUMBER_OF_UNITS; ++i) {
       if (Data[i] != other.Data[i])
         return false;

``````````

</details>


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


More information about the libc-commits mailing list