diff options
author | Anders Carlsson <andersca@mac.com> | 2011-05-06 14:25:31 +0000 |
---|---|---|
committer | Anders Carlsson <andersca@mac.com> | 2011-05-06 14:25:31 +0000 |
commit | 2174d4c11c1544a6729637790637b765e35b67a3 (patch) | |
tree | 65f332794d67239aea3ac74935030388b1a1123d /lib | |
parent | 9d0fbeadc455c8292837b738b6af315d27930637 (diff) |
Warn when trying to call a pure virtual member function in a class from the class constructor/destructor. Fixes PR7966.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@130982 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Sema/SemaOverload.cpp | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/Sema/SemaOverload.cpp b/lib/Sema/SemaOverload.cpp index 79caecc5a8..64f04de87a 100644 --- a/lib/Sema/SemaOverload.cpp +++ b/lib/Sema/SemaOverload.cpp @@ -8781,6 +8781,19 @@ Sema::BuildCallToMemberFunction(Scope *S, Expr *MemExprE, if (CheckFunctionCall(Method, TheCall)) return ExprError(); + if ((isa<CXXConstructorDecl>(CurContext) || + isa<CXXDestructorDecl>(CurContext)) && + TheCall->getMethodDecl()->isPure()) { + const CXXMethodDecl *MD = TheCall->getMethodDecl(); + + if (isa<CXXThisExpr>(MemExpr->getBase()->IgnoreParenCasts())) + Diag(MemExpr->getLocStart(), + diag::warn_call_to_pure_virtual_member_function_from_ctor_dtor) + << MD->getDeclName() << isa<CXXDestructorDecl>(CurContext) + << MD->getParent()->getDeclName(); + + Diag(MD->getLocStart(), diag::note_previous_decl) << MD->getDeclName(); + } return MaybeBindToTemporary(TheCall); } |