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

2011-06-21 Thread redi at gcc dot gnu.org
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


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

2009-12-23 Thread redi at gcc dot gnu dot org


--- Comment #1 from redi at gcc dot gnu dot org  2009-12-23 23:47 ---
When GCC supports C++ attributes you could get the diagnostics you want like
this:

class A_noconst [[base_check]] : public A {
...
};

class A_const [[base_check]] : public A {
...
};

c.f. http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2009/n2928.htm

As I said in bug 31397 c12 it would be better to implement those attributes
than to add warning switches


-- 

redi at gcc dot gnu dot org changed:

   What|Removed |Added

   Severity|normal  |enhancement


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36848