Parse: Don't crash when default argument in typedef consists of sole '='

We'd crash trying to make the SourceRange for the tokens we'd like to
highlight.  Don't assume there is more than one token makes up the
default argument.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@225774 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
David Majnemer 2015-01-13 07:42:33 +00:00
parent 8f0f848a5e
commit 269798ba2c
2 changed files with 8 additions and 2 deletions

View File

@ -388,9 +388,14 @@ void Sema::CheckExtraCXXDefaultArguments(Declarator &D) {
ParmVarDecl *Param = cast<ParmVarDecl>(chunk.Fun.Params[argIdx].Param);
if (Param->hasUnparsedDefaultArg()) {
CachedTokens *Toks = chunk.Fun.Params[argIdx].DefaultArgTokens;
SourceRange SR;
if (Toks->size() > 1)
SR = SourceRange((*Toks)[1].getLocation(),
Toks->back().getLocation());
else
SR = UnparsedDefaultArgLocs[Param];
Diag(Param->getLocation(), diag::err_param_default_argument_nonfunc)
<< SourceRange((*Toks)[1].getLocation(),
Toks->back().getLocation());
<< SR;
delete Toks;
chunk.Fun.Params[argIdx].DefaultArgTokens = nullptr;
} else if (Param->getDefaultArg()) {

View File

@ -39,4 +39,5 @@ struct S {
struct U {
void i(int x = ) {} // expected-error{{expected expression}}
typedef int *fp(int x = ); // expected-error{{default arguments can only be specified for parameters in a function declaration}}
};