[PATCH] D82617: Disable GCC's -Woverloaded-virtual, which has false positives.

Arthur O'Dwyer via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 26 08:10:29 PDT 2020


Quuxplusone added a comment.

FWIW, I think the example you gave is **correct** for GCC to warn on. You said:

  class Base {
    virtual void foo(); // to be overridden
    void foo(int); // implemented in terms of foo()
  };

foo(int) is hidden in derived classes. So if someone derives from Base (which someone must, because Base is polymorphic), then the derived class violates the Liskov substitution principle: it doesn't have an `obj.foo(42)` method. The correct solution is to rename the implementation method from `foo()` to e.g. `fooImpl()` or (my personal style, following the NVI idiom) `do_foo()`.

GCC is correct to warn that this code is confusing and hard to maintain because of name hiding. The solution is to adjust the code until it is clear and maintainable, at which point it'll no longer trigger the warning. I don't see any problem with GCC's warning here.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82617/new/

https://reviews.llvm.org/D82617





More information about the cfe-commits mailing list