diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-11-19 21:13:18 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-11-19 21:13:18 +0000 |
commit | 1a5bd5d680726f3d133da27791b228b2c8fe96c6 (patch) | |
tree | da409b9a876a0b0227e8906fb06e4988daef8853 /lib | |
parent | 728948fba8ce2249db0a6fd228d883f38434289a (diff) |
PR14381: Never skip constexpr function bodies when code-completing. We may need
them in order to parse the rest of the file.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@168327 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Parse/ParseStmt.cpp | 6 | ||||
-rw-r--r-- | lib/Sema/SemaDecl.cpp | 16 |
2 files changed, 20 insertions, 2 deletions
diff --git a/lib/Parse/ParseStmt.cpp b/lib/Parse/ParseStmt.cpp index a4e0c9844a..12f9fac484 100644 --- a/lib/Parse/ParseStmt.cpp +++ b/lib/Parse/ParseStmt.cpp @@ -2003,7 +2003,8 @@ Decl *Parser::ParseFunctionStatementBody(Decl *Decl, ParseScope &BodyScope) { assert(Tok.is(tok::l_brace)); SourceLocation LBraceLoc = Tok.getLocation(); - if (SkipFunctionBodies && trySkippingFunctionBody()) { + if (SkipFunctionBodies && Actions.canSkipFunctionBody(Decl) && + trySkippingFunctionBody()) { BodyScope.Exit(); return Actions.ActOnFinishFunctionBody(Decl, 0); } @@ -2045,7 +2046,8 @@ Decl *Parser::ParseFunctionTryBlock(Decl *Decl, ParseScope &BodyScope) { else Actions.ActOnDefaultCtorInitializers(Decl); - if (SkipFunctionBodies && trySkippingFunctionBody()) { + if (SkipFunctionBodies && Actions.canSkipFunctionBody(Decl) && + trySkippingFunctionBody()) { BodyScope.Exit(); return Actions.ActOnFinishFunctionBody(Decl, 0); } diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index cc19ce9959..629fccc306 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -7984,6 +7984,22 @@ void Sema::computeNRVO(Stmt *Body, FunctionScopeInfo *Scope) { const_cast<VarDecl*>(NRVOCandidate)->setNRVOVariable(true); } +bool Sema::canSkipFunctionBody(Decl *D) { + 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. + return !FD->isConstexpr(); +} + Decl *Sema::ActOnFinishFunctionBody(Decl *D, Stmt *BodyArg) { return ActOnFinishFunctionBody(D, BodyArg, false); } |