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.

llvm-svn: 81460
This commit is contained in:
Anders Carlsson
2009-09-10 20:48:14 +00:00
parent 7b98b9291c
commit 04e1e22fe7
2 changed files with 26 additions and 1 deletions

View File

@@ -2142,8 +2142,16 @@ Sema::BuildMemberReferenceExpr(Scope *S, ExprArg Base, SourceLocation OpLoc,
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)) {

View File

@@ -24,3 +24,20 @@ void A::h(A* a)
(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}}
}