diff options
Diffstat (limited to 'clang/lib/Sema/SemaDecl.cpp')
-rw-r--r-- | clang/lib/Sema/SemaDecl.cpp | 50 |
1 files changed, 14 insertions, 36 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 9dac4d53024..949526b3edf 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -845,7 +845,8 @@ Corrected: // seems likely a type is wanted instead of the non-type that was found. bool NextIsOp = NextToken.is(tok::amp) || NextToken.is(tok::star); if ((NextToken.is(tok::identifier) || - (NextIsOp && FirstDecl->isFunctionOrFunctionTemplate())) && + (NextIsOp && + FirstDecl->getUnderlyingDecl()->isFunctionOrFunctionTemplate())) && isTagTypeWithMissingTag(*this, Result, S, SS, Name, NameLoc)) { TypeDecl *Type = Result.getAsSingle<TypeDecl>(); DiagnoseUseOfDecl(Type, NameLoc); @@ -962,12 +963,9 @@ void Sema::ExitDeclaratorContext(Scope *S) { void Sema::ActOnReenterFunctionContext(Scope* S, Decl *D) { - FunctionDecl *FD = dyn_cast<FunctionDecl>(D); - if (FunctionTemplateDecl *TFD = dyn_cast_or_null<FunctionTemplateDecl>(D)) { - // We assume that the caller has already called - // ActOnReenterTemplateScope - FD = TFD->getTemplatedDecl(); - } + // We assume that the caller has already called + // ActOnReenterTemplateScope so getTemplatedDecl() works. + FunctionDecl *FD = D->getAsFunction(); if (!FD) return; @@ -2270,12 +2268,7 @@ static bool haveIncompatibleLanguageLinkages(const T *Old, const T *New) { bool Sema::MergeFunctionDecl(FunctionDecl *New, Decl *OldD, Scope *S, bool MergeTypeWithOld) { // Verify the old decl was also a function. - FunctionDecl *Old = 0; - if (FunctionTemplateDecl *OldFunctionTemplate - = dyn_cast<FunctionTemplateDecl>(OldD)) - Old = OldFunctionTemplate->getTemplatedDecl(); - else - Old = dyn_cast<FunctionDecl>(OldD); + FunctionDecl *Old = OldD->getAsFunction(); if (!Old) { if (UsingShadowDecl *Shadow = dyn_cast<UsingShadowDecl>(OldD)) { if (New->getFriendObjectKind()) { @@ -7474,10 +7467,9 @@ bool Sema::CheckFunctionDeclaration(Scope *S, FunctionDecl *NewFD, if (!getLangOpts().CPlusPlus1y && MD && MD->isConstexpr() && !MD->isStatic() && !isa<CXXConstructorDecl>(MD) && (MD->getTypeQualifiers() & Qualifiers::Const) == 0) { - CXXMethodDecl *OldMD = dyn_cast_or_null<CXXMethodDecl>(OldDecl); - if (FunctionTemplateDecl *OldTD = - dyn_cast_or_null<FunctionTemplateDecl>(OldDecl)) - OldMD = dyn_cast<CXXMethodDecl>(OldTD->getTemplatedDecl()); + CXXMethodDecl *OldMD = 0; + if (OldDecl) + OldMD = dyn_cast<CXXMethodDecl>(OldDecl->getAsFunction()); if (!OldMD || !OldMD->isStatic()) { const FunctionProtoType *FPT = MD->getType()->castAs<FunctionProtoType>(); @@ -9699,24 +9691,15 @@ void Sema::computeNRVO(Stmt *Body, FunctionScopeInfo *Scope) { } bool Sema::canSkipFunctionBody(Decl *D) { - if (!Consumer.shouldSkipFunctionBody(D)) - return false; - - if (isa<ObjCMethodDecl>(D)) - return true; - - FunctionDecl *FD = 0; - if (FunctionTemplateDecl *FTD = dyn_cast<FunctionTemplateDecl>(D)) - FD = FTD->getTemplatedDecl(); - else - FD = cast<FunctionDecl>(D); - // We cannot skip the body of a function (or function template) which is // constexpr, since we may need to evaluate its body in order to parse the // rest of the file. // We cannot skip the body of a function with an undeduced return type, // because any callers of that function need to know the type. - return !FD->isConstexpr() && !FD->getResultType()->isUndeducedType(); + if (const FunctionDecl *FD = D->getAsFunction()) + if (FD->isConstexpr() || FD->getResultType()->isUndeducedType()) + return false; + return Consumer.shouldSkipFunctionBody(D); } Decl *Sema::ActOnSkippedFunctionBody(Decl *Decl) { @@ -9733,12 +9716,7 @@ Decl *Sema::ActOnFinishFunctionBody(Decl *D, Stmt *BodyArg) { Decl *Sema::ActOnFinishFunctionBody(Decl *dcl, Stmt *Body, bool IsInstantiation) { - FunctionDecl *FD = 0; - FunctionTemplateDecl *FunTmpl = dyn_cast_or_null<FunctionTemplateDecl>(dcl); - if (FunTmpl) - FD = FunTmpl->getTemplatedDecl(); - else - FD = dyn_cast_or_null<FunctionDecl>(dcl); + FunctionDecl *FD = dcl ? dcl->getAsFunction() : 0; sema::AnalysisBasedWarnings::Policy WP = AnalysisWarnings.getDefaultPolicy(); sema::AnalysisBasedWarnings::Policy *ActivePolicy = 0; |