]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
analyzer: Add missing 'const' to equiv_class::operator==
authorJonathan Wakely <jwakely@redhat.com>
Thu, 27 Nov 2025 16:13:44 +0000 (16:13 +0000)
committerJonathan Wakely <jwakely@redhat.com>
Thu, 27 Nov 2025 16:32:57 +0000 (16:32 +0000)
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.

gcc/analyzer/constraint-manager.cc
gcc/analyzer/constraint-manager.h

index 58c60feae36931d91b204a26e7420176202f0132..c8cc71593cc007e57f0a02be77807fa9c2bf8c6e 100644 (file)
@@ -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?
index 4339ea665d84f6082659e98c0e389305ea991eba..38686b7e696b57c49ae4c4b56c520f7818cd5c14 100644 (file)
@@ -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);