diff options
author | Douglas Gregor <dgregor@apple.com> | 2009-12-01 17:24:26 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2009-12-01 17:24:26 +0000 |
commit | 4ba3136b3eb9740a07bd61d0ab23ce9a8d894dee (patch) | |
tree | 525f804333c9a177e4635d61de93b6fe891ea83e /lib/Sema/SemaDecl.cpp | |
parent | 9af2f52fbcb993350f54e57d498e7849ba29c75d (diff) |
Move the checking of overridden virtual functions into the code path
common to both parsing and template instantiation, so that we'll find
overridden virtuals for member functions of class templates when they
are instantiated.
Additionally, factor out the checking for pure virtual functions, so
that it will be executed both at parsing time and at template
instantiation time.
These changes fix PR5656 (for real), although one more tweak
w.r.t. member function templates will be coming along shortly.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@90241 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaDecl.cpp')
-rw-r--r-- | lib/Sema/SemaDecl.cpp | 25 |
1 files changed, 9 insertions, 16 deletions
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 2087f8b8c6..49be340873 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -2865,9 +2865,6 @@ Sema::ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC, NewFD->setAccess(AS_public); } - if (CXXMethodDecl *NewMD = dyn_cast<CXXMethodDecl>(NewFD)) - AddOverriddenMethods(cast<CXXRecordDecl>(DC), NewMD); - if (SC == FunctionDecl::Static && isa<CXXMethodDecl>(NewFD) && !CurContext->isRecord()) { // C++ [class.static]p1: @@ -3257,8 +3254,13 @@ void Sema::CheckFunctionDeclaration(FunctionDecl *NewFD, // FIXME: C++0x: don't do this for "= default" destructors Record->setHasTrivialDestructor(false); } else if (CXXConversionDecl *Conversion - = dyn_cast<CXXConversionDecl>(NewFD)) + = dyn_cast<CXXConversionDecl>(NewFD)) { ActOnConversionDeclarator(Conversion); + } + + // Find any virtual functions that this function overrides. + if (CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(NewFD)) + AddOverriddenMethods(Method->getParent(), Method); // Extra checking for C++ overloaded operators (C++ [over.oper]). if (NewFD->isOverloadedOperator() && @@ -3392,18 +3394,9 @@ void Sema::AddInitializerToDecl(DeclPtrTy dcl, ExprArg init, bool DirectInit) { IntegerLiteral *IL; Expr *Init = static_cast<Expr *>(init.get()); if ((IL = dyn_cast<IntegerLiteral>(Init)) && IL->getValue() == 0 && - Context.getCanonicalType(IL->getType()) == Context.IntTy) { - if (Method->isVirtual()) { - Method->setPure(); - - // A class is abstract if at least one function is pure virtual. - cast<CXXRecordDecl>(CurContext)->setAbstract(true); - } else if (!Method->isInvalidDecl()) { - Diag(Method->getLocation(), diag::err_non_virtual_pure) - << Method->getDeclName() << Init->getSourceRange(); - Method->setInvalidDecl(); - } - } else { + Context.getCanonicalType(IL->getType()) == Context.IntTy) + CheckPureMethod(Method, Init->getSourceRange()); + else { Diag(Method->getLocation(), diag::err_member_function_initialization) << Method->getDeclName() << Init->getSourceRange(); Method->setInvalidDecl(); |