public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "romain.geissler at amadeus dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/109918] New: Unexpected -Woverloaded-virtual with virtual conversion operators
Date: Sat, 20 May 2023 18:28:04 +0000	[thread overview]
Message-ID: <bug-109918-4@http.gcc.gnu.org/bugzilla/> (raw)

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109918

            Bug ID: 109918
           Summary: Unexpected -Woverloaded-virtual with virtual
                    conversion operators
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: romain.geissler at amadeus dot com
  Target Milestone: ---

Hi,

Now that the -Woverloaded-virtual=1 is enabled by default with -Wall, the
following code raises warning while I think it should not (for the specific
case of conversion operators):

#include <iostream>

struct A
{
    virtual operator int() { return 42; }

    virtual operator char() = 0;
};

struct B : public A
{
    operator char() override { return 'A'; }
};

int main()
{
    B b;

    std::cout << static_cast<int>(b) << std::endl; // int conversion was not
hiden, contrary to what -Woverloaded-virtual claims
    std::cout << static_cast<char>(b) << std::endl;
}


Godbolt link: https://godbolt.org/z/4Wb9rxbMP

Compiled with -Wall, it raises this warning:

<source>:5:13: warning: 'virtual A::operator int()' was hidden
[-Woverloaded-virtual=]
    5 |     virtual operator int() { return 42; }
      |             ^~~~~~~~
<built-in>: note:   by 'operator'
ASM generation compiler returned: 0
<source>:5:13: warning: 'virtual A::operator int()' was hidden
[-Woverloaded-virtual=]
    5 |     virtual operator int() { return 42; }
      |             ^~~~~~~~
<built-in>: note:   by 'operator'
Execution build compiler returned: 0
Program returned: 0
42
A


I have hit this issue in a real code base, while migrating to gcc 13.

Cheers,
Romain

             reply	other threads:[~2023-05-20 18:28 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-20 18:28 romain.geissler at amadeus dot com [this message]
2023-05-20 18:41 ` [Bug c++/109918] [10/11/12/13/14 Regression] " pinskia at gcc dot gnu.org
2023-07-07 10:45 ` [Bug c++/109918] [11/12/13/14 " rguenth at gcc dot gnu.org
2024-01-10 17:17 ` jamborm at gcc dot gnu.org
2024-03-08 15:36 ` law at gcc dot gnu.org

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=bug-109918-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).