This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/36848] const/nonconst virtual function ambiguity deserves a warning


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]