Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Subject: [PATCH 1/2] [gdb/testsuite] Fix ambiguous operator warning
Date: Fri, 29 May 2026 14:51:48 +0200	[thread overview]
Message-ID: <20260529125149.2027857-2-tdevries@suse.de> (raw)
In-Reply-To: <20260529125149.2027857-1-tdevries@suse.de>

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.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=34187
---
 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
-- 
2.51.0


  reply	other threads:[~2026-05-29 12:52 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-29 12:51 [PATCH 0/2] [gdb/testsuite] Handle gcc 16 Tom de Vries
2026-05-29 12:51 ` Tom de Vries [this message]
2026-05-29 16:23   ` [PATCH 1/2] [gdb/testsuite] Fix ambiguous operator warning Keith Seitz
2026-05-29 12:51 ` [PATCH 2/2] [gdb/testsuite] Use Wno-non-c-typedef-for-linkage for gcc 16 Tom de Vries
2026-05-29 16:25   ` Keith Seitz
2026-05-30  8:49     ` Tom de Vries

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260529125149.2027857-2-tdevries@suse.de \
    --to=tdevries@suse.de \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox