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

via libc-commits libc-commits at lists.llvm.org
Thu Nov 30 08:22:17 PST 2023


Author: Samira Bazuzi
Date: 2023-11-30T17:22:10+01:00
New Revision: 3f505cd58776fca59f4f2eb456b169fa5da09317

URL: https://github.com/llvm/llvm-project/commit/3f505cd58776fca59f4f2eb456b169fa5da09317
DIFF: https://github.com/llvm/llvm-project/commit/3f505cd58776fca59f4f2eb456b169fa5da09317.diff

LOG: [libc] Mark operator== const to avoid ambiguity in C++20. (#73954)

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.

Added: 
    

Modified: 
    libc/src/__support/CPP/bitset.h

Removed: 
    


################################################################################
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;


        


More information about the libc-commits mailing list