This produces a warning in C++20:

/home/test/src/gcc/gcc/analyzer/constraint-manager.cc: In member function ‘bool 
ana::constraint_manager::operator==(const ana::constraint_manager&) const’:
/home/test/src/gcc/gcc/analyzer/constraint-manager.cc:1610:42: warning: C++20 
says that these are ambiguous, even though the second is reversed:
 1610 |     if (!(*ec == *other.m_equiv_classes[i]))
      |                                          ^
/home/test/src/gcc/gcc/analyzer/constraint-manager.cc:1178:1: note: candidate 
1: ‘bool ana::equiv_class::operator==(const ana::equiv_class&)’
 1178 | equiv_class::operator== (const equiv_class &other)
      | ^~~~~~~~~~~
/home/test/src/gcc/gcc/analyzer/constraint-manager.cc:1178:1: note: candidate 
2: ‘bool ana::equiv_class::operator==(const ana::equiv_class&)’ (reversed)
/home/test/src/gcc/gcc/analyzer/constraint-manager.cc:1178:1: note: try making 
the operator a ‘const’ member function

gcc/analyzer/ChangeLog:

        * constraint-manager.cc (equiv_class::operator==): Add const
        qualifier.
        * constraint-manager.h (equiv_class::operator==): Likewise.
---

Bootstrapped on x86_64-linux. Pushed as obvious.

 gcc/analyzer/constraint-manager.cc | 2 +-
 gcc/analyzer/constraint-manager.h  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/analyzer/constraint-manager.cc 
b/gcc/analyzer/constraint-manager.cc
index 58c60feae369..c8cc71593cc0 100644
--- a/gcc/analyzer/constraint-manager.cc
+++ b/gcc/analyzer/constraint-manager.cc
@@ -1175,7 +1175,7 @@ equiv_class::hash () const
    meaningful.  */
 
 bool
-equiv_class::operator== (const equiv_class &other)
+equiv_class::operator== (const equiv_class &other) const
 {
   if (m_constant != other.m_constant)
     return false; // TODO: use tree equality here?
diff --git a/gcc/analyzer/constraint-manager.h 
b/gcc/analyzer/constraint-manager.h
index 4339ea665d84..38686b7e696b 100644
--- a/gcc/analyzer/constraint-manager.h
+++ b/gcc/analyzer/constraint-manager.h
@@ -258,7 +258,7 @@ public:
   equiv_class (const equiv_class &other);
 
   hashval_t hash () const;
-  bool operator== (const equiv_class &other);
+  bool operator== (const equiv_class &other) const;
 
   void add (const svalue *sval);
   bool del (const svalue *sval);
-- 
2.51.1

Reply via email to