[cfe-commits] r162904 - in /cfe/trunk: lib/Sema/SemaLambda.cpp test/Parser/cxx0x-lambda-expressions.cpp

Richard Smith richard-llvm at metafoo.co.uk
Thu Aug 30 06:13:21 PDT 2012


Author: rsmith
Date: Thu Aug 30 08:13:20 2012
New Revision: 162904

URL: http://llvm.org/viewvc/llvm-project?rev=162904&view=rev
Log:
PR13652: Don't assume the parameter array on a FunctionTypeLoc for a lambda will
be filled in; they won't if the lambda's declarator has an invalid type. Instead
take the parameters from the declarator directly.

Modified:
    cfe/trunk/lib/Sema/SemaLambda.cpp
    cfe/trunk/test/Parser/cxx0x-lambda-expressions.cpp

Modified: cfe/trunk/lib/Sema/SemaLambda.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaLambda.cpp?rev=162904&r1=162903&r2=162904&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaLambda.cpp (original)
+++ cfe/trunk/lib/Sema/SemaLambda.cpp Thu Aug 30 08:13:20 2012
@@ -377,7 +377,7 @@
   bool ExplicitResultType = true;
   bool ContainsUnexpandedParameterPack = false;
   SourceLocation EndLoc;
-  llvm::ArrayRef<ParmVarDecl *> Params;
+  llvm::SmallVector<ParmVarDecl *, 8> Params;
   if (ParamInfo.getNumTypeObjects() == 0) {
     // C++11 [expr.prim.lambda]p4:
     //   If a lambda-expression does not include a lambda-declarator, it is as 
@@ -410,11 +410,10 @@
     ExplicitResultType
       = MethodTyInfo->getType()->getAs<FunctionType>()->getResultType() 
                                                         != Context.DependentTy;
-    
-    TypeLoc TL = MethodTyInfo->getTypeLoc();
-    FunctionProtoTypeLoc Proto = cast<FunctionProtoTypeLoc>(TL);
-    Params = llvm::ArrayRef<ParmVarDecl *>(Proto.getParmArray(), 
-                                           Proto.getNumArgs());
+
+    Params.reserve(FTI.NumArgs);
+    for (unsigned i = 0, e = FTI.NumArgs; i != e; ++i)
+      Params.push_back(cast<ParmVarDecl>(FTI.ArgInfo[i].Param));
 
     // Check for unexpanded parameter packs in the method type.
     if (MethodTyInfo->getType()->containsUnexpandedParameterPack())

Modified: cfe/trunk/test/Parser/cxx0x-lambda-expressions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/cxx0x-lambda-expressions.cpp?rev=162904&r1=162903&r2=162904&view=diff
==============================================================================
--- cfe/trunk/test/Parser/cxx0x-lambda-expressions.cpp (original)
+++ cfe/trunk/test/Parser/cxx0x-lambda-expressions.cpp Thu Aug 30 08:13:20 2012
@@ -26,6 +26,7 @@
 
     [] -> int { return 0; }; // expected-error{{lambda requires '()' before return type}}
     [] mutable -> int { return 0; }; // expected-error{{lambda requires '()' before 'mutable'}}
+    [](int) -> {}; // PR13652 expected-error {{expected a type}}
     return 1;
   }
 





More information about the cfe-commits mailing list