From 906ed278b96692cdb9546c16ea1f958b6213d9e1 Mon Sep 17 00:00:00 2001 From: David Majnemer Date: Tue, 13 Jan 2015 05:28:24 +0000 Subject: [PATCH] Parse: Don't crash if missing an initializer expression llvm-svn: 225768 --- clang/lib/Parse/ParseDecl.cpp | 3 ++- clang/test/Parser/cxx-default-args.cpp | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp index 0d8b0cc..93125e9 100644 --- a/clang/lib/Parse/ParseDecl.cpp +++ b/clang/lib/Parse/ParseDecl.cpp @@ -5625,13 +5625,14 @@ void Parser::ParseParameterDeclarationClause( // FIXME: Can we use a smart pointer for Toks? DefArgToks = new CachedTokens; + SourceLocation ArgStartLoc = NextToken().getLocation(); if (!ConsumeAndStoreInitializer(*DefArgToks, CIK_DefaultArgument)) { delete DefArgToks; DefArgToks = nullptr; Actions.ActOnParamDefaultArgumentError(Param, EqualLoc); } else { Actions.ActOnParamUnparsedDefaultArgument(Param, EqualLoc, - (*DefArgToks)[1].getLocation()); + ArgStartLoc); } } else { // Consume the '='. diff --git a/clang/test/Parser/cxx-default-args.cpp b/clang/test/Parser/cxx-default-args.cpp index f0e2e69..0c028f7 100644 --- a/clang/test/Parser/cxx-default-args.cpp +++ b/clang/test/Parser/cxx-default-args.cpp @@ -36,3 +36,7 @@ struct T { struct S { void f(int &r = error); // expected-error {{use of undeclared identifier 'error'}} }; + +struct U { + void i(int x = ) {} // expected-error{{expected expression}} +}; -- 2.7.4