SemaLambda.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539
  1. //===--- SemaLambda.cpp - Semantic Analysis for C++11 Lambdas -------------===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This file implements semantic analysis for C++ lambda expressions.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #include "clang/Sema/DeclSpec.h"
  14. #include "clang/Sema/Initialization.h"
  15. #include "clang/Sema/Lookup.h"
  16. #include "clang/Sema/ScopeInfo.h"
  17. #include "clang/Sema/SemaInternal.h"
  18. #include "clang/Lex/Preprocessor.h"
  19. #include "clang/AST/ExprCXX.h"
  20. using namespace clang;
  21. using namespace sema;
  22. CXXRecordDecl *Sema::createLambdaClosureType(SourceRange IntroducerRange) {
  23. DeclContext *DC = CurContext;
  24. while (!(DC->isFunctionOrMethod() || DC->isRecord() || DC->isFileContext()))
  25. DC = DC->getParent();
  26. // Start constructing the lambda class.
  27. CXXRecordDecl *Class = CXXRecordDecl::CreateLambda(Context, DC,
  28. IntroducerRange.getBegin());
  29. CurContext->addDecl(Class);
  30. return Class;
  31. }
  32. CXXMethodDecl *Sema::startLambdaDefinition(CXXRecordDecl *Class,
  33. SourceRange IntroducerRange,
  34. TypeSourceInfo *MethodType,
  35. SourceLocation EndLoc) {
  36. // C++11 [expr.prim.lambda]p5:
  37. // The closure type for a lambda-expression has a public inline function
  38. // call operator (13.5.4) whose parameters and return type are described by
  39. // the lambda-expression's parameter-declaration-clause and
  40. // trailing-return-type respectively.
  41. DeclarationName MethodName
  42. = Context.DeclarationNames.getCXXOperatorName(OO_Call);
  43. DeclarationNameLoc MethodNameLoc;
  44. MethodNameLoc.CXXOperatorName.BeginOpNameLoc
  45. = IntroducerRange.getBegin().getRawEncoding();
  46. MethodNameLoc.CXXOperatorName.EndOpNameLoc
  47. = IntroducerRange.getEnd().getRawEncoding();
  48. CXXMethodDecl *Method
  49. = CXXMethodDecl::Create(Context, Class, EndLoc,
  50. DeclarationNameInfo(MethodName,
  51. IntroducerRange.getBegin(),
  52. MethodNameLoc),
  53. MethodType->getType(), MethodType,
  54. /*isStatic=*/false,
  55. SC_None,
  56. /*isInline=*/true,
  57. /*isConstExpr=*/false,
  58. EndLoc);
  59. Method->setAccess(AS_public);
  60. // Temporarily set the lexical declaration context to the current
  61. // context, so that the Scope stack matches the lexical nesting.
  62. Method->setLexicalDeclContext(Class->getDeclContext());
  63. return Method;
  64. }
  65. LambdaScopeInfo *Sema::enterLambdaScope(CXXMethodDecl *CallOperator,
  66. SourceRange IntroducerRange,
  67. LambdaCaptureDefault CaptureDefault,
  68. bool ExplicitParams,
  69. bool ExplicitResultType,
  70. bool Mutable) {
  71. PushLambdaScope(CallOperator->getParent(), CallOperator);
  72. LambdaScopeInfo *LSI = getCurLambda();
  73. if (CaptureDefault == LCD_ByCopy)
  74. LSI->ImpCaptureStyle = LambdaScopeInfo::ImpCap_LambdaByval;
  75. else if (CaptureDefault == LCD_ByRef)
  76. LSI->ImpCaptureStyle = LambdaScopeInfo::ImpCap_LambdaByref;
  77. LSI->IntroducerRange = IntroducerRange;
  78. LSI->ExplicitParams = ExplicitParams;
  79. LSI->Mutable = Mutable;
  80. if (ExplicitResultType) {
  81. LSI->ReturnType = CallOperator->getResultType();
  82. } else {
  83. LSI->HasImplicitReturnType = true;
  84. }
  85. return LSI;
  86. }
  87. void Sema::finishLambdaExplicitCaptures(LambdaScopeInfo *LSI) {
  88. LSI->finishedExplicitCaptures();
  89. }
  90. void Sema::addLambdaParameters(CXXMethodDecl *CallOperator, Scope *CurScope,
  91. llvm::ArrayRef<ParmVarDecl *> Params) {
  92. CallOperator->setParams(Params);
  93. CheckParmsForFunctionDef(const_cast<ParmVarDecl **>(Params.begin()),
  94. const_cast<ParmVarDecl **>(Params.end()),
  95. /*CheckParameterNames=*/false);
  96. // Introduce our parameters into the function scope
  97. for (unsigned p = 0, NumParams = CallOperator->getNumParams();
  98. p < NumParams; ++p) {
  99. ParmVarDecl *Param = CallOperator->getParamDecl(p);
  100. Param->setOwningFunction(CallOperator);
  101. // If this has an identifier, add it to the scope stack.
  102. if (CurScope && Param->getIdentifier()) {
  103. CheckShadow(CurScope, Param);
  104. PushOnScopeChains(Param, CurScope);
  105. }
  106. }
  107. }
  108. void Sema::ActOnStartOfLambdaDefinition(LambdaIntroducer &Intro,
  109. Declarator &ParamInfo,
  110. Scope *CurScope) {
  111. CXXRecordDecl *Class = createLambdaClosureType(Intro.Range);
  112. // Determine the signature of the call operator.
  113. TypeSourceInfo *MethodTyInfo;
  114. bool ExplicitParams = true;
  115. bool ExplicitResultType = true;
  116. SourceLocation EndLoc;
  117. if (ParamInfo.getNumTypeObjects() == 0) {
  118. // C++11 [expr.prim.lambda]p4:
  119. // If a lambda-expression does not include a lambda-declarator, it is as
  120. // if the lambda-declarator were ().
  121. FunctionProtoType::ExtProtoInfo EPI;
  122. EPI.HasTrailingReturn = true;
  123. EPI.TypeQuals |= DeclSpec::TQ_const;
  124. QualType MethodTy = Context.getFunctionType(Context.DependentTy,
  125. /*Args=*/0, /*NumArgs=*/0, EPI);
  126. MethodTyInfo = Context.getTrivialTypeSourceInfo(MethodTy);
  127. ExplicitParams = false;
  128. ExplicitResultType = false;
  129. EndLoc = Intro.Range.getEnd();
  130. } else {
  131. assert(ParamInfo.isFunctionDeclarator() &&
  132. "lambda-declarator is a function");
  133. DeclaratorChunk::FunctionTypeInfo &FTI = ParamInfo.getFunctionTypeInfo();
  134. // C++11 [expr.prim.lambda]p5:
  135. // This function call operator is declared const (9.3.1) if and only if
  136. // the lambda-expression's parameter-declaration-clause is not followed
  137. // by mutable. It is neither virtual nor declared volatile. [...]
  138. if (!FTI.hasMutableQualifier())
  139. FTI.TypeQuals |= DeclSpec::TQ_const;
  140. // C++11 [expr.prim.lambda]p5:
  141. // [...] Default arguments (8.3.6) shall not be specified in the
  142. // parameter-declaration-clause of a lambda-declarator.
  143. CheckExtraCXXDefaultArguments(ParamInfo);
  144. MethodTyInfo = GetTypeForDeclarator(ParamInfo, CurScope);
  145. // FIXME: Can these asserts actually fail?
  146. assert(MethodTyInfo && "no type from lambda-declarator");
  147. EndLoc = ParamInfo.getSourceRange().getEnd();
  148. ExplicitResultType
  149. = MethodTyInfo->getType()->getAs<FunctionType>()->getResultType()
  150. != Context.DependentTy;
  151. }
  152. CXXMethodDecl *Method = startLambdaDefinition(Class, Intro.Range,
  153. MethodTyInfo, EndLoc);
  154. // Attributes on the lambda apply to the method.
  155. ProcessDeclAttributes(CurScope, Method, ParamInfo);
  156. // Introduce the function call operator as the current declaration context.
  157. PushDeclContext(CurScope, Method);
  158. // Introduce the lambda scope.
  159. LambdaScopeInfo *LSI
  160. = enterLambdaScope(Method, Intro.Range, Intro.Default, ExplicitParams,
  161. ExplicitResultType,
  162. (Method->getTypeQualifiers() & Qualifiers::Const) == 0);
  163. // Handle explicit captures.
  164. SourceLocation PrevCaptureLoc
  165. = Intro.Default == LCD_None? Intro.Range.getBegin() : Intro.DefaultLoc;
  166. for (llvm::SmallVector<LambdaCapture, 4>::const_iterator
  167. C = Intro.Captures.begin(),
  168. E = Intro.Captures.end();
  169. C != E;
  170. PrevCaptureLoc = C->Loc, ++C) {
  171. if (C->Kind == LCK_This) {
  172. // C++11 [expr.prim.lambda]p8:
  173. // An identifier or this shall not appear more than once in a
  174. // lambda-capture.
  175. if (LSI->isCXXThisCaptured()) {
  176. Diag(C->Loc, diag::err_capture_more_than_once)
  177. << "'this'"
  178. << SourceRange(LSI->getCXXThisCapture().getLocation())
  179. << FixItHint::CreateRemoval(
  180. SourceRange(PP.getLocForEndOfToken(PrevCaptureLoc), C->Loc));
  181. continue;
  182. }
  183. // C++11 [expr.prim.lambda]p8:
  184. // If a lambda-capture includes a capture-default that is =, the
  185. // lambda-capture shall not contain this [...].
  186. if (Intro.Default == LCD_ByCopy) {
  187. Diag(C->Loc, diag::err_this_capture_with_copy_default)
  188. << FixItHint::CreateRemoval(
  189. SourceRange(PP.getLocForEndOfToken(PrevCaptureLoc), C->Loc));
  190. continue;
  191. }
  192. // C++11 [expr.prim.lambda]p12:
  193. // If this is captured by a local lambda expression, its nearest
  194. // enclosing function shall be a non-static member function.
  195. QualType ThisCaptureType = getCurrentThisType();
  196. if (ThisCaptureType.isNull()) {
  197. Diag(C->Loc, diag::err_this_capture) << true;
  198. continue;
  199. }
  200. CheckCXXThisCapture(C->Loc, /*Explicit=*/true);
  201. continue;
  202. }
  203. assert(C->Id && "missing identifier for capture");
  204. // C++11 [expr.prim.lambda]p8:
  205. // If a lambda-capture includes a capture-default that is &, the
  206. // identifiers in the lambda-capture shall not be preceded by &.
  207. // If a lambda-capture includes a capture-default that is =, [...]
  208. // each identifier it contains shall be preceded by &.
  209. if (C->Kind == LCK_ByRef && Intro.Default == LCD_ByRef) {
  210. Diag(C->Loc, diag::err_reference_capture_with_reference_default)
  211. << FixItHint::CreateRemoval(
  212. SourceRange(PP.getLocForEndOfToken(PrevCaptureLoc), C->Loc));
  213. continue;
  214. } else if (C->Kind == LCK_ByCopy && Intro.Default == LCD_ByCopy) {
  215. Diag(C->Loc, diag::err_copy_capture_with_copy_default)
  216. << FixItHint::CreateRemoval(
  217. SourceRange(PP.getLocForEndOfToken(PrevCaptureLoc), C->Loc));
  218. continue;
  219. }
  220. DeclarationNameInfo Name(C->Id, C->Loc);
  221. LookupResult R(*this, Name, LookupOrdinaryName);
  222. LookupName(R, CurScope);
  223. if (R.isAmbiguous())
  224. continue;
  225. if (R.empty()) {
  226. // FIXME: Disable corrections that would add qualification?
  227. CXXScopeSpec ScopeSpec;
  228. DeclFilterCCC<VarDecl> Validator;
  229. if (DiagnoseEmptyLookup(CurScope, ScopeSpec, R, Validator))
  230. continue;
  231. }
  232. // C++11 [expr.prim.lambda]p10:
  233. // The identifiers in a capture-list are looked up using the usual rules
  234. // for unqualified name lookup (3.4.1); each such lookup shall find a
  235. // variable with automatic storage duration declared in the reaching
  236. // scope of the local lambda expression.
  237. // FIXME: Check reaching scope.
  238. VarDecl *Var = R.getAsSingle<VarDecl>();
  239. if (!Var) {
  240. Diag(C->Loc, diag::err_capture_does_not_name_variable) << C->Id;
  241. continue;
  242. }
  243. if (!Var->hasLocalStorage()) {
  244. Diag(C->Loc, diag::err_capture_non_automatic_variable) << C->Id;
  245. Diag(Var->getLocation(), diag::note_previous_decl) << C->Id;
  246. continue;
  247. }
  248. // C++11 [expr.prim.lambda]p8:
  249. // An identifier or this shall not appear more than once in a
  250. // lambda-capture.
  251. if (LSI->isCaptured(Var)) {
  252. Diag(C->Loc, diag::err_capture_more_than_once)
  253. << C->Id
  254. << SourceRange(LSI->getCapture(Var).getLocation())
  255. << FixItHint::CreateRemoval(
  256. SourceRange(PP.getLocForEndOfToken(PrevCaptureLoc), C->Loc));
  257. continue;
  258. }
  259. TryCaptureKind Kind = C->Kind == LCK_ByRef ? TryCapture_ExplicitByRef :
  260. TryCapture_ExplicitByVal;
  261. TryCaptureVar(Var, C->Loc, Kind);
  262. }
  263. finishLambdaExplicitCaptures(LSI);
  264. // Set the parameters on the decl, if specified.
  265. if (isa<FunctionProtoTypeLoc>(MethodTyInfo->getTypeLoc())) {
  266. FunctionProtoTypeLoc Proto
  267. = cast<FunctionProtoTypeLoc>(MethodTyInfo->getTypeLoc());
  268. addLambdaParameters(Method, CurScope, Proto.getParams());
  269. }
  270. // FIXME: Check return type is complete, !isObjCObjectType
  271. // Enter a new evaluation context to insulate the lambda from any
  272. // cleanups from the enclosing full-expression.
  273. PushExpressionEvaluationContext(PotentiallyEvaluated);
  274. }
  275. void Sema::ActOnLambdaError(SourceLocation StartLoc, Scope *CurScope,
  276. bool IsInstantiation) {
  277. // Leave the expression-evaluation context.
  278. DiscardCleanupsInEvaluationContext();
  279. PopExpressionEvaluationContext();
  280. // Leave the context of the lambda.
  281. if (!IsInstantiation)
  282. PopDeclContext();
  283. // Finalize the lambda.
  284. LambdaScopeInfo *LSI = getCurLambda();
  285. CXXRecordDecl *Class = LSI->Lambda;
  286. Class->setInvalidDecl();
  287. SmallVector<Decl*, 4> Fields(Class->field_begin(), Class->field_end());
  288. ActOnFields(0, Class->getLocation(), Class, Fields,
  289. SourceLocation(), SourceLocation(), 0);
  290. CheckCompletedCXXClass(Class);
  291. PopFunctionScopeInfo();
  292. }
  293. ExprResult Sema::ActOnLambdaExpr(SourceLocation StartLoc, Stmt *Body,
  294. Scope *CurScope, bool IsInstantiation) {
  295. // Leave the expression-evaluation context.
  296. DiscardCleanupsInEvaluationContext();
  297. PopExpressionEvaluationContext();
  298. // Collect information from the lambda scope.
  299. llvm::SmallVector<LambdaExpr::Capture, 4> Captures;
  300. llvm::SmallVector<Expr *, 4> CaptureInits;
  301. LambdaCaptureDefault CaptureDefault;
  302. CXXRecordDecl *Class;
  303. CXXMethodDecl *CallOperator;
  304. SourceRange IntroducerRange;
  305. bool ExplicitParams;
  306. bool ExplicitResultType;
  307. bool LambdaExprNeedsCleanups;
  308. llvm::SmallVector<VarDecl *, 4> ArrayIndexVars;
  309. llvm::SmallVector<unsigned, 4> ArrayIndexStarts;
  310. {
  311. LambdaScopeInfo *LSI = getCurLambda();
  312. CallOperator = LSI->CallOperator;
  313. Class = LSI->Lambda;
  314. IntroducerRange = LSI->IntroducerRange;
  315. ExplicitParams = LSI->ExplicitParams;
  316. ExplicitResultType = !LSI->HasImplicitReturnType;
  317. LambdaExprNeedsCleanups = LSI->ExprNeedsCleanups;
  318. ArrayIndexVars.swap(LSI->ArrayIndexVars);
  319. ArrayIndexStarts.swap(LSI->ArrayIndexStarts);
  320. // Translate captures.
  321. for (unsigned I = 0, N = LSI->Captures.size(); I != N; ++I) {
  322. LambdaScopeInfo::Capture From = LSI->Captures[I];
  323. assert(!From.isBlockCapture() && "Cannot capture __block variables");
  324. bool IsImplicit = I >= LSI->NumExplicitCaptures;
  325. // Handle 'this' capture.
  326. if (From.isThisCapture()) {
  327. Captures.push_back(LambdaExpr::Capture(From.getLocation(),
  328. IsImplicit,
  329. LCK_This));
  330. CaptureInits.push_back(new (Context) CXXThisExpr(From.getLocation(),
  331. getCurrentThisType(),
  332. /*isImplicit=*/true));
  333. continue;
  334. }
  335. VarDecl *Var = From.getVariable();
  336. // FIXME: Handle pack expansions.
  337. LambdaCaptureKind Kind = From.isCopyCapture()? LCK_ByCopy : LCK_ByRef;
  338. Captures.push_back(LambdaExpr::Capture(From.getLocation(), IsImplicit,
  339. Kind, Var));
  340. CaptureInits.push_back(From.getCopyExpr());
  341. }
  342. switch (LSI->ImpCaptureStyle) {
  343. case CapturingScopeInfo::ImpCap_None:
  344. CaptureDefault = LCD_None;
  345. break;
  346. case CapturingScopeInfo::ImpCap_LambdaByval:
  347. CaptureDefault = LCD_ByCopy;
  348. break;
  349. case CapturingScopeInfo::ImpCap_LambdaByref:
  350. CaptureDefault = LCD_ByRef;
  351. break;
  352. case CapturingScopeInfo::ImpCap_Block:
  353. llvm_unreachable("block capture in lambda");
  354. break;
  355. }
  356. // C++11 [expr.prim.lambda]p4:
  357. // If a lambda-expression does not include a
  358. // trailing-return-type, it is as if the trailing-return-type
  359. // denotes the following type:
  360. // FIXME: Assumes current resolution to core issue 975.
  361. if (LSI->HasImplicitReturnType) {
  362. // - if there are no return statements in the
  363. // compound-statement, or all return statements return
  364. // either an expression of type void or no expression or
  365. // braced-init-list, the type void;
  366. if (LSI->ReturnType.isNull()) {
  367. LSI->ReturnType = Context.VoidTy;
  368. } else {
  369. // C++11 [expr.prim.lambda]p4:
  370. // - if the compound-statement is of the form
  371. //
  372. // { attribute-specifier-seq[opt] return expression ; }
  373. //
  374. // the type of the returned expression after
  375. // lvalue-to-rvalue conversion (4.1), array-to-pointer
  376. // conver- sion (4.2), and function-to-pointer conversion
  377. // (4.3);
  378. //
  379. // Since we're accepting the resolution to a post-C++11 core
  380. // issue with a non-trivial extension, provide a warning (by
  381. // default).
  382. CompoundStmt *CompoundBody = cast<CompoundStmt>(Body);
  383. if (!(CompoundBody->size() == 1 &&
  384. isa<ReturnStmt>(*CompoundBody->body_begin())) &&
  385. !Context.hasSameType(LSI->ReturnType, Context.VoidTy))
  386. Diag(IntroducerRange.getBegin(),
  387. diag::ext_lambda_implies_void_return);
  388. }
  389. // Create a function type with the inferred return type.
  390. const FunctionProtoType *Proto
  391. = CallOperator->getType()->getAs<FunctionProtoType>();
  392. QualType FunctionTy
  393. = Context.getFunctionType(LSI->ReturnType,
  394. Proto->arg_type_begin(),
  395. Proto->getNumArgs(),
  396. Proto->getExtProtoInfo());
  397. CallOperator->setType(FunctionTy);
  398. }
  399. // C++ [expr.prim.lambda]p7:
  400. // The lambda-expression's compound-statement yields the
  401. // function-body (8.4) of the function call operator [...].
  402. ActOnFinishFunctionBody(CallOperator, Body, IsInstantiation);
  403. CallOperator->setLexicalDeclContext(Class);
  404. Class->addDecl(CallOperator);
  405. // C++11 [expr.prim.lambda]p6:
  406. // The closure type for a lambda-expression with no lambda-capture
  407. // has a public non-virtual non-explicit const conversion function
  408. // to pointer to function having the same parameter and return
  409. // types as the closure type's function call operator.
  410. if (Captures.empty() && CaptureDefault == LCD_None) {
  411. const FunctionProtoType *Proto
  412. = CallOperator->getType()->getAs<FunctionProtoType>();
  413. QualType FunctionPtrTy;
  414. {
  415. FunctionProtoType::ExtProtoInfo ExtInfo = Proto->getExtProtoInfo();
  416. ExtInfo.TypeQuals = 0;
  417. QualType FunctionTy
  418. = Context.getFunctionType(Proto->getResultType(),
  419. Proto->arg_type_begin(),
  420. Proto->getNumArgs(),
  421. ExtInfo);
  422. FunctionPtrTy = Context.getPointerType(FunctionTy);
  423. }
  424. FunctionProtoType::ExtProtoInfo ExtInfo;
  425. ExtInfo.TypeQuals = Qualifiers::Const;
  426. QualType ConvTy = Context.getFunctionType(FunctionPtrTy, 0, 0, ExtInfo);
  427. SourceLocation Loc = IntroducerRange.getBegin();
  428. DeclarationName Name
  429. = Context.DeclarationNames.getCXXConversionFunctionName(
  430. Context.getCanonicalType(FunctionPtrTy));
  431. DeclarationNameLoc NameLoc;
  432. NameLoc.NamedType.TInfo = Context.getTrivialTypeSourceInfo(FunctionPtrTy,
  433. Loc);
  434. CXXConversionDecl *Conversion
  435. = CXXConversionDecl::Create(Context, Class, Loc,
  436. DeclarationNameInfo(Name, Loc, NameLoc),
  437. ConvTy,
  438. Context.getTrivialTypeSourceInfo(ConvTy,
  439. Loc),
  440. /*isInline=*/false, /*isExplicit=*/false,
  441. /*isConstexpr=*/false, Body->getLocEnd());
  442. Conversion->setAccess(AS_public);
  443. Conversion->setImplicit(true);
  444. Class->addDecl(Conversion);
  445. }
  446. // Finalize the lambda class.
  447. SmallVector<Decl*, 4> Fields(Class->field_begin(), Class->field_end());
  448. ActOnFields(0, Class->getLocation(), Class, Fields,
  449. SourceLocation(), SourceLocation(), 0);
  450. CheckCompletedCXXClass(Class);
  451. }
  452. if (LambdaExprNeedsCleanups)
  453. ExprNeedsCleanups = true;
  454. LambdaExpr *Lambda = LambdaExpr::Create(Context, Class, IntroducerRange,
  455. CaptureDefault, Captures,
  456. ExplicitParams, ExplicitResultType,
  457. CaptureInits, ArrayIndexVars,
  458. ArrayIndexStarts, Body->getLocEnd());
  459. // C++11 [expr.prim.lambda]p2:
  460. // A lambda-expression shall not appear in an unevaluated operand
  461. // (Clause 5).
  462. switch (ExprEvalContexts.back().Context) {
  463. case Unevaluated:
  464. // We don't actually diagnose this case immediately, because we
  465. // could be within a context where we might find out later that
  466. // the expression is potentially evaluated (e.g., for typeid).
  467. ExprEvalContexts.back().Lambdas.push_back(Lambda);
  468. break;
  469. case ConstantEvaluated:
  470. case PotentiallyEvaluated:
  471. case PotentiallyEvaluatedIfUsed:
  472. break;
  473. }
  474. return MaybeBindToTemporary(Lambda);
  475. }