r225774 - Parse: Don't crash when default argument in typedef consists of sole '='
David Majnemer
david.majnemer at gmail.com
Mon Jan 12 23:42:34 PST 2015
Author: majnemer
Date: Tue Jan 13 01:42:33 2015
New Revision: 225774
URL: http://llvm.org/viewvc/llvm-project?rev=225774&view=rev
Log:
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.
Modified:
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/test/Parser/cxx-default-args.cpp
Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=225774&r1=225773&r2=225774&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Tue Jan 13 01:42:33 2015
@@ -388,9 +388,14 @@ void Sema::CheckExtraCXXDefaultArguments
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()) {
Modified: cfe/trunk/test/Parser/cxx-default-args.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/cxx-default-args.cpp?rev=225774&r1=225773&r2=225774&view=diff
==============================================================================
--- cfe/trunk/test/Parser/cxx-default-args.cpp (original)
+++ cfe/trunk/test/Parser/cxx-default-args.cpp Tue Jan 13 01:42:33 2015
@@ -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}}
};
More information about the cfe-commits
mailing list