Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

Warn if a method is virtual final but does not override anything. #21050

Open Quuxplusone opened 9 years ago

Quuxplusone commented 9 years ago
Bugzilla Link PR21051
Status NEW
Importance P normal
Reported by dcheng@google.com
Reported on 2014-09-24 00:03:56 -0700
Last modified on 2014-09-29 13:01:29 -0700
Version unspecified
Hardware PC All
CC dgregor@apple.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk, zinovy.nis@gmail.com
Fixed by commit(s)
Attachments
Blocks
Blocked by
See also
$ cat test.cc
class Base {
  virtual void F() final;
};
$ clang++ -fsyntax-only -std=c++11 test.cc

It might make sense to warn about this, since there's no point in having a
virtual that can never be overridden.
Quuxplusone commented 9 years ago

I'm not convinced that this pattern is pointless; it might be useful for reserving vtable slots (for ABI forwards compatibility) or for declaring methods that cannot be hidden by derived classes. This may well be a good idea for a warning, but I don't think we know enough about emerging idioms for usage of 'final' to start warning on this just yet.

That said, if we see a virtual method in a derived class (especially one marked 'final'), and a near-match virtual method in a base class, we should probably warn on that.