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 | 1ab34b3ad579f43f915cc3ae5c5e2d80fdd7191b (patch) | |
| tree | c1956d7988e019085776c1ab305e3ea9f8a17721 | |
| parent | f65a638d942b87413a7181acb965e4c2fc4c0c6f (diff) | |
| download | bcm5719-llvm-1ab34b3ad579f43f915cc3ae5c5e2d80fdd7191b.tar.gz bcm5719-llvm-1ab34b3ad579f43f915cc3ae5c5e2d80fdd7191b.zip | |
PR14381: Never skip constexpr function bodies when code-completing. We may need
them in order to parse the rest of the file.
llvm-svn: 168327
| -rw-r--r-- | clang/include/clang/Sema/Sema.h | 9 | ||||
| -rw-r--r-- | clang/lib/Parse/ParseStmt.cpp | 6 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaDecl.cpp | 16 | ||||
| -rw-r--r-- | clang/test/CodeCompletion/constexpr.cpp | 13 |
4 files changed, 42 insertions, 2 deletions
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index a67e630cfd7..ee365c3299d 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -1379,6 +1379,15 @@ public: return D && isa<ObjCMethodDecl>(D); } + /// \brief Determine whether we can skip parsing the body of a function + /// definition, assuming we don't care about analyzing its body or emitting + /// code for that function. + /// + /// This will be \c false only if we may need the body of the function in + /// order to parse the rest of the program (for instance, if it is + /// \c constexpr in C++11 or has an 'auto' return type in C++14). + bool canSkipFunctionBody(Decl *D); + void computeNRVO(Stmt *Body, sema::FunctionScopeInfo *Scope); Decl *ActOnFinishFunctionBody(Decl *Decl, Stmt *Body); Decl *ActOnFinishFunctionBody(Decl *Decl, Stmt *Body, bool IsInstantiation); diff --git a/clang/lib/Parse/ParseStmt.cpp b/clang/lib/Parse/ParseStmt.cpp index a4e0c9844ac..12f9fac4847 100644 --- a/clang/lib/Parse/ParseStmt.cpp +++ b/clang/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/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index cc19ce99596..629fccc3064 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/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); } diff --git a/clang/test/CodeCompletion/constexpr.cpp b/clang/test/CodeCompletion/constexpr.cpp new file mode 100644 index 00000000000..12396c0198f --- /dev/null +++ b/clang/test/CodeCompletion/constexpr.cpp @@ -0,0 +1,13 @@ +// RUN: %clang_cc1 -fsyntax-only -std=c++11 -code-completion-at=%s:12:9 %s -o - | FileCheck %s + +// PR14381: need constexpr function bodies always, even if code-completing. +template<int> struct S; +template<> struct S<1> { + typedef int type; +}; +constexpr int f() { + return 1; +} + +S<f()>:: +// CHECK: COMPLETION: type : type |

