]> granicus.if.org Git - clang/commitdiff
PR13652: Don't assume the parameter array on a FunctionTypeLoc for a lambda will
authorRichard Smith <richard-llvm@metafoo.co.uk>
Thu, 30 Aug 2012 13:13:20 +0000 (13:13 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Thu, 30 Aug 2012 13:13:20 +0000 (13:13 +0000)
be filled in; they won't if the lambda's declarator has an invalid type. Instead
take the parameters from the declarator directly.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@162904 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaLambda.cpp
test/Parser/cxx0x-lambda-expressions.cpp

index 6414c6fbac97b86fa354400a34bb95c0b036ae43..75ea5368f86c0de2369387f50b3eceb4de1a59ce 100644 (file)
@@ -377,7 +377,7 @@ void Sema::ActOnStartOfLambdaDefinition(LambdaIntroducer &Intro,
   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 @@ void Sema::ActOnStartOfLambdaDefinition(LambdaIntroducer &Intro,
     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())
index 7e9d4751e6efb05060e82f66a42a4d4b7c54e4fa..82b26534a1aeb2deeea0569c81c43d52d1ac214c 100644 (file)
@@ -26,6 +26,7 @@ class C {
 
     [] -> 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;
   }