https://gcc.gnu.org/g:dfd17e05f9e983660b87e603c062918d2d173fc3

commit r16-5673-gdfd17e05f9e983660b87e603c062918d2d173fc3
Author: Jonathan Wakely <[email protected]>
Date:   Thu Nov 27 16:13:44 2025 +0000

    analyzer: Add missing 'const' to equiv_class::operator==
    
    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.

Diff:
---
 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);

Reply via email to