diff options
author | Ilya Biryukov <ibiryukov@google.com> | 2017-09-08 13:36:38 +0000 |
---|---|---|
committer | Ilya Biryukov <ibiryukov@google.com> | 2017-09-08 13:36:38 +0000 |
commit | 78a32be113e2f01f214275598a0ece1c48f89849 (patch) | |
tree | 022adbdf560994dffa5a7fa2f98fef6da4aa9eb7 /lib/Parse/ParseDecl.cpp | |
parent | 0abc73f06cef0b9d73cb139f410cc23f53348ae4 (diff) |
Fixed a crash in code completion.
Summary: The crash occured when FunctionDecl was parsed with an initializer.
Reviewers: bkramer, klimek, francisco.lopes
Reviewed By: bkramer
Subscribers: cfe-commits
Differential Revision: https://reviews.llvm.org/D37382
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@312788 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Parse/ParseDecl.cpp')
-rw-r--r-- | lib/Parse/ParseDecl.cpp | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp index b20b0db7d3..15fefaa5a6 100644 --- a/lib/Parse/ParseDecl.cpp +++ b/lib/Parse/ParseDecl.cpp @@ -2264,11 +2264,23 @@ Decl *Parser::ParseDeclarationAfterDeclaratorAndAttributes( Actions.ActOnCXXEnterDeclInitializer(getCurScope(), ThisDecl); } - if (ParseExpressionList(Exprs, CommaLocs, [&] { - Actions.CodeCompleteConstructor(getCurScope(), - cast<VarDecl>(ThisDecl)->getType()->getCanonicalTypeInternal(), - ThisDecl->getLocation(), Exprs); - })) { + llvm::function_ref<void()> ExprListCompleter; + auto ThisVarDecl = dyn_cast_or_null<VarDecl>(ThisDecl); + auto ConstructorCompleter = [&, ThisVarDecl] { + Actions.CodeCompleteConstructor( + getCurScope(), ThisVarDecl->getType()->getCanonicalTypeInternal(), + ThisDecl->getLocation(), Exprs); + }; + if (ThisVarDecl) { + // ParseExpressionList can sometimes succeed even when ThisDecl is not + // VarDecl. This is an error and it is reported in a call to + // Actions.ActOnInitializerError(). However, we call + // CodeCompleteConstructor only on VarDecls, falling back to default + // completer in other cases. + ExprListCompleter = ConstructorCompleter; + } + + if (ParseExpressionList(Exprs, CommaLocs, ExprListCompleter)) { Actions.ActOnInitializerError(ThisDecl); SkipUntil(tok::r_paren, StopAtSemi); |