Don't check use of a member function declaration used if the member function is virtual and the member reference expression doesn't explicitly qualify it. Fixes PR4878.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@81460 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index 723d6d7..53f3dde 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -2142,8 +2142,16 @@
if (MemberDecl->isInvalidDecl())
return ExprError();
+ bool ShouldCheckUse = true;
+ if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(MemberDecl)) {
+ // Don't diagnose the use of a virtual member function unless it's
+ // explicitly qualified.
+ if (MD->isVirtual() && (!SS || !SS->isSet()))
+ ShouldCheckUse = false;
+ }
+
// Check the use of this field
- if (DiagnoseUseOfDecl(MemberDecl, MemberLoc))
+ if (ShouldCheckUse && DiagnoseUseOfDecl(MemberDecl, MemberLoc))
return ExprError();
if (FieldDecl *FD = dyn_cast<FieldDecl>(MemberDecl)) {
diff --git a/test/SemaCXX/attr-deprecated.cpp b/test/SemaCXX/attr-deprecated.cpp
index 99a249e..10b4a55 100644
--- a/test/SemaCXX/attr-deprecated.cpp
+++ b/test/SemaCXX/attr-deprecated.cpp
@@ -24,3 +24,20 @@
(void)b;
(void)a->b;
}
+
+struct B {
+ virtual void f() __attribute__((deprecated));
+};
+
+struct C : B {
+ virtual void f();
+};
+
+void f(B* b, C *c) {
+ b->f();
+ b->B::f(); // expected-warning{{'f' is deprecated}}
+
+ c->f();
+ c->C::f();
+ c->B::f(); // expected-warning{{'f' is deprecated}}
+}