[LLVMbugs] [Bug 6127] Provide a warning when a method's only difference to a inherited one is "const"

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Fri Jun 22 14:15:23 PDT 2012


http://llvm.org/bugs/show_bug.cgi?id=6127

Kaelyn Uhrain <rikka at google.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |rikka at google.com
         Resolution|                            |FIXED

--- Comment #2 from Kaelyn Uhrain <rikka at google.com> 2012-06-22 16:15:23 CDT ---
Not sure when it was added, but in the 3.1 release clang has
-Woverloaded-virtual that is off by default and enabled by -Wall that will warn
on the example given:

$ cat tmp.cc 
#include <cstdio>

class foo {
public:
  virtual void f() { printf("foo\n"); }
  virtual void g() const { printf("foo\n"); }
};

class bar : public foo {
public:
  void f() const { printf("bar\n"); }
  void g() const { printf("bar\n"); }
};

int main() {
  foo *b = new bar();
  b->f();
  b->g();
  return 0;
}


$ clang++ -Wall -fsyntax-only tmp.cc 
tmp.cc:11:8: warning: 'bar::f' hides overloaded virtual function
[-Woverloaded-virtual]
  void f() const { printf("bar\n"); }
       ^
tmp.cc:5:16: note: hidden overloaded virtual function 'foo::f' declared here
  virtual void f() { printf("foo\n"); }
               ^
1 warning generated.

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list