[binutils-gdb] [gdb/testsuite] Fix ambiguous operator warning
Tom de Vries via Gdb-cvs <[email protected]> Sat, 30 May 2026 12:46:26 +0000 (GMT)
| Newsgroups | gmane.comp.gdb.cvs |
|---|---|
| Message-ID | <[email protected]> |
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=d45673f4502e84036afb9713e0b9a51c56576b82 commit d45673f4502e84036afb9713e0b9a51c56576b82 Author: Tom de Vries <[email protected]> Date: Sat May 30 14:46:22 2026 +0200 [gdb/testsuite] Fix ambiguous operator warning 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 <[email protected]> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=34187 Diff: --- gdb/testsuite/gdb.cp/cmpd-minsyms.cc | 2 +- gdb/testsuite/gdb.cp/cmpd-minsyms.exp | 2 +- gdb/testsuite/gdb.cp/many-args.cc | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/gdb/testsuite/gdb.cp/cmpd-minsyms.cc b/gdb/testsuite/gdb.cp/cmpd-minsyms.cc index 504dfec0f9c..afef5d7dcd4 100644 --- a/gdb/testsuite/gdb.cp/cmpd-minsyms.cc +++ b/gdb/testsuite/gdb.cp/cmpd-minsyms.cc @@ -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 { } diff --git a/gdb/testsuite/gdb.cp/cmpd-minsyms.exp b/gdb/testsuite/gdb.cp/cmpd-minsyms.exp index 19653a4ccc9..ccd7f5d692a 100644 --- a/gdb/testsuite/gdb.cp/cmpd-minsyms.exp +++ b/gdb/testsuite/gdb.cp/cmpd-minsyms.exp @@ -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)"} \ diff --git a/gdb/testsuite/gdb.cp/many-args.cc b/gdb/testsuite/gdb.cp/many-args.cc index b5685b13c47..8c8805297f7 100644 --- a/gdb/testsuite/gdb.cp/many-args.cc +++ b/gdb/testsuite/gdb.cp/many-args.cc @@ -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