From: Richard Smith Date: Thu, 30 Aug 2012 13:13:20 +0000 (+0000) Subject: PR13652: Don't assume the parameter array on a FunctionTypeLoc for a lambda will X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3bc22262af7b09a459b400976cfce3d9318b8ea9;p=clang 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@162904 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaLambda.cpp b/lib/Sema/SemaLambda.cpp index 6414c6fbac..75ea5368f8 100644 --- a/lib/Sema/SemaLambda.cpp +++ b/lib/Sema/SemaLambda.cpp @@ -377,7 +377,7 @@ void Sema::ActOnStartOfLambdaDefinition(LambdaIntroducer &Intro, bool ExplicitResultType = true; bool ContainsUnexpandedParameterPack = false; SourceLocation EndLoc; - llvm::ArrayRef Params; + llvm::SmallVector 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()->getResultType() != Context.DependentTy; - - TypeLoc TL = MethodTyInfo->getTypeLoc(); - FunctionProtoTypeLoc Proto = cast(TL); - Params = llvm::ArrayRef(Proto.getParmArray(), - Proto.getNumArgs()); + + Params.reserve(FTI.NumArgs); + for (unsigned i = 0, e = FTI.NumArgs; i != e; ++i) + Params.push_back(cast(FTI.ArgInfo[i].Param)); // Check for unexpanded parameter packs in the method type. if (MethodTyInfo->getType()->containsUnexpandedParameterPack()) diff --git a/test/Parser/cxx0x-lambda-expressions.cpp b/test/Parser/cxx0x-lambda-expressions.cpp index 7e9d4751e6..82b26534a1 100644 --- a/test/Parser/cxx0x-lambda-expressions.cpp +++ b/test/Parser/cxx0x-lambda-expressions.cpp @@ -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; }