Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit 8f0f848

Browse files
committed
Parse: Don't crash if missing an initializer expression
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@225768 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent d6f99ed commit 8f0f848

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

lib/Parse/ParseDecl.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -5625,13 +5625,14 @@ void Parser::ParseParameterDeclarationClause(
56255625
// FIXME: Can we use a smart pointer for Toks?
56265626
DefArgToks = new CachedTokens;
56275627

5628+
SourceLocation ArgStartLoc = NextToken().getLocation();
56285629
if (!ConsumeAndStoreInitializer(*DefArgToks, CIK_DefaultArgument)) {
56295630
delete DefArgToks;
56305631
DefArgToks = nullptr;
56315632
Actions.ActOnParamDefaultArgumentError(Param, EqualLoc);
56325633
} else {
56335634
Actions.ActOnParamUnparsedDefaultArgument(Param, EqualLoc,
5634-
(*DefArgToks)[1].getLocation());
5635+
ArgStartLoc);
56355636
}
56365637
} else {
56375638
// Consume the '='.

test/Parser/cxx-default-args.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,7 @@ struct T {
3636
struct S {
3737
void f(int &r = error); // expected-error {{use of undeclared identifier 'error'}}
3838
};
39+
40+
struct U {
41+
void i(int x = ) {} // expected-error{{expected expression}}
42+
};

0 commit comments

Comments
 (0)