r225768 - Parse: Don't crash if missing an initializer expression

David Majnemer david.majnemer at gmail.com
Mon Jan 12 21:28:25 PST 2015


Author: majnemer
Date: Mon Jan 12 23:28:24 2015
New Revision: 225768

URL: http://llvm.org/viewvc/llvm-project?rev=225768&view=rev
Log:
Parse: Don't crash if missing an initializer expression

Modified:
    cfe/trunk/lib/Parse/ParseDecl.cpp
    cfe/trunk/test/Parser/cxx-default-args.cpp

Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=225768&r1=225767&r2=225768&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Mon Jan 12 23:28:24 2015
@@ -5625,13 +5625,14 @@ void Parser::ParseParameterDeclarationCl
           // 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 '='.

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=225768&r1=225767&r2=225768&view=diff
==============================================================================
--- cfe/trunk/test/Parser/cxx-default-args.cpp (original)
+++ cfe/trunk/test/Parser/cxx-default-args.cpp Mon Jan 12 23:28:24 2015
@@ -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}}
+};





More information about the cfe-commits mailing list