public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/109918] New: Unexpected -Woverloaded-virtual with virtual conversion operators
@ 2023-05-20 18:28 romain.geissler at amadeus dot com
  2023-05-20 18:41 ` [Bug c++/109918] [10/11/12/13/14 Regression] " pinskia at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: romain.geissler at amadeus dot com @ 2023-05-20 18:28 UTC (permalink / raw)
  To: gcc-bugs

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-03-08 15:36 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-20 18:28 [Bug c++/109918] New: Unexpected -Woverloaded-virtual with virtual conversion operators romain.geissler at amadeus dot com
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

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).