]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
[gdb/testsuite] Fix ambiguous operator warning
authorTom de Vries <tdevries@suse.de>
Sat, 30 May 2026 12:46:22 +0000 (14:46 +0200)
committerTom de Vries <tdevries@suse.de>
Sat, 30 May 2026 12:46:22 +0000 (14:46 +0200)
With gcc 16, defaulting to c++20, and test-case gdb.cp/cmpd-minsyms.exp I run
into:
...
cmpd-minsyms.cc: In function 'int main(int, char**)':^M
cmpd-minsyms.cc:39:13: warning: C++20 says that these are ambiguous, even \
  though the second is reversed:^M
   39 |    if (a == b)^M
      |             ^^M
cmpd-minsyms.cc:26:8: note: candidate 1: 'int GDB<T>::operator==(const GDB<T>&) [with T = int]'^M
   26 |    int operator == (GDB const& other)^M
      |        ^~~~~~~~^M
cmpd-minsyms.cc:26:8: note: candidate 2: 'int GDB<T>::operator==(const GDB<T>&) [with T = int]' (reversed)^M
cmpd-minsyms.cc:26:8: note: try making the operator a 'const' member function^M
...

Fix this by following the advice:
...
-   int operator == (GDB const& other)
+   int operator == (GDB const& other) const
    { return 1; }
...

Likewise in gdb.cp/many-args.exp.

Reviewed-By: Keith Seitz <keiths@redhat.com>
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=34187

gdb/testsuite/gdb.cp/cmpd-minsyms.cc
gdb/testsuite/gdb.cp/cmpd-minsyms.exp
gdb/testsuite/gdb.cp/many-args.cc

index 504dfec0f9c7c973ce4c21220544f1c3dd2c3457..afef5d7dcd46f6991039215ce3033a9f105b1695 100644 (file)
@@ -23,7 +23,7 @@ class GDB
    static int harder (T a) { return 1; }
    template <typename X>
    static X even_harder (T a) { return static_cast<X> (a); }
-   int operator == (GDB const& other)
+   int operator == (GDB const& other) const
    { return 1; }
   void a (void) const { }
   void b (void) volatile { }
index 19653a4ccc9ee37d5bb3088dd3f55604a5beea27..ccd7f5d692a9895e1ec503467cd0f53bd19a8f53 100644 (file)
@@ -48,7 +48,7 @@ gdb_test_no_output "set language c++"
 # of the minimal symbol.
 set min_syms [list \
                  "GDB<int>::operator ==" \
-                 "GDB<int>::operator==(GDB<int> const&)" \
+                 "GDB<int>::operator==(GDB<int> const&) const" \
                  "GDB<char>::harder(char)" \
                  "GDB<int>::harder(int)" \
                  {"int GDB<char>::even_harder<int>(char)"} \
index b5685b13c47a04236ade7e0bfe847a9cc75cdb08..8c8805297f7b6f78cda0d915613c5934dc0fc39d 100644 (file)
@@ -26,7 +26,7 @@ struct ss
 
   unsigned char aa;
 
-  bool operator== (const ss &rhs)
+  bool operator== (const ss &rhs) const
   {
     return (memcmp (&this->static_field, &rhs.static_field,
                    sizeof (this->static_field)) == 0