[Bug c++/109740] -Woverloaded-virtual is too aggressive
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109740 --- Comment #5 from Alexander Goomenuk --- Created attachment 56495 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=56495=edit Overloaded virtual testcase Another relevant issue with gcc (GCC) 13.2.1 20231011 (Red Hat 13.2.1-4) and -Woverloaded-virtual. Overloading method f() in Derived class affects the warning that is caused by assignment operator! Woverloaded-virtual-test.cpp:6:28: warning: ‘virtual const Parent& Parent::operator=(int&)’ was hidden [-Woverloaded-virtual=] 6 | virtual const Parent & operator=(int ) |^~~~ Woverloaded-virtual-test.cpp:15:8: note: by ‘constexpr Derived& Derived::operator=(const Derived&)’ 15 | struct Derived : public Parent |^~~
[Bug c++/109740] -Woverloaded-virtual is too aggressive
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109740 --- Comment #4 from Alexander Goomenuk --- https://en.cppreference.com/w/cpp/language/using_declaration # In class definition ... If the derived class already has a member with the same name, parameter list, and qualifications, *the derived class member hides or overrides (doesn't conflict with) the member that is introduced from the base class*. https://gcc.gnu.org/onlinedocs/gcc-13.1.0/gcc/C_002b_002b-Dialect-Options.html#index-Woverloaded-virtual In cases where the different signatures are not an accident, the simplest solution is to add a *using-declaration to the derived class to un-hide the base function*, e.g. add using A::f; to B. These two statements contradict each other, isn't it?
[Bug c++/109740] -Woverloaded-virtual is too aggressive
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109740 Alexander Goomenuk changed: What|Removed |Added CC||emerg.reanimator at gmail dot com --- Comment #3 from Alexander Goomenuk --- Let consider the following case: - There is a base class that implement virtual assignment operator with arbitrary input argument (not copy operator). - There is a derived class that inherits the assignment operator from base class. g++ version >= 13 produces the warning in this case because implicitly-defined copy operator of derived class pretends to hide the user defined assignment operator of base class. The code is totally fine and the assignment operator works as expected. Even worse, the warning is produced by compiler even if no implicitly-defined copy operator is NOT generated by the compiler and the code fails to build due to the lack of copy operator. So the warning is misleading and incorrect in this case. See https://stackoverflow.com/questions/77378553/woverloaded-virtual-with-default-shallow-copy-operator for more details.
[Bug c++/109740] -Woverloaded-virtual is too aggressive
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109740 --- Comment #2 from Paul Smith --- What I'm trying to say is that it's not useful (to me) for GCC to warn about code that I could maybe write in the future but didn't actually write, and which if I did write it would generate a compiler error anyway, rather than "doing the wrong thing". On the other hand, it's very useful for GCC to warn me about situations where I could be actually getting an unexpected result, without a compiler error. For example if the parent method takes an int and the child method takes a char, then I might call B.foo(10) expecting to get the parent method but actually the child method will be invoked. That kind of warning is very helpful. So, it would be nice to have a way to warn about things that might miscompile silently in unexpected ways, without also warning about things that can't possibly miscompile in unexpected ways. I did read the description in the docs, and the suggestion of adding using A::foo to the child class, but that inherits all the parent class's virtual methods into the child class which I don't want to do in all cases.
[Bug c++/109740] -Woverloaded-virtual is too aggressive
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109740 --- Comment #1 from Andrew Pinski --- The warning is specifically designed this way and even is documented to warn. https://gcc.gnu.org/onlinedocs/gcc-13.1.0/gcc/C_002b_002b-Dialect-Options.html#index-Woverloaded-virtual It is designed this way so you don't accidently have the wrong arguments (types and/or count). The documentation even talks about that: "In cases where the different signatures are not an accident,"