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 | cbea95dd9551c4388af16ef3808843707aecdd21 (patch) | |
tree | be7a5718ce52a6baa7704843014f9c3d966106e9 /clang/lib/Parse/ParseDecl.cpp | |
parent | 7ac3825afbd94a7f266c5063d5b38654d9da1f88 (diff) | |
download | bcm5719-llvm-cbea95dd9551c4388af16ef3808843707aecdd21.tar.gz bcm5719-llvm-cbea95dd9551c4388af16ef3808843707aecdd21.zip |
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
llvm-svn: 312788
Diffstat (limited to 'clang/lib/Parse/ParseDecl.cpp')
-rw-r--r-- | clang/lib/Parse/ParseDecl.cpp | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp index b20b0db7d30..15fefaa5a66 100644 --- a/clang/lib/Parse/ParseDecl.cpp +++ b/clang/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); |