[cfe-commits] r166154 - in /cfe/trunk: lib/Sema/SemaDeclCXX.cpp test/SemaCXX/warn-overloaded-virtual.cpp
David Blaikie
dblaikie at gmail.com
Wed Oct 17 16:45:39 PDT 2012
Author: dblaikie
Date: Wed Oct 17 18:45:39 2012
New Revision: 166154
URL: http://llvm.org/viewvc/llvm-project?rev=166154&view=rev
Log:
Fix -Woverloaded-virtual when the using statement refers to a base declaration of a virtual function.
GCC and Clang both do not warn on:
struct a { virtual void func(); };
struct b: a { virtual void func(); void func(int); };
struct c: b { void func(int); using b::func; };
but if the "using" was using a::func GCC would still remain silent where Clang
would warn. This change makes Clang consistent with GCC's existing behavior.
Modified:
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/test/SemaCXX/warn-overloaded-virtual.cpp
Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=166154&r1=166153&r2=166154&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Wed Oct 17 18:45:39 2012
@@ -4770,7 +4770,12 @@
if (!Data.S->IsOverload(Data.Method, MD, false))
return true;
// Collect the overload only if its hidden.
- if (!Data.OverridenAndUsingBaseMethods.count(MD))
+ bool Using = Data.OverridenAndUsingBaseMethods.count(MD);
+ for (CXXMethodDecl::method_iterator I = MD->begin_overridden_methods(),
+ E = MD->end_overridden_methods();
+ I != E && !Using; ++I)
+ Using = Data.OverridenAndUsingBaseMethods.count(*I);
+ if (!Using)
overloadedMethods.push_back(MD);
}
}
Modified: cfe/trunk/test/SemaCXX/warn-overloaded-virtual.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-overloaded-virtual.cpp?rev=166154&r1=166153&r2=166154&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/warn-overloaded-virtual.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-overloaded-virtual.cpp Wed Oct 17 18:45:39 2012
@@ -64,3 +64,19 @@
static void f() {}
};
}
+
+namespace ThreeLayer {
+struct A {
+ virtual void f();
+};
+
+struct B: A {
+ void f();
+ void f(int);
+};
+
+struct C: B {
+ void f(int);
+ using A::f;
+};
+}
More information about the cfe-commits
mailing list