This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/36848] const/nonconst virtual function ambiguity deserves a warning
- From: "redi at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 21 Jun 2011 15:56:50 +0000
- Subject: [Bug c++/36848] const/nonconst virtual function ambiguity deserves a warning
- Auto-submitted: auto-generated
- References: <bug-36848-4@http.gcc.gnu.org/bugzilla/>
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36848
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |WORKSFORME
--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> 2011-06-21 15:56:26 UTC ---
You probably want the -Woverloaded-virtual warning, present for many years.
Additionally, G++ 4.7 implements C++0x explicit override control, so you can
change your derived classes like so:
class A_noconst : public A {
public:
void sayhi() override { /* ... */ }
void saybye() override { /* ... */ }
};
class A_const : public A {
public:
void sayhi() const override { /* ... */ }
void saybye() const override { /* ... */ }
};
This causes the compiler to reject the program:
final.cc:9:8: error: 'void A_noconst::sayhi()' marked override, but does not
override
final.cc:16:8: error: 'void A_const::saybye() const' marked override, but does
not override