clang  16.0.0git
SemaLambda.cpp
Go to the documentation of this file.
1 //===--- SemaLambda.cpp - Semantic Analysis for C++11 Lambdas -------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements semantic analysis for C++ lambda expressions.
10 //
11 //===----------------------------------------------------------------------===//
12 #include "clang/Sema/DeclSpec.h"
13 #include "TypeLocBuilder.h"
14 #include "clang/AST/ASTLambda.h"
15 #include "clang/AST/ExprCXX.h"
16 #include "clang/Basic/TargetInfo.h"
18 #include "clang/Sema/Lookup.h"
19 #include "clang/Sema/Scope.h"
20 #include "clang/Sema/ScopeInfo.h"
22 #include "clang/Sema/SemaLambda.h"
23 #include "llvm/ADT/STLExtras.h"
24 using namespace clang;
25 using namespace sema;
26 
27 /// Examines the FunctionScopeInfo stack to determine the nearest
28 /// enclosing lambda (to the current lambda) that is 'capture-ready' for
29 /// the variable referenced in the current lambda (i.e. \p VarToCapture).
30 /// If successful, returns the index into Sema's FunctionScopeInfo stack
31 /// of the capture-ready lambda's LambdaScopeInfo.
32 ///
33 /// Climbs down the stack of lambdas (deepest nested lambda - i.e. current
34 /// lambda - is on top) to determine the index of the nearest enclosing/outer
35 /// lambda that is ready to capture the \p VarToCapture being referenced in
36 /// the current lambda.
37 /// As we climb down the stack, we want the index of the first such lambda -
38 /// that is the lambda with the highest index that is 'capture-ready'.
39 ///
40 /// A lambda 'L' is capture-ready for 'V' (var or this) if:
41 /// - its enclosing context is non-dependent
42 /// - and if the chain of lambdas between L and the lambda in which
43 /// V is potentially used (i.e. the lambda at the top of the scope info
44 /// stack), can all capture or have already captured V.
45 /// If \p VarToCapture is 'null' then we are trying to capture 'this'.
46 ///
47 /// Note that a lambda that is deemed 'capture-ready' still needs to be checked
48 /// for whether it is 'capture-capable' (see
49 /// getStackIndexOfNearestEnclosingCaptureCapableLambda), before it can truly
50 /// capture.
51 ///
52 /// \param FunctionScopes - Sema's stack of nested FunctionScopeInfo's (which a
53 /// LambdaScopeInfo inherits from). The current/deepest/innermost lambda
54 /// is at the top of the stack and has the highest index.
55 /// \param VarToCapture - the variable to capture. If NULL, capture 'this'.
56 ///
57 /// \returns An Optional<unsigned> Index that if evaluates to 'true' contains
58 /// the index (into Sema's FunctionScopeInfo stack) of the innermost lambda
59 /// which is capture-ready. If the return value evaluates to 'false' then
60 /// no lambda is capture-ready for \p VarToCapture.
61 
62 static inline Optional<unsigned>
65  VarDecl *VarToCapture) {
66  // Label failure to capture.
67  const Optional<unsigned> NoLambdaIsCaptureReady;
68 
69  // Ignore all inner captured regions.
70  unsigned CurScopeIndex = FunctionScopes.size() - 1;
71  while (CurScopeIndex > 0 && isa<clang::sema::CapturedRegionScopeInfo>(
72  FunctionScopes[CurScopeIndex]))
73  --CurScopeIndex;
74  assert(
75  isa<clang::sema::LambdaScopeInfo>(FunctionScopes[CurScopeIndex]) &&
76  "The function on the top of sema's function-info stack must be a lambda");
77 
78  // If VarToCapture is null, we are attempting to capture 'this'.
79  const bool IsCapturingThis = !VarToCapture;
80  const bool IsCapturingVariable = !IsCapturingThis;
81 
82  // Start with the current lambda at the top of the stack (highest index).
83  DeclContext *EnclosingDC =
84  cast<sema::LambdaScopeInfo>(FunctionScopes[CurScopeIndex])->CallOperator;
85 
86  do {
87  const clang::sema::LambdaScopeInfo *LSI =
88  cast<sema::LambdaScopeInfo>(FunctionScopes[CurScopeIndex]);
89  // IF we have climbed down to an intervening enclosing lambda that contains
90  // the variable declaration - it obviously can/must not capture the
91  // variable.
92  // Since its enclosing DC is dependent, all the lambdas between it and the
93  // innermost nested lambda are dependent (otherwise we wouldn't have
94  // arrived here) - so we don't yet have a lambda that can capture the
95  // variable.
96  if (IsCapturingVariable &&
97  VarToCapture->getDeclContext()->Equals(EnclosingDC))
98  return NoLambdaIsCaptureReady;
99 
100  // For an enclosing lambda to be capture ready for an entity, all
101  // intervening lambda's have to be able to capture that entity. If even
102  // one of the intervening lambda's is not capable of capturing the entity
103  // then no enclosing lambda can ever capture that entity.
104  // For e.g.
105  // const int x = 10;
106  // [=](auto a) { #1
107  // [](auto b) { #2 <-- an intervening lambda that can never capture 'x'
108  // [=](auto c) { #3
109  // f(x, c); <-- can not lead to x's speculative capture by #1 or #2
110  // }; }; };
111  // If they do not have a default implicit capture, check to see
112  // if the entity has already been explicitly captured.
113  // If even a single dependent enclosing lambda lacks the capability
114  // to ever capture this variable, there is no further enclosing
115  // non-dependent lambda that can capture this variable.
117  if (IsCapturingVariable && !LSI->isCaptured(VarToCapture))
118  return NoLambdaIsCaptureReady;
119  if (IsCapturingThis && !LSI->isCXXThisCaptured())
120  return NoLambdaIsCaptureReady;
121  }
122  EnclosingDC = getLambdaAwareParentOfDeclContext(EnclosingDC);
123 
124  assert(CurScopeIndex);
125  --CurScopeIndex;
126  } while (!EnclosingDC->isTranslationUnit() &&
127  EnclosingDC->isDependentContext() &&
128  isLambdaCallOperator(EnclosingDC));
129 
130  assert(CurScopeIndex < (FunctionScopes.size() - 1));
131  // If the enclosingDC is not dependent, then the immediately nested lambda
132  // (one index above) is capture-ready.
133  if (!EnclosingDC->isDependentContext())
134  return CurScopeIndex + 1;
135  return NoLambdaIsCaptureReady;
136 }
137 
138 /// Examines the FunctionScopeInfo stack to determine the nearest
139 /// enclosing lambda (to the current lambda) that is 'capture-capable' for
140 /// the variable referenced in the current lambda (i.e. \p VarToCapture).
141 /// If successful, returns the index into Sema's FunctionScopeInfo stack
142 /// of the capture-capable lambda's LambdaScopeInfo.
143 ///
144 /// Given the current stack of lambdas being processed by Sema and
145 /// the variable of interest, to identify the nearest enclosing lambda (to the
146 /// current lambda at the top of the stack) that can truly capture
147 /// a variable, it has to have the following two properties:
148 /// a) 'capture-ready' - be the innermost lambda that is 'capture-ready':
149 /// - climb down the stack (i.e. starting from the innermost and examining
150 /// each outer lambda step by step) checking if each enclosing
151 /// lambda can either implicitly or explicitly capture the variable.
152 /// Record the first such lambda that is enclosed in a non-dependent
153 /// context. If no such lambda currently exists return failure.
154 /// b) 'capture-capable' - make sure the 'capture-ready' lambda can truly
155 /// capture the variable by checking all its enclosing lambdas:
156 /// - check if all outer lambdas enclosing the 'capture-ready' lambda
157 /// identified above in 'a' can also capture the variable (this is done
158 /// via tryCaptureVariable for variables and CheckCXXThisCapture for
159 /// 'this' by passing in the index of the Lambda identified in step 'a')
160 ///
161 /// \param FunctionScopes - Sema's stack of nested FunctionScopeInfo's (which a
162 /// LambdaScopeInfo inherits from). The current/deepest/innermost lambda
163 /// is at the top of the stack.
164 ///
165 /// \param VarToCapture - the variable to capture. If NULL, capture 'this'.
166 ///
167 ///
168 /// \returns An Optional<unsigned> Index that if evaluates to 'true' contains
169 /// the index (into Sema's FunctionScopeInfo stack) of the innermost lambda
170 /// which is capture-capable. If the return value evaluates to 'false' then
171 /// no lambda is capture-capable for \p VarToCapture.
172 
175  VarDecl *VarToCapture, Sema &S) {
176 
177  const Optional<unsigned> NoLambdaIsCaptureCapable;
178 
179  const Optional<unsigned> OptionalStackIndex =
181  VarToCapture);
182  if (!OptionalStackIndex)
183  return NoLambdaIsCaptureCapable;
184 
185  const unsigned IndexOfCaptureReadyLambda = *OptionalStackIndex;
186  assert(((IndexOfCaptureReadyLambda != (FunctionScopes.size() - 1)) ||
187  S.getCurGenericLambda()) &&
188  "The capture ready lambda for a potential capture can only be the "
189  "current lambda if it is a generic lambda");
190 
191  const sema::LambdaScopeInfo *const CaptureReadyLambdaLSI =
192  cast<sema::LambdaScopeInfo>(FunctionScopes[IndexOfCaptureReadyLambda]);
193 
194  // If VarToCapture is null, we are attempting to capture 'this'
195  const bool IsCapturingThis = !VarToCapture;
196  const bool IsCapturingVariable = !IsCapturingThis;
197 
198  if (IsCapturingVariable) {
199  // Check if the capture-ready lambda can truly capture the variable, by
200  // checking whether all enclosing lambdas of the capture-ready lambda allow
201  // the capture - i.e. make sure it is capture-capable.
202  QualType CaptureType, DeclRefType;
203  const bool CanCaptureVariable =
204  !S.tryCaptureVariable(VarToCapture,
205  /*ExprVarIsUsedInLoc*/ SourceLocation(),
207  /*EllipsisLoc*/ SourceLocation(),
208  /*BuildAndDiagnose*/ false, CaptureType,
209  DeclRefType, &IndexOfCaptureReadyLambda);
210  if (!CanCaptureVariable)
211  return NoLambdaIsCaptureCapable;
212  } else {
213  // Check if the capture-ready lambda can truly capture 'this' by checking
214  // whether all enclosing lambdas of the capture-ready lambda can capture
215  // 'this'.
216  const bool CanCaptureThis =
218  CaptureReadyLambdaLSI->PotentialThisCaptureLocation,
219  /*Explicit*/ false, /*BuildAndDiagnose*/ false,
220  &IndexOfCaptureReadyLambda);
221  if (!CanCaptureThis)
222  return NoLambdaIsCaptureCapable;
223  }
224  return IndexOfCaptureReadyLambda;
225 }
226 
227 static inline TemplateParameterList *
229  if (!LSI->GLTemplateParameterList && !LSI->TemplateParams.empty()) {
231  SemaRef.Context,
232  /*Template kw loc*/ SourceLocation(),
233  /*L angle loc*/ LSI->ExplicitTemplateParamsRange.getBegin(),
234  LSI->TemplateParams,
235  /*R angle loc*/LSI->ExplicitTemplateParamsRange.getEnd(),
236  LSI->RequiresClause.get());
237  }
238  return LSI->GLTemplateParameterList;
239 }
240 
243  unsigned LambdaDependencyKind,
244  LambdaCaptureDefault CaptureDefault) {
245  DeclContext *DC = CurContext;
246  while (!(DC->isFunctionOrMethod() || DC->isRecord() || DC->isFileContext()))
247  DC = DC->getParent();
248  bool IsGenericLambda = getGenericLambdaTemplateParameterList(getCurLambda(),
249  *this);
250  // Start constructing the lambda class.
252  Context, DC, Info, IntroducerRange.getBegin(), LambdaDependencyKind,
253  IsGenericLambda, CaptureDefault);
254  DC->addDecl(Class);
255 
256  return Class;
257 }
258 
259 /// Determine whether the given context is or is enclosed in an inline
260 /// function.
261 static bool isInInlineFunction(const DeclContext *DC) {
262  while (!DC->isFileContext()) {
263  if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(DC))
264  if (FD->isInlined())
265  return true;
266 
267  DC = DC->getLexicalParent();
268  }
269 
270  return false;
271 }
272 
273 std::tuple<MangleNumberingContext *, Decl *>
275  // Compute the context for allocating mangling numbers in the current
276  // expression, if the ABI requires them.
277  Decl *ManglingContextDecl = ExprEvalContexts.back().ManglingContextDecl;
278 
279  enum ContextKind {
280  Normal,
281  DefaultArgument,
282  DataMember,
283  StaticDataMember,
284  InlineVariable,
285  VariableTemplate,
286  Concept
287  } Kind = Normal;
288 
289  // Default arguments of member function parameters that appear in a class
290  // definition, as well as the initializers of data members, receive special
291  // treatment. Identify them.
292  if (ManglingContextDecl) {
293  if (ParmVarDecl *Param = dyn_cast<ParmVarDecl>(ManglingContextDecl)) {
294  if (const DeclContext *LexicalDC
295  = Param->getDeclContext()->getLexicalParent())
296  if (LexicalDC->isRecord())
297  Kind = DefaultArgument;
298  } else if (VarDecl *Var = dyn_cast<VarDecl>(ManglingContextDecl)) {
299  if (Var->getDeclContext()->isRecord())
300  Kind = StaticDataMember;
301  else if (Var->getMostRecentDecl()->isInline())
302  Kind = InlineVariable;
303  else if (Var->getDescribedVarTemplate())
304  Kind = VariableTemplate;
305  else if (auto *VTS = dyn_cast<VarTemplateSpecializationDecl>(Var)) {
306  if (!VTS->isExplicitSpecialization())
307  Kind = VariableTemplate;
308  }
309  } else if (isa<FieldDecl>(ManglingContextDecl)) {
310  Kind = DataMember;
311  } else if (isa<ImplicitConceptSpecializationDecl>(ManglingContextDecl)) {
312  Kind = Concept;
313  }
314  }
315 
316  // Itanium ABI [5.1.7]:
317  // In the following contexts [...] the one-definition rule requires closure
318  // types in different translation units to "correspond":
319  bool IsInNonspecializedTemplate =
320  inTemplateInstantiation() || CurContext->isDependentContext();
321  switch (Kind) {
322  case Normal: {
323  // -- the bodies of non-exported nonspecialized template functions
324  // -- the bodies of inline functions
325  if ((IsInNonspecializedTemplate &&
326  !(ManglingContextDecl && isa<ParmVarDecl>(ManglingContextDecl))) ||
327  isInInlineFunction(CurContext)) {
328  while (auto *CD = dyn_cast<CapturedDecl>(DC))
329  DC = CD->getParent();
330  return std::make_tuple(&Context.getManglingNumberContext(DC), nullptr);
331  }
332 
333  return std::make_tuple(nullptr, nullptr);
334  }
335 
336  case Concept:
337  // Concept definitions aren't code generated and thus aren't mangled,
338  // however the ManglingContextDecl is important for the purposes of
339  // re-forming the template argument list of the lambda for constraint
340  // evaluation.
341  case StaticDataMember:
342  // -- the initializers of nonspecialized static members of template classes
343  if (!IsInNonspecializedTemplate)
344  return std::make_tuple(nullptr, ManglingContextDecl);
345  // Fall through to get the current context.
346  [[fallthrough]];
347 
348  case DataMember:
349  // -- the in-class initializers of class members
350  case DefaultArgument:
351  // -- default arguments appearing in class definitions
352  case InlineVariable:
353  // -- the initializers of inline variables
354  case VariableTemplate:
355  // -- the initializers of templated variables
356  return std::make_tuple(
358  ManglingContextDecl),
359  ManglingContextDecl);
360  }
361 
362  llvm_unreachable("unexpected context");
363 }
364 
366  CXXRecordDecl *Class, SourceRange IntroducerRange,
367  TypeSourceInfo *MethodTypeInfo, SourceLocation EndLoc,
368  ArrayRef<ParmVarDecl *> Params, ConstexprSpecKind ConstexprKind,
369  StorageClass SC, Expr *TrailingRequiresClause) {
370  QualType MethodType = MethodTypeInfo->getType();
371  TemplateParameterList *TemplateParams =
372  getGenericLambdaTemplateParameterList(getCurLambda(), *this);
373  // If a lambda appears in a dependent context or is a generic lambda (has
374  // template parameters) and has an 'auto' return type, deduce it to a
375  // dependent type.
376  if (Class->isDependentContext() || TemplateParams) {
377  const FunctionProtoType *FPT = MethodType->castAs<FunctionProtoType>();
378  QualType Result = FPT->getReturnType();
379  if (Result->isUndeducedType()) {
380  Result = SubstAutoTypeDependent(Result);
381  MethodType = Context.getFunctionType(Result, FPT->getParamTypes(),
382  FPT->getExtProtoInfo());
383  }
384  }
385 
386  // C++11 [expr.prim.lambda]p5:
387  // The closure type for a lambda-expression has a public inline function
388  // call operator (13.5.4) whose parameters and return type are described by
389  // the lambda-expression's parameter-declaration-clause and
390  // trailing-return-type respectively.
391  DeclarationName MethodName
392  = Context.DeclarationNames.getCXXOperatorName(OO_Call);
393  DeclarationNameLoc MethodNameLoc =
396  Context, Class, EndLoc,
397  DeclarationNameInfo(MethodName, IntroducerRange.getBegin(),
398  MethodNameLoc),
399  MethodType, MethodTypeInfo, SC, getCurFPFeatures().isFPConstrained(),
400  /*isInline=*/true, ConstexprKind, EndLoc, TrailingRequiresClause);
401  Method->setAccess(AS_public);
402  if (!TemplateParams)
403  Class->addDecl(Method);
404 
405  // Temporarily set the lexical declaration context to the current
406  // context, so that the Scope stack matches the lexical nesting.
407  Method->setLexicalDeclContext(CurContext);
408  // Create a function template if we have a template parameter list
409  FunctionTemplateDecl *const TemplateMethod = TemplateParams ?
410  FunctionTemplateDecl::Create(Context, Class,
411  Method->getLocation(), MethodName,
412  TemplateParams,
413  Method) : nullptr;
414  if (TemplateMethod) {
415  TemplateMethod->setAccess(AS_public);
416  Method->setDescribedFunctionTemplate(TemplateMethod);
417  Class->addDecl(TemplateMethod);
418  TemplateMethod->setLexicalDeclContext(CurContext);
419  }
420 
421  // Add parameters.
422  if (!Params.empty()) {
423  Method->setParams(Params);
424  CheckParmsForFunctionDef(Params,
425  /*CheckParameterNames=*/false);
426 
427  for (auto *P : Method->parameters())
428  P->setOwningFunction(Method);
429  }
430 
431  return Method;
432 }
433 
435  CXXRecordDecl *Class, CXXMethodDecl *Method,
436  Optional<std::tuple<bool, unsigned, unsigned, Decl *>> Mangling) {
437  if (Mangling) {
438  bool HasKnownInternalLinkage;
439  unsigned ManglingNumber, DeviceManglingNumber;
440  Decl *ManglingContextDecl;
441  std::tie(HasKnownInternalLinkage, ManglingNumber, DeviceManglingNumber,
442  ManglingContextDecl) = *Mangling;
443  Class->setLambdaMangling(ManglingNumber, ManglingContextDecl,
444  HasKnownInternalLinkage);
445  Class->setDeviceLambdaManglingNumber(DeviceManglingNumber);
446  return;
447  }
448 
449  auto getMangleNumberingContext =
450  [this](CXXRecordDecl *Class,
451  Decl *ManglingContextDecl) -> MangleNumberingContext * {
452  // Get mangle numbering context if there's any extra decl context.
453  if (ManglingContextDecl)
454  return &Context.getManglingNumberContext(
455  ASTContext::NeedExtraManglingDecl, ManglingContextDecl);
456  // Otherwise, from that lambda's decl context.
457  auto DC = Class->getDeclContext();
458  while (auto *CD = dyn_cast<CapturedDecl>(DC))
459  DC = CD->getParent();
460  return &Context.getManglingNumberContext(DC);
461  };
462 
464  Decl *ManglingContextDecl;
465  std::tie(MCtx, ManglingContextDecl) =
466  getCurrentMangleNumberContext(Class->getDeclContext());
467  bool HasKnownInternalLinkage = false;
468  if (!MCtx && (getLangOpts().CUDA || getLangOpts().SYCLIsDevice ||
469  getLangOpts().SYCLIsHost)) {
470  // Force lambda numbering in CUDA/HIP as we need to name lambdas following
471  // ODR. Both device- and host-compilation need to have a consistent naming
472  // on kernel functions. As lambdas are potential part of these `__global__`
473  // function names, they needs numbering following ODR.
474  // Also force for SYCL, since we need this for the
475  // __builtin_sycl_unique_stable_name implementation, which depends on lambda
476  // mangling.
477  MCtx = getMangleNumberingContext(Class, ManglingContextDecl);
478  assert(MCtx && "Retrieving mangle numbering context failed!");
479  HasKnownInternalLinkage = true;
480  }
481  if (MCtx) {
482  unsigned ManglingNumber = MCtx->getManglingNumber(Method);
483  Class->setLambdaMangling(ManglingNumber, ManglingContextDecl,
484  HasKnownInternalLinkage);
485  Class->setDeviceLambdaManglingNumber(MCtx->getDeviceManglingNumber(Method));
486  }
487 }
488 
490  CXXMethodDecl *CallOperator,
491  SourceRange IntroducerRange,
492  LambdaCaptureDefault CaptureDefault,
493  SourceLocation CaptureDefaultLoc,
494  bool ExplicitParams,
495  bool ExplicitResultType,
496  bool Mutable) {
497  LSI->CallOperator = CallOperator;
498  CXXRecordDecl *LambdaClass = CallOperator->getParent();
499  LSI->Lambda = LambdaClass;
500  if (CaptureDefault == LCD_ByCopy)
502  else if (CaptureDefault == LCD_ByRef)
504  LSI->CaptureDefaultLoc = CaptureDefaultLoc;
505  LSI->IntroducerRange = IntroducerRange;
506  LSI->ExplicitParams = ExplicitParams;
507  LSI->Mutable = Mutable;
508 
509  if (ExplicitResultType) {
510  LSI->ReturnType = CallOperator->getReturnType();
511 
512  if (!LSI->ReturnType->isDependentType() &&
513  !LSI->ReturnType->isVoidType()) {
514  if (RequireCompleteType(CallOperator->getBeginLoc(), LSI->ReturnType,
515  diag::err_lambda_incomplete_result)) {
516  // Do nothing.
517  }
518  }
519  } else {
520  LSI->HasImplicitReturnType = true;
521  }
522 }
523 
526 }
527 
529  ArrayRef<NamedDecl *> TParams,
530  SourceLocation RAngleLoc,
531  ExprResult RequiresClause) {
532  LambdaScopeInfo *LSI = getCurLambda();
533  assert(LSI && "Expected a lambda scope");
534  assert(LSI->NumExplicitTemplateParams == 0 &&
535  "Already acted on explicit template parameters");
536  assert(LSI->TemplateParams.empty() &&
537  "Explicit template parameters should come "
538  "before invented (auto) ones");
539  assert(!TParams.empty() &&
540  "No template parameters to act on");
541  LSI->TemplateParams.append(TParams.begin(), TParams.end());
542  LSI->NumExplicitTemplateParams = TParams.size();
543  LSI->ExplicitTemplateParamsRange = {LAngleLoc, RAngleLoc};
544  LSI->RequiresClause = RequiresClause;
545 }
546 
549  CXXMethodDecl *CallOperator, Scope *CurScope) {
550  // Introduce our parameters into the function scope
551  for (unsigned p = 0, NumParams = CallOperator->getNumParams();
552  p < NumParams; ++p) {
553  ParmVarDecl *Param = CallOperator->getParamDecl(p);
554 
555  // If this has an identifier, add it to the scope stack.
556  if (CurScope && Param->getIdentifier()) {
557  bool Error = false;
558  // Resolution of CWG 2211 in C++17 renders shadowing ill-formed, but we
559  // retroactively apply it.
560  for (const auto &Capture : Captures) {
561  if (Capture.Id == Param->getIdentifier()) {
562  Error = true;
563  Diag(Param->getLocation(), diag::err_parameter_shadow_capture);
564  Diag(Capture.Loc, diag::note_var_explicitly_captured_here)
565  << Capture.Id << true;
566  }
567  }
568  if (!Error)
569  CheckShadow(CurScope, Param);
570 
571  PushOnScopeChains(Param, CurScope);
572  }
573  }
574 }
575 
576 /// If this expression is an enumerator-like expression of some type
577 /// T, return the type T; otherwise, return null.
578 ///
579 /// Pointer comparisons on the result here should always work because
580 /// it's derived from either the parent of an EnumConstantDecl
581 /// (i.e. the definition) or the declaration returned by
582 /// EnumType::getDecl() (i.e. the definition).
584  // An expression is an enumerator-like expression of type T if,
585  // ignoring parens and parens-like expressions:
586  E = E->IgnoreParens();
587 
588  // - it is an enumerator whose enum type is T or
589  if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E)) {
590  if (EnumConstantDecl *D
591  = dyn_cast<EnumConstantDecl>(DRE->getDecl())) {
592  return cast<EnumDecl>(D->getDeclContext());
593  }
594  return nullptr;
595  }
596 
597  // - it is a comma expression whose RHS is an enumerator-like
598  // expression of type T or
599  if (BinaryOperator *BO = dyn_cast<BinaryOperator>(E)) {
600  if (BO->getOpcode() == BO_Comma)
601  return findEnumForBlockReturn(BO->getRHS());
602  return nullptr;
603  }
604 
605  // - it is a statement-expression whose value expression is an
606  // enumerator-like expression of type T or
607  if (StmtExpr *SE = dyn_cast<StmtExpr>(E)) {
608  if (Expr *last = dyn_cast_or_null<Expr>(SE->getSubStmt()->body_back()))
609  return findEnumForBlockReturn(last);
610  return nullptr;
611  }
612 
613  // - it is a ternary conditional operator (not the GNU ?:
614  // extension) whose second and third operands are
615  // enumerator-like expressions of type T or
616  if (ConditionalOperator *CO = dyn_cast<ConditionalOperator>(E)) {
617  if (EnumDecl *ED = findEnumForBlockReturn(CO->getTrueExpr()))
618  if (ED == findEnumForBlockReturn(CO->getFalseExpr()))
619  return ED;
620  return nullptr;
621  }
622 
623  // (implicitly:)
624  // - it is an implicit integral conversion applied to an
625  // enumerator-like expression of type T or
626  if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) {
627  // We can sometimes see integral conversions in valid
628  // enumerator-like expressions.
629  if (ICE->getCastKind() == CK_IntegralCast)
630  return findEnumForBlockReturn(ICE->getSubExpr());
631 
632  // Otherwise, just rely on the type.
633  }
634 
635  // - it is an expression of that formal enum type.
636  if (const EnumType *ET = E->getType()->getAs<EnumType>()) {
637  return ET->getDecl();
638  }
639 
640  // Otherwise, nope.
641  return nullptr;
642 }
643 
644 /// Attempt to find a type T for which the returned expression of the
645 /// given statement is an enumerator-like expression of that type.
647  if (Expr *retValue = ret->getRetValue())
648  return findEnumForBlockReturn(retValue);
649  return nullptr;
650 }
651 
652 /// Attempt to find a common type T for which all of the returned
653 /// expressions in a block are enumerator-like expressions of that
654 /// type.
656  ArrayRef<ReturnStmt*>::iterator i = returns.begin(), e = returns.end();
657 
658  // Try to find one for the first return.
660  if (!ED) return nullptr;
661 
662  // Check that the rest of the returns have the same enum.
663  for (++i; i != e; ++i) {
664  if (findEnumForBlockReturn(*i) != ED)
665  return nullptr;
666  }
667 
668  // Never infer an anonymous enum type.
669  if (!ED->hasNameForLinkage()) return nullptr;
670 
671  return ED;
672 }
673 
674 /// Adjust the given return statements so that they formally return
675 /// the given type. It should require, at most, an IntegralCast.
677  QualType returnType) {
679  i = returns.begin(), e = returns.end(); i != e; ++i) {
680  ReturnStmt *ret = *i;
681  Expr *retValue = ret->getRetValue();
682  if (S.Context.hasSameType(retValue->getType(), returnType))
683  continue;
684 
685  // Right now we only support integral fixup casts.
686  assert(returnType->isIntegralOrUnscopedEnumerationType());
687  assert(retValue->getType()->isIntegralOrUnscopedEnumerationType());
688 
689  ExprWithCleanups *cleanups = dyn_cast<ExprWithCleanups>(retValue);
690 
691  Expr *E = (cleanups ? cleanups->getSubExpr() : retValue);
692  E = ImplicitCastExpr::Create(S.Context, returnType, CK_IntegralCast, E,
693  /*base path*/ nullptr, VK_PRValue,
695  if (cleanups) {
696  cleanups->setSubExpr(E);
697  } else {
698  ret->setRetValue(E);
699  }
700  }
701 }
702 
704  assert(CSI.HasImplicitReturnType);
705  // If it was ever a placeholder, it had to been deduced to DependentTy.
706  assert(CSI.ReturnType.isNull() || !CSI.ReturnType->isUndeducedType());
707  assert((!isa<LambdaScopeInfo>(CSI) || !getLangOpts().CPlusPlus14) &&
708  "lambda expressions use auto deduction in C++14 onwards");
709 
710  // C++ core issue 975:
711  // If a lambda-expression does not include a trailing-return-type,
712  // it is as if the trailing-return-type denotes the following type:
713  // - if there are no return statements in the compound-statement,
714  // or all return statements return either an expression of type
715  // void or no expression or braced-init-list, the type void;
716  // - otherwise, if all return statements return an expression
717  // and the types of the returned expressions after
718  // lvalue-to-rvalue conversion (4.1 [conv.lval]),
719  // array-to-pointer conversion (4.2 [conv.array]), and
720  // function-to-pointer conversion (4.3 [conv.func]) are the
721  // same, that common type;
722  // - otherwise, the program is ill-formed.
723  //
724  // C++ core issue 1048 additionally removes top-level cv-qualifiers
725  // from the types of returned expressions to match the C++14 auto
726  // deduction rules.
727  //
728  // In addition, in blocks in non-C++ modes, if all of the return
729  // statements are enumerator-like expressions of some type T, where
730  // T has a name for linkage, then we infer the return type of the
731  // block to be that type.
732 
733  // First case: no return statements, implicit void return type.
734  ASTContext &Ctx = getASTContext();
735  if (CSI.Returns.empty()) {
736  // It's possible there were simply no /valid/ return statements.
737  // In this case, the first one we found may have at least given us a type.
738  if (CSI.ReturnType.isNull())
739  CSI.ReturnType = Ctx.VoidTy;
740  return;
741  }
742 
743  // Second case: at least one return statement has dependent type.
744  // Delay type checking until instantiation.
745  assert(!CSI.ReturnType.isNull() && "We should have a tentative return type.");
746  if (CSI.ReturnType->isDependentType())
747  return;
748 
749  // Try to apply the enum-fuzz rule.
750  if (!getLangOpts().CPlusPlus) {
751  assert(isa<BlockScopeInfo>(CSI));
753  if (ED) {
754  CSI.ReturnType = Context.getTypeDeclType(ED);
756  return;
757  }
758  }
759 
760  // Third case: only one return statement. Don't bother doing extra work!
761  if (CSI.Returns.size() == 1)
762  return;
763 
764  // General case: many return statements.
765  // Check that they all have compatible return types.
766 
767  // We require the return types to strictly match here.
768  // Note that we've already done the required promotions as part of
769  // processing the return statement.
770  for (const ReturnStmt *RS : CSI.Returns) {
771  const Expr *RetE = RS->getRetValue();
772 
773  QualType ReturnType =
774  (RetE ? RetE->getType() : Context.VoidTy).getUnqualifiedType();
775  if (Context.getCanonicalFunctionResultType(ReturnType) ==
777  // Use the return type with the strictest possible nullability annotation.
778  auto RetTyNullability = ReturnType->getNullability(Ctx);
779  auto BlockNullability = CSI.ReturnType->getNullability(Ctx);
780  if (BlockNullability &&
781  (!RetTyNullability ||
782  hasWeakerNullability(*RetTyNullability, *BlockNullability)))
783  CSI.ReturnType = ReturnType;
784  continue;
785  }
786 
787  // FIXME: This is a poor diagnostic for ReturnStmts without expressions.
788  // TODO: It's possible that the *first* return is the divergent one.
789  Diag(RS->getBeginLoc(),
790  diag::err_typecheck_missing_return_type_incompatible)
791  << ReturnType << CSI.ReturnType << isa<LambdaScopeInfo>(CSI);
792  // Continue iterating so that we keep emitting diagnostics.
793  }
794 }
795 
797  SourceLocation Loc, bool ByRef, SourceLocation EllipsisLoc,
798  Optional<unsigned> NumExpansions, IdentifierInfo *Id, bool IsDirectInit,
799  Expr *&Init) {
800  // Create an 'auto' or 'auto&' TypeSourceInfo that we can use to
801  // deduce against.
802  QualType DeductType = Context.getAutoDeductType();
803  TypeLocBuilder TLB;
804  AutoTypeLoc TL = TLB.push<AutoTypeLoc>(DeductType);
805  TL.setNameLoc(Loc);
806  if (ByRef) {
807  DeductType = BuildReferenceType(DeductType, true, Loc, Id);
808  assert(!DeductType.isNull() && "can't build reference to auto");
809  TLB.push<ReferenceTypeLoc>(DeductType).setSigilLoc(Loc);
810  }
811  if (EllipsisLoc.isValid()) {
812  if (Init->containsUnexpandedParameterPack()) {
813  Diag(EllipsisLoc, getLangOpts().CPlusPlus20
814  ? diag::warn_cxx17_compat_init_capture_pack
815  : diag::ext_init_capture_pack);
816  DeductType = Context.getPackExpansionType(DeductType, NumExpansions,
817  /*ExpectPackInType=*/false);
818  TLB.push<PackExpansionTypeLoc>(DeductType).setEllipsisLoc(EllipsisLoc);
819  } else {
820  // Just ignore the ellipsis for now and form a non-pack variable. We'll
821  // diagnose this later when we try to capture it.
822  }
823  }
824  TypeSourceInfo *TSI = TLB.getTypeSourceInfo(Context, DeductType);
825 
826  // Deduce the type of the init capture.
827  QualType DeducedType = deduceVarTypeFromInitializer(
828  /*VarDecl*/nullptr, DeclarationName(Id), DeductType, TSI,
829  SourceRange(Loc, Loc), IsDirectInit, Init);
830  if (DeducedType.isNull())
831  return QualType();
832 
833  // Are we a non-list direct initialization?
834  ParenListExpr *CXXDirectInit = dyn_cast<ParenListExpr>(Init);
835 
836  // Perform initialization analysis and ensure any implicit conversions
837  // (such as lvalue-to-rvalue) are enforced.
838  InitializedEntity Entity =
841  IsDirectInit
842  ? (CXXDirectInit ? InitializationKind::CreateDirect(
843  Loc, Init->getBeginLoc(), Init->getEndLoc())
845  : InitializationKind::CreateCopy(Loc, Init->getBeginLoc());
846 
847  MultiExprArg Args = Init;
848  if (CXXDirectInit)
849  Args =
850  MultiExprArg(CXXDirectInit->getExprs(), CXXDirectInit->getNumExprs());
851  QualType DclT;
852  InitializationSequence InitSeq(*this, Entity, Kind, Args);
853  ExprResult Result = InitSeq.Perform(*this, Entity, Kind, Args, &DclT);
854 
855  if (Result.isInvalid())
856  return QualType();
857 
858  Init = Result.getAs<Expr>();
859  return DeducedType;
860 }
861 
863  QualType InitCaptureType,
864  SourceLocation EllipsisLoc,
866  unsigned InitStyle, Expr *Init) {
867  // FIXME: Retain the TypeSourceInfo from buildLambdaInitCaptureInitialization
868  // rather than reconstructing it here.
869  TypeSourceInfo *TSI = Context.getTrivialTypeSourceInfo(InitCaptureType, Loc);
870  if (auto PETL = TSI->getTypeLoc().getAs<PackExpansionTypeLoc>())
871  PETL.setEllipsisLoc(EllipsisLoc);
872 
873  // Create a dummy variable representing the init-capture. This is not actually
874  // used as a variable, and only exists as a way to name and refer to the
875  // init-capture.
876  // FIXME: Pass in separate source locations for '&' and identifier.
877  VarDecl *NewVD = VarDecl::Create(Context, CurContext, Loc,
878  Loc, Id, InitCaptureType, TSI, SC_Auto);
879  NewVD->setInitCapture(true);
880  NewVD->setReferenced(true);
881  // FIXME: Pass in a VarDecl::InitializationStyle.
882  NewVD->setInitStyle(static_cast<VarDecl::InitializationStyle>(InitStyle));
883  NewVD->markUsed(Context);
884  NewVD->setInit(Init);
885  if (NewVD->isParameterPack())
886  getCurLambda()->LocalPacks.push_back(NewVD);
887  return NewVD;
888 }
889 
891  assert(Var->isInitCapture() && "init capture flag should be set");
892  LSI->addCapture(Var, /*isBlock*/false, Var->getType()->isReferenceType(),
893  /*isNested*/false, Var->getLocation(), SourceLocation(),
894  Var->getType(), /*Invalid*/false);
895 }
896 
898  Declarator &ParamInfo,
899  Scope *CurScope) {
900  LambdaScopeInfo *const LSI = getCurLambda();
901  assert(LSI && "LambdaScopeInfo should be on stack!");
902 
903  // Determine if we're within a context where we know that the lambda will
904  // be dependent, because there are template parameters in scope.
905  CXXRecordDecl::LambdaDependencyKind LambdaDependencyKind =
907  if (LSI->NumExplicitTemplateParams > 0) {
908  auto *TemplateParamScope = CurScope->getTemplateParamParent();
909  assert(TemplateParamScope &&
910  "Lambda with explicit template param list should establish a "
911  "template param scope");
912  assert(TemplateParamScope->getParent());
913  if (TemplateParamScope->getParent()->getTemplateParamParent() != nullptr)
914  LambdaDependencyKind = CXXRecordDecl::LDK_AlwaysDependent;
915  } else if (CurScope->getTemplateParamParent() != nullptr) {
916  LambdaDependencyKind = CXXRecordDecl::LDK_AlwaysDependent;
917  }
918 
919  // Determine the signature of the call operator.
920  TypeSourceInfo *MethodTyInfo;
921  bool ExplicitParams = true;
922  bool ExplicitResultType = true;
923  bool ContainsUnexpandedParameterPack = false;
924  SourceLocation EndLoc;
926 
927  assert(
928  (ParamInfo.getDeclSpec().getStorageClassSpec() ==
931  "Unexpected storage specifier");
932  bool IsLambdaStatic =
934 
935  if (ParamInfo.getNumTypeObjects() == 0) {
936  // C++11 [expr.prim.lambda]p4:
937  // If a lambda-expression does not include a lambda-declarator, it is as
938  // if the lambda-declarator were ().
940  /*IsVariadic=*/false, /*IsCXXMethod=*/true));
941  EPI.HasTrailingReturn = true;
942  EPI.TypeQuals.addConst();
943  LangAS AS = getDefaultCXXMethodAddrSpace();
944  if (AS != LangAS::Default)
945  EPI.TypeQuals.addAddressSpace(AS);
946 
947  // C++1y [expr.prim.lambda]:
948  // The lambda return type is 'auto', which is replaced by the
949  // trailing-return type if provided and/or deduced from 'return'
950  // statements
951  // We don't do this before C++1y, because we don't support deduced return
952  // types there.
953  QualType DefaultTypeForNoTrailingReturn =
954  getLangOpts().CPlusPlus14 ? Context.getAutoDeductType()
955  : Context.DependentTy;
956  QualType MethodTy =
957  Context.getFunctionType(DefaultTypeForNoTrailingReturn, None, EPI);
958  MethodTyInfo = Context.getTrivialTypeSourceInfo(MethodTy);
959  ExplicitParams = false;
960  ExplicitResultType = false;
961  EndLoc = Intro.Range.getEnd();
962  } else {
963  assert(ParamInfo.isFunctionDeclarator() &&
964  "lambda-declarator is a function");
966 
967  // C++11 [expr.prim.lambda]p5:
968  // This function call operator is declared const (9.3.1) if and only if
969  // the lambda-expression's parameter-declaration-clause is not followed
970  // by mutable. It is neither virtual nor declared volatile. [...]
971  if (!FTI.hasMutableQualifier() && !IsLambdaStatic) {
973  SourceLocation());
974  }
975 
976  MethodTyInfo = GetTypeForDeclarator(ParamInfo, CurScope);
977  assert(MethodTyInfo && "no type from lambda-declarator");
978  EndLoc = ParamInfo.getSourceRange().getEnd();
979 
980  ExplicitResultType = FTI.hasTrailingReturnType();
981 
982  if (ExplicitResultType && getLangOpts().HLSL) {
983  QualType RetTy = FTI.getTrailingReturnType().get();
984  if (!RetTy.isNull()) {
985  // HLSL does not support specifying an address space on a lambda return
986  // type.
987  LangAS AddressSpace = RetTy.getAddressSpace();
988  if (AddressSpace != LangAS::Default)
990  diag::err_return_value_with_address_space);
991  }
992  }
993 
994  if (FTIHasNonVoidParameters(FTI)) {
995  Params.reserve(FTI.NumParams);
996  for (unsigned i = 0, e = FTI.NumParams; i != e; ++i)
997  Params.push_back(cast<ParmVarDecl>(FTI.Params[i].Param));
998  }
999 
1000  // Check for unexpanded parameter packs in the method type.
1001  if (MethodTyInfo->getType()->containsUnexpandedParameterPack())
1002  DiagnoseUnexpandedParameterPack(Intro.Range.getBegin(), MethodTyInfo,
1003  UPPC_DeclarationType);
1004  }
1005 
1006  CXXRecordDecl *Class = createLambdaClosureType(
1007  Intro.Range, MethodTyInfo, LambdaDependencyKind, Intro.Default);
1008  CXXMethodDecl *Method =
1009  startLambdaDefinition(Class, Intro.Range, MethodTyInfo, EndLoc, Params,
1010  ParamInfo.getDeclSpec().getConstexprSpecifier(),
1011  IsLambdaStatic ? SC_Static : SC_None,
1012  ParamInfo.getTrailingRequiresClause());
1013  if (ExplicitParams)
1014  CheckCXXDefaultArguments(Method);
1015 
1016  // This represents the function body for the lambda function, check if we
1017  // have to apply optnone due to a pragma.
1018  AddRangeBasedOptnone(Method);
1019 
1020  // code_seg attribute on lambda apply to the method.
1021  if (Attr *A = getImplicitCodeSegOrSectionAttrForFunction(Method, /*IsDefinition=*/true))
1022  Method->addAttr(A);
1023 
1024  // Attributes on the lambda apply to the method.
1025  ProcessDeclAttributes(CurScope, Method, ParamInfo);
1026 
1027  // CUDA lambdas get implicit host and device attributes.
1028  if (getLangOpts().CUDA)
1029  CUDASetLambdaAttrs(Method);
1030 
1031  // OpenMP lambdas might get assumumption attributes.
1032  if (LangOpts.OpenMP)
1033  ActOnFinishedFunctionDefinitionInOpenMPAssumeScope(Method);
1034 
1035  // Number the lambda for linkage purposes if necessary.
1036  handleLambdaNumbering(Class, Method);
1037 
1038  // Introduce the function call operator as the current declaration context.
1039  PushDeclContext(CurScope, Method);
1040 
1041  // Build the lambda scope.
1042  buildLambdaScope(LSI, Method, Intro.Range, Intro.Default, Intro.DefaultLoc,
1043  ExplicitParams, ExplicitResultType, !Method->isConst());
1044 
1045  // C++11 [expr.prim.lambda]p9:
1046  // A lambda-expression whose smallest enclosing scope is a block scope is a
1047  // local lambda expression; any other lambda expression shall not have a
1048  // capture-default or simple-capture in its lambda-introducer.
1049  //
1050  // For simple-captures, this is covered by the check below that any named
1051  // entity is a variable that can be captured.
1052  //
1053  // For DR1632, we also allow a capture-default in any context where we can
1054  // odr-use 'this' (in particular, in a default initializer for a non-static
1055  // data member).
1056  if (Intro.Default != LCD_None && !Class->getParent()->isFunctionOrMethod() &&
1057  (getCurrentThisType().isNull() ||
1058  CheckCXXThisCapture(SourceLocation(), /*Explicit*/true,
1059  /*BuildAndDiagnose*/false)))
1060  Diag(Intro.DefaultLoc, diag::err_capture_default_non_local);
1061 
1062  // Distinct capture names, for diagnostics.
1063  llvm::SmallSet<IdentifierInfo*, 8> CaptureNames;
1064 
1065  // Handle explicit captures.
1066  SourceLocation PrevCaptureLoc
1067  = Intro.Default == LCD_None? Intro.Range.getBegin() : Intro.DefaultLoc;
1068  for (auto C = Intro.Captures.begin(), E = Intro.Captures.end(); C != E;
1069  PrevCaptureLoc = C->Loc, ++C) {
1070  if (C->Kind == LCK_This || C->Kind == LCK_StarThis) {
1071  if (C->Kind == LCK_StarThis)
1072  Diag(C->Loc, !getLangOpts().CPlusPlus17
1073  ? diag::ext_star_this_lambda_capture_cxx17
1074  : diag::warn_cxx14_compat_star_this_lambda_capture);
1075 
1076  // C++11 [expr.prim.lambda]p8:
1077  // An identifier or this shall not appear more than once in a
1078  // lambda-capture.
1079  if (LSI->isCXXThisCaptured()) {
1080  Diag(C->Loc, diag::err_capture_more_than_once)
1081  << "'this'" << SourceRange(LSI->getCXXThisCapture().getLocation())
1083  SourceRange(getLocForEndOfToken(PrevCaptureLoc), C->Loc));
1084  continue;
1085  }
1086 
1087  // C++2a [expr.prim.lambda]p8:
1088  // If a lambda-capture includes a capture-default that is =,
1089  // each simple-capture of that lambda-capture shall be of the form
1090  // "&identifier", "this", or "* this". [ Note: The form [&,this] is
1091  // redundant but accepted for compatibility with ISO C++14. --end note ]
1092  if (Intro.Default == LCD_ByCopy && C->Kind != LCK_StarThis)
1093  Diag(C->Loc, !getLangOpts().CPlusPlus20
1094  ? diag::ext_equals_this_lambda_capture_cxx20
1095  : diag::warn_cxx17_compat_equals_this_lambda_capture);
1096 
1097  // C++11 [expr.prim.lambda]p12:
1098  // If this is captured by a local lambda expression, its nearest
1099  // enclosing function shall be a non-static member function.
1100  QualType ThisCaptureType = getCurrentThisType();
1101  if (ThisCaptureType.isNull()) {
1102  Diag(C->Loc, diag::err_this_capture) << true;
1103  continue;
1104  }
1105 
1106  CheckCXXThisCapture(C->Loc, /*Explicit=*/true, /*BuildAndDiagnose*/ true,
1107  /*FunctionScopeIndexToStopAtPtr*/ nullptr,
1108  C->Kind == LCK_StarThis);
1109  if (!LSI->Captures.empty())
1110  LSI->ExplicitCaptureRanges[LSI->Captures.size() - 1] = C->ExplicitRange;
1111  continue;
1112  }
1113 
1114  assert(C->Id && "missing identifier for capture");
1115 
1116  if (C->Init.isInvalid())
1117  continue;
1118 
1119  ValueDecl *Var = nullptr;
1120  if (C->Init.isUsable()) {
1121  Diag(C->Loc, getLangOpts().CPlusPlus14
1122  ? diag::warn_cxx11_compat_init_capture
1123  : diag::ext_init_capture);
1124 
1125  // If the initializer expression is usable, but the InitCaptureType
1126  // is not, then an error has occurred - so ignore the capture for now.
1127  // for e.g., [n{0}] { }; <-- if no <initializer_list> is included.
1128  // FIXME: we should create the init capture variable and mark it invalid
1129  // in this case.
1130  if (C->InitCaptureType.get().isNull())
1131  continue;
1132 
1133  if (C->Init.get()->containsUnexpandedParameterPack() &&
1134  !C->InitCaptureType.get()->getAs<PackExpansionType>())
1135  DiagnoseUnexpandedParameterPack(C->Init.get(), UPPC_Initializer);
1136 
1137  unsigned InitStyle;
1138  switch (C->InitKind) {
1140  llvm_unreachable("not an init-capture?");
1142  InitStyle = VarDecl::CInit;
1143  break;
1145  InitStyle = VarDecl::CallInit;
1146  break;
1148  InitStyle = VarDecl::ListInit;
1149  break;
1150  }
1151  Var = createLambdaInitCaptureVarDecl(C->Loc, C->InitCaptureType.get(),
1152  C->EllipsisLoc, C->Id, InitStyle,
1153  C->Init.get());
1154  // C++1y [expr.prim.lambda]p11:
1155  // An init-capture behaves as if it declares and explicitly
1156  // captures a variable [...] whose declarative region is the
1157  // lambda-expression's compound-statement
1158  if (Var)
1159  PushOnScopeChains(Var, CurScope, false);
1160  } else {
1161  assert(C->InitKind == LambdaCaptureInitKind::NoInit &&
1162  "init capture has valid but null init?");
1163 
1164  // C++11 [expr.prim.lambda]p8:
1165  // If a lambda-capture includes a capture-default that is &, the
1166  // identifiers in the lambda-capture shall not be preceded by &.
1167  // If a lambda-capture includes a capture-default that is =, [...]
1168  // each identifier it contains shall be preceded by &.
1169  if (C->Kind == LCK_ByRef && Intro.Default == LCD_ByRef) {
1170  Diag(C->Loc, diag::err_reference_capture_with_reference_default)
1172  SourceRange(getLocForEndOfToken(PrevCaptureLoc), C->Loc));
1173  continue;
1174  } else if (C->Kind == LCK_ByCopy && Intro.Default == LCD_ByCopy) {
1175  Diag(C->Loc, diag::err_copy_capture_with_copy_default)
1177  SourceRange(getLocForEndOfToken(PrevCaptureLoc), C->Loc));
1178  continue;
1179  }
1180 
1181  // C++11 [expr.prim.lambda]p10:
1182  // The identifiers in a capture-list are looked up using the usual
1183  // rules for unqualified name lookup (3.4.1)
1184  DeclarationNameInfo Name(C->Id, C->Loc);
1185  LookupResult R(*this, Name, LookupOrdinaryName);
1186  LookupName(R, CurScope);
1187  if (R.isAmbiguous())
1188  continue;
1189  if (R.empty()) {
1190  // FIXME: Disable corrections that would add qualification?
1191  CXXScopeSpec ScopeSpec;
1192  DeclFilterCCC<VarDecl> Validator{};
1193  if (DiagnoseEmptyLookup(CurScope, ScopeSpec, R, Validator))
1194  continue;
1195  }
1196 
1197  if (auto *BD = R.getAsSingle<BindingDecl>())
1198  Var = BD;
1199  else
1200  Var = R.getAsSingle<VarDecl>();
1201  if (Var && DiagnoseUseOfDecl(Var, C->Loc))
1202  continue;
1203  }
1204 
1205  // C++11 [expr.prim.lambda]p8:
1206  // An identifier or this shall not appear more than once in a
1207  // lambda-capture.
1208  if (!CaptureNames.insert(C->Id).second) {
1209  if (Var && LSI->isCaptured(Var)) {
1210  Diag(C->Loc, diag::err_capture_more_than_once)
1211  << C->Id << SourceRange(LSI->getCapture(Var).getLocation())
1213  SourceRange(getLocForEndOfToken(PrevCaptureLoc), C->Loc));
1214  } else
1215  // Previous capture captured something different (one or both was
1216  // an init-cpature): no fixit.
1217  Diag(C->Loc, diag::err_capture_more_than_once) << C->Id;
1218  continue;
1219  }
1220 
1221  // C++11 [expr.prim.lambda]p10:
1222  // [...] each such lookup shall find a variable with automatic storage
1223  // duration declared in the reaching scope of the local lambda expression.
1224  // Note that the 'reaching scope' check happens in tryCaptureVariable().
1225  if (!Var) {
1226  Diag(C->Loc, diag::err_capture_does_not_name_variable) << C->Id;
1227  continue;
1228  }
1229 
1230  // Ignore invalid decls; they'll just confuse the code later.
1231  if (Var->isInvalidDecl())
1232  continue;
1233 
1234  VarDecl *Underlying;
1235  if (auto *BD = dyn_cast<BindingDecl>(Var))
1236  Underlying = dyn_cast<VarDecl>(BD->getDecomposedDecl());
1237  else
1238  Underlying = cast<VarDecl>(Var);
1239 
1240  if (!Underlying->hasLocalStorage()) {
1241  Diag(C->Loc, diag::err_capture_non_automatic_variable) << C->Id;
1242  Diag(Var->getLocation(), diag::note_previous_decl) << C->Id;
1243  continue;
1244  }
1245 
1246  // C++11 [expr.prim.lambda]p23:
1247  // A capture followed by an ellipsis is a pack expansion (14.5.3).
1248  SourceLocation EllipsisLoc;
1249  if (C->EllipsisLoc.isValid()) {
1250  if (Var->isParameterPack()) {
1251  EllipsisLoc = C->EllipsisLoc;
1252  } else {
1253  Diag(C->EllipsisLoc, diag::err_pack_expansion_without_parameter_packs)
1254  << (C->Init.isUsable() ? C->Init.get()->getSourceRange()
1255  : SourceRange(C->Loc));
1256 
1257  // Just ignore the ellipsis.
1258  }
1259  } else if (Var->isParameterPack()) {
1260  ContainsUnexpandedParameterPack = true;
1261  }
1262 
1263  if (C->Init.isUsable()) {
1264  addInitCapture(LSI, cast<VarDecl>(Var));
1265  } else {
1266  TryCaptureKind Kind = C->Kind == LCK_ByRef ? TryCapture_ExplicitByRef :
1267  TryCapture_ExplicitByVal;
1268  tryCaptureVariable(Var, C->Loc, Kind, EllipsisLoc);
1269  }
1270  if (!LSI->Captures.empty())
1271  LSI->ExplicitCaptureRanges[LSI->Captures.size() - 1] = C->ExplicitRange;
1272  }
1273  finishLambdaExplicitCaptures(LSI);
1274 
1275  LSI->ContainsUnexpandedParameterPack |= ContainsUnexpandedParameterPack;
1276 
1277  // Add lambda parameters into scope.
1278  addLambdaParameters(Intro.Captures, Method, CurScope);
1279 
1280  // Enter a new evaluation context to insulate the lambda from any
1281  // cleanups from the enclosing full-expression.
1282  PushExpressionEvaluationContext(
1283  LSI->CallOperator->isConsteval()
1284  ? ExpressionEvaluationContext::ImmediateFunctionContext
1285  : ExpressionEvaluationContext::PotentiallyEvaluated);
1286 }
1287 
1289  bool IsInstantiation) {
1290  LambdaScopeInfo *LSI = cast<LambdaScopeInfo>(FunctionScopes.back());
1291 
1292  // Leave the expression-evaluation context.
1293  DiscardCleanupsInEvaluationContext();
1294  PopExpressionEvaluationContext();
1295 
1296  // Leave the context of the lambda.
1297  if (!IsInstantiation)
1298  PopDeclContext();
1299 
1300  // Finalize the lambda.
1301  CXXRecordDecl *Class = LSI->Lambda;
1302  Class->setInvalidDecl();
1303  SmallVector<Decl*, 4> Fields(Class->fields());
1304  ActOnFields(nullptr, Class->getLocation(), Class, Fields, SourceLocation(),
1306  CheckCompletedCXXClass(nullptr, Class);
1307 
1308  PopFunctionScopeInfo();
1309 }
1310 
1311 template <typename Func>
1313  Sema &S, const FunctionProtoType &CallOpProto, Func F) {
1315  CallOpProto.isVariadic(), /*IsCXXMethod=*/false);
1317  CallOpProto.isVariadic(), /*IsCXXMethod=*/true);
1318  CallingConv CallOpCC = CallOpProto.getCallConv();
1319 
1320  /// Implement emitting a version of the operator for many of the calling
1321  /// conventions for MSVC, as described here:
1322  /// https://devblogs.microsoft.com/oldnewthing/20150220-00/?p=44623.
1323  /// Experimentally, we determined that cdecl, stdcall, fastcall, and
1324  /// vectorcall are generated by MSVC when it is supported by the target.
1325  /// Additionally, we are ensuring that the default-free/default-member and
1326  /// call-operator calling convention are generated as well.
1327  /// NOTE: We intentionally generate a 'thiscall' on Win32 implicitly from the
1328  /// 'member default', despite MSVC not doing so. We do this in order to ensure
1329  /// that someone who intentionally places 'thiscall' on the lambda call
1330  /// operator will still get that overload, since we don't have the a way of
1331  /// detecting the attribute by the time we get here.
1332  if (S.getLangOpts().MSVCCompat) {
1333  CallingConv Convs[] = {
1335  DefaultFree, DefaultMember, CallOpCC};
1336  llvm::sort(Convs);
1337  llvm::iterator_range<CallingConv *> Range(
1338  std::begin(Convs), std::unique(std::begin(Convs), std::end(Convs)));
1339  const TargetInfo &TI = S.getASTContext().getTargetInfo();
1340 
1341  for (CallingConv C : Range) {
1343  F(C);
1344  }
1345  return;
1346  }
1347 
1348  if (CallOpCC == DefaultMember && DefaultMember != DefaultFree) {
1349  F(DefaultFree);
1350  F(DefaultMember);
1351  } else {
1352  F(CallOpCC);
1353  }
1354 }
1355 
1356 // Returns the 'standard' calling convention to be used for the lambda
1357 // conversion function, that is, the 'free' function calling convention unless
1358 // it is overridden by a non-default calling convention attribute.
1359 static CallingConv
1361  const FunctionProtoType *CallOpProto) {
1363  CallOpProto->isVariadic(), /*IsCXXMethod=*/false);
1365  CallOpProto->isVariadic(), /*IsCXXMethod=*/true);
1366  CallingConv CallOpCC = CallOpProto->getCallConv();
1367 
1368  // If the call-operator hasn't been changed, return both the 'free' and
1369  // 'member' function calling convention.
1370  if (CallOpCC == DefaultMember && DefaultMember != DefaultFree)
1371  return DefaultFree;
1372  return CallOpCC;
1373 }
1374 
1376  const FunctionProtoType *CallOpProto, CallingConv CC) {
1377  const FunctionProtoType::ExtProtoInfo CallOpExtInfo =
1378  CallOpProto->getExtProtoInfo();
1379  FunctionProtoType::ExtProtoInfo InvokerExtInfo = CallOpExtInfo;
1380  InvokerExtInfo.ExtInfo = InvokerExtInfo.ExtInfo.withCallingConv(CC);
1381  InvokerExtInfo.TypeQuals = Qualifiers();
1382  assert(InvokerExtInfo.RefQualifier == RQ_None &&
1383  "Lambda's call operator should not have a reference qualifier");
1384  return Context.getFunctionType(CallOpProto->getReturnType(),
1385  CallOpProto->getParamTypes(), InvokerExtInfo);
1386 }
1387 
1388 /// Add a lambda's conversion to function pointer, as described in
1389 /// C++11 [expr.prim.lambda]p6.
1390 static void addFunctionPointerConversion(Sema &S, SourceRange IntroducerRange,
1391  CXXRecordDecl *Class,
1392  CXXMethodDecl *CallOperator,
1393  QualType InvokerFunctionTy) {
1394  // This conversion is explicitly disabled if the lambda's function has
1395  // pass_object_size attributes on any of its parameters.
1396  auto HasPassObjectSizeAttr = [](const ParmVarDecl *P) {
1397  return P->hasAttr<PassObjectSizeAttr>();
1398  };
1399  if (llvm::any_of(CallOperator->parameters(), HasPassObjectSizeAttr))
1400  return;
1401 
1402  // Add the conversion to function pointer.
1403  QualType PtrToFunctionTy = S.Context.getPointerType(InvokerFunctionTy);
1404 
1405  // Create the type of the conversion function.
1406  FunctionProtoType::ExtProtoInfo ConvExtInfo(
1408  /*IsVariadic=*/false, /*IsCXXMethod=*/true));
1409  // The conversion function is always const and noexcept.
1410  ConvExtInfo.TypeQuals = Qualifiers();
1411  ConvExtInfo.TypeQuals.addConst();
1412  ConvExtInfo.ExceptionSpec.Type = EST_BasicNoexcept;
1413  QualType ConvTy =
1414  S.Context.getFunctionType(PtrToFunctionTy, None, ConvExtInfo);
1415 
1416  SourceLocation Loc = IntroducerRange.getBegin();
1417  DeclarationName ConversionName
1419  S.Context.getCanonicalType(PtrToFunctionTy));
1420  // Construct a TypeSourceInfo for the conversion function, and wire
1421  // all the parameters appropriately for the FunctionProtoTypeLoc
1422  // so that everything works during transformation/instantiation of
1423  // generic lambdas.
1424  // The main reason for wiring up the parameters of the conversion
1425  // function with that of the call operator is so that constructs
1426  // like the following work:
1427  // auto L = [](auto b) { <-- 1
1428  // return [](auto a) -> decltype(a) { <-- 2
1429  // return a;
1430  // };
1431  // };
1432  // int (*fp)(int) = L(5);
1433  // Because the trailing return type can contain DeclRefExprs that refer
1434  // to the original call operator's variables, we hijack the call
1435  // operators ParmVarDecls below.
1436  TypeSourceInfo *ConvNamePtrToFunctionTSI =
1437  S.Context.getTrivialTypeSourceInfo(PtrToFunctionTy, Loc);
1438  DeclarationNameLoc ConvNameLoc =
1439  DeclarationNameLoc::makeNamedTypeLoc(ConvNamePtrToFunctionTSI);
1440 
1441  // The conversion function is a conversion to a pointer-to-function.
1442  TypeSourceInfo *ConvTSI = S.Context.getTrivialTypeSourceInfo(ConvTy, Loc);
1443  FunctionProtoTypeLoc ConvTL =
1444  ConvTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
1445  // Get the result of the conversion function which is a pointer-to-function.
1446  PointerTypeLoc PtrToFunctionTL =
1447  ConvTL.getReturnLoc().getAs<PointerTypeLoc>();
1448  // Do the same for the TypeSourceInfo that is used to name the conversion
1449  // operator.
1450  PointerTypeLoc ConvNamePtrToFunctionTL =
1451  ConvNamePtrToFunctionTSI->getTypeLoc().getAs<PointerTypeLoc>();
1452 
1453  // Get the underlying function types that the conversion function will
1454  // be converting to (should match the type of the call operator).
1455  FunctionProtoTypeLoc CallOpConvTL =
1456  PtrToFunctionTL.getPointeeLoc().getAs<FunctionProtoTypeLoc>();
1457  FunctionProtoTypeLoc CallOpConvNameTL =
1458  ConvNamePtrToFunctionTL.getPointeeLoc().getAs<FunctionProtoTypeLoc>();
1459 
1460  // Wire up the FunctionProtoTypeLocs with the call operator's parameters.
1461  // These parameter's are essentially used to transform the name and
1462  // the type of the conversion operator. By using the same parameters
1463  // as the call operator's we don't have to fix any back references that
1464  // the trailing return type of the call operator's uses (such as
1465  // decltype(some_type<decltype(a)>::type{} + decltype(a){}) etc.)
1466  // - we can simply use the return type of the call operator, and
1467  // everything should work.
1468  SmallVector<ParmVarDecl *, 4> InvokerParams;
1469  for (unsigned I = 0, N = CallOperator->getNumParams(); I != N; ++I) {
1470  ParmVarDecl *From = CallOperator->getParamDecl(I);
1471 
1472  InvokerParams.push_back(ParmVarDecl::Create(
1473  S.Context,
1474  // Temporarily add to the TU. This is set to the invoker below.
1476  From->getLocation(), From->getIdentifier(), From->getType(),
1477  From->getTypeSourceInfo(), From->getStorageClass(),
1478  /*DefArg=*/nullptr));
1479  CallOpConvTL.setParam(I, From);
1480  CallOpConvNameTL.setParam(I, From);
1481  }
1482 
1484  S.Context, Class, Loc,
1485  DeclarationNameInfo(ConversionName, Loc, ConvNameLoc), ConvTy, ConvTSI,
1487  /*isInline=*/true, ExplicitSpecifier(),
1488  S.getLangOpts().CPlusPlus17 ? ConstexprSpecKind::Constexpr
1490  CallOperator->getBody()->getEndLoc());
1491  Conversion->setAccess(AS_public);
1492  Conversion->setImplicit(true);
1493 
1494  if (Class->isGenericLambda()) {
1495  // Create a template version of the conversion operator, using the template
1496  // parameter list of the function call operator.
1497  FunctionTemplateDecl *TemplateCallOperator =
1498  CallOperator->getDescribedFunctionTemplate();
1499  FunctionTemplateDecl *ConversionTemplate =
1501  Loc, ConversionName,
1502  TemplateCallOperator->getTemplateParameters(),
1503  Conversion);
1504  ConversionTemplate->setAccess(AS_public);
1505  ConversionTemplate->setImplicit(true);
1506  Conversion->setDescribedFunctionTemplate(ConversionTemplate);
1507  Class->addDecl(ConversionTemplate);
1508  } else
1509  Class->addDecl(Conversion);
1510 
1511  // If the lambda is not static, we need to add a static member
1512  // function that will be the result of the conversion with a
1513  // certain unique ID.
1514  // When it is static we just return the static call operator instead.
1515  if (CallOperator->isInstance()) {
1516  DeclarationName InvokerName =
1518  // FIXME: Instead of passing in the CallOperator->getTypeSourceInfo()
1519  // we should get a prebuilt TrivialTypeSourceInfo from Context
1520  // using FunctionTy & Loc and get its TypeLoc as a FunctionProtoTypeLoc
1521  // then rewire the parameters accordingly, by hoisting up the InvokeParams
1522  // loop below and then use its Params to set Invoke->setParams(...) below.
1523  // This would avoid the 'const' qualifier of the calloperator from
1524  // contaminating the type of the invoker, which is currently adjusted
1525  // in SemaTemplateDeduction.cpp:DeduceTemplateArguments. Fixing the
1526  // trailing return type of the invoker would require a visitor to rebuild
1527  // the trailing return type and adjusting all back DeclRefExpr's to refer
1528  // to the new static invoker parameters - not the call operator's.
1530  S.Context, Class, Loc, DeclarationNameInfo(InvokerName, Loc),
1531  InvokerFunctionTy, CallOperator->getTypeSourceInfo(), SC_Static,
1533  /*isInline=*/true, ConstexprSpecKind::Unspecified,
1534  CallOperator->getBody()->getEndLoc());
1535  for (unsigned I = 0, N = CallOperator->getNumParams(); I != N; ++I)
1536  InvokerParams[I]->setOwningFunction(Invoke);
1537  Invoke->setParams(InvokerParams);
1538  Invoke->setAccess(AS_private);
1539  Invoke->setImplicit(true);
1540  if (Class->isGenericLambda()) {
1541  FunctionTemplateDecl *TemplateCallOperator =
1542  CallOperator->getDescribedFunctionTemplate();
1543  FunctionTemplateDecl *StaticInvokerTemplate =
1545  S.Context, Class, Loc, InvokerName,
1546  TemplateCallOperator->getTemplateParameters(), Invoke);
1547  StaticInvokerTemplate->setAccess(AS_private);
1548  StaticInvokerTemplate->setImplicit(true);
1549  Invoke->setDescribedFunctionTemplate(StaticInvokerTemplate);
1550  Class->addDecl(StaticInvokerTemplate);
1551  } else
1552  Class->addDecl(Invoke);
1553  }
1554 }
1555 
1556 /// Add a lambda's conversion to function pointers, as described in
1557 /// C++11 [expr.prim.lambda]p6. Note that in most cases, this should emit only a
1558 /// single pointer conversion. In the event that the default calling convention
1559 /// for free and member functions is different, it will emit both conventions.
1560 static void addFunctionPointerConversions(Sema &S, SourceRange IntroducerRange,
1561  CXXRecordDecl *Class,
1562  CXXMethodDecl *CallOperator) {
1563  const FunctionProtoType *CallOpProto =
1564  CallOperator->getType()->castAs<FunctionProtoType>();
1565 
1567  S, *CallOpProto, [&](CallingConv CC) {
1568  QualType InvokerFunctionTy =
1569  S.getLambdaConversionFunctionResultType(CallOpProto, CC);
1570  addFunctionPointerConversion(S, IntroducerRange, Class, CallOperator,
1571  InvokerFunctionTy);
1572  });
1573 }
1574 
1575 /// Add a lambda's conversion to block pointer.
1577  SourceRange IntroducerRange,
1578  CXXRecordDecl *Class,
1579  CXXMethodDecl *CallOperator) {
1580  const FunctionProtoType *CallOpProto =
1581  CallOperator->getType()->castAs<FunctionProtoType>();
1583  CallOpProto, getLambdaConversionFunctionCallConv(S, CallOpProto));
1584  QualType BlockPtrTy = S.Context.getBlockPointerType(FunctionTy);
1585 
1586  FunctionProtoType::ExtProtoInfo ConversionEPI(
1588  /*IsVariadic=*/false, /*IsCXXMethod=*/true));
1589  ConversionEPI.TypeQuals = Qualifiers();
1590  ConversionEPI.TypeQuals.addConst();
1591  QualType ConvTy = S.Context.getFunctionType(BlockPtrTy, None, ConversionEPI);
1592 
1593  SourceLocation Loc = IntroducerRange.getBegin();
1594  DeclarationName Name
1596  S.Context.getCanonicalType(BlockPtrTy));
1598  S.Context.getTrivialTypeSourceInfo(BlockPtrTy, Loc));
1600  S.Context, Class, Loc, DeclarationNameInfo(Name, Loc, NameLoc), ConvTy,
1601  S.Context.getTrivialTypeSourceInfo(ConvTy, Loc),
1603  /*isInline=*/true, ExplicitSpecifier(), ConstexprSpecKind::Unspecified,
1604  CallOperator->getBody()->getEndLoc());
1605  Conversion->setAccess(AS_public);
1606  Conversion->setImplicit(true);
1607  Class->addDecl(Conversion);
1608 }
1609 
1611  SourceLocation ImplicitCaptureLoc,
1612  bool IsOpenMPMapping) {
1613  // VLA captures don't have a stored initialization expression.
1614  if (Cap.isVLATypeCapture())
1615  return ExprResult();
1616 
1617  // An init-capture is initialized directly from its stored initializer.
1618  if (Cap.isInitCapture())
1619  return cast<VarDecl>(Cap.getVariable())->getInit();
1620 
1621  // For anything else, build an initialization expression. For an implicit
1622  // capture, the capture notionally happens at the capture-default, so use
1623  // that location here.
1624  SourceLocation Loc =
1625  ImplicitCaptureLoc.isValid() ? ImplicitCaptureLoc : Cap.getLocation();
1626 
1627  // C++11 [expr.prim.lambda]p21:
1628  // When the lambda-expression is evaluated, the entities that
1629  // are captured by copy are used to direct-initialize each
1630  // corresponding non-static data member of the resulting closure
1631  // object. (For array members, the array elements are
1632  // direct-initialized in increasing subscript order.) These
1633  // initializations are performed in the (unspecified) order in
1634  // which the non-static data members are declared.
1635 
1636  // C++ [expr.prim.lambda]p12:
1637  // An entity captured by a lambda-expression is odr-used (3.2) in
1638  // the scope containing the lambda-expression.
1639  ExprResult Init;
1640  IdentifierInfo *Name = nullptr;
1641  if (Cap.isThisCapture()) {
1642  QualType ThisTy = getCurrentThisType();
1643  Expr *This = BuildCXXThisExpr(Loc, ThisTy, ImplicitCaptureLoc.isValid());
1644  if (Cap.isCopyCapture())
1645  Init = CreateBuiltinUnaryOp(Loc, UO_Deref, This);
1646  else
1647  Init = This;
1648  } else {
1649  assert(Cap.isVariableCapture() && "unknown kind of capture");
1650  ValueDecl *Var = Cap.getVariable();
1651  Name = Var->getIdentifier();
1652  Init = BuildDeclarationNameExpr(
1653  CXXScopeSpec(), DeclarationNameInfo(Var->getDeclName(), Loc), Var);
1654  }
1655 
1656  // In OpenMP, the capture kind doesn't actually describe how to capture:
1657  // variables are "mapped" onto the device in a process that does not formally
1658  // make a copy, even for a "copy capture".
1659  if (IsOpenMPMapping)
1660  return Init;
1661 
1662  if (Init.isInvalid())
1663  return ExprError();
1664 
1665  Expr *InitExpr = Init.get();
1667  Name, Cap.getCaptureType(), Loc);
1668  InitializationKind InitKind =
1669  InitializationKind::CreateDirect(Loc, Loc, Loc);
1670  InitializationSequence InitSeq(*this, Entity, InitKind, InitExpr);
1671  return InitSeq.Perform(*this, Entity, InitKind, InitExpr);
1672 }
1673 
1675  Scope *CurScope) {
1676  LambdaScopeInfo LSI = *cast<LambdaScopeInfo>(FunctionScopes.back());
1677  ActOnFinishFunctionBody(LSI.CallOperator, Body);
1678  return BuildLambdaExpr(StartLoc, Body->getEndLoc(), &LSI);
1679 }
1680 
1681 static LambdaCaptureDefault
1683  switch (ICS) {
1685  return LCD_None;
1687  return LCD_ByCopy;
1690  return LCD_ByRef;
1692  llvm_unreachable("block capture in lambda");
1693  }
1694  llvm_unreachable("Unknown implicit capture style");
1695 }
1696 
1698  if (From.isInitCapture()) {
1699  Expr *Init = cast<VarDecl>(From.getVariable())->getInit();
1700  if (Init && Init->HasSideEffects(Context))
1701  return true;
1702  }
1703 
1704  if (!From.isCopyCapture())
1705  return false;
1706 
1707  const QualType T = From.isThisCapture()
1708  ? getCurrentThisType()->getPointeeType()
1709  : From.getCaptureType();
1710 
1711  if (T.isVolatileQualified())
1712  return true;
1713 
1714  const Type *BaseT = T->getBaseElementTypeUnsafe();
1715  if (const CXXRecordDecl *RD = BaseT->getAsCXXRecordDecl())
1716  return !RD->isCompleteDefinition() || !RD->hasTrivialCopyConstructor() ||
1717  !RD->hasTrivialDestructor();
1718 
1719  return false;
1720 }
1721 
1723  const Capture &From) {
1724  if (CaptureHasSideEffects(From))
1725  return false;
1726 
1727  if (From.isVLATypeCapture())
1728  return false;
1729 
1730  auto diag = Diag(From.getLocation(), diag::warn_unused_lambda_capture);
1731  if (From.isThisCapture())
1732  diag << "'this'";
1733  else
1734  diag << From.getVariable();
1735  diag << From.isNonODRUsed();
1736  diag << FixItHint::CreateRemoval(CaptureRange);
1737  return true;
1738 }
1739 
1740 /// Create a field within the lambda class or captured statement record for the
1741 /// given capture.
1743  const sema::Capture &Capture) {
1745  QualType FieldType = Capture.getCaptureType();
1746 
1747  TypeSourceInfo *TSI = nullptr;
1748  if (Capture.isVariableCapture()) {
1749  const auto *Var = dyn_cast_or_null<VarDecl>(Capture.getVariable());
1750  if (Var && Var->isInitCapture())
1751  TSI = Var->getTypeSourceInfo();
1752  }
1753 
1754  // FIXME: Should we really be doing this? A null TypeSourceInfo seems more
1755  // appropriate, at least for an implicit capture.
1756  if (!TSI)
1757  TSI = Context.getTrivialTypeSourceInfo(FieldType, Loc);
1758 
1759  // Build the non-static data member.
1760  FieldDecl *Field =
1761  FieldDecl::Create(Context, RD, /*StartLoc=*/Loc, /*IdLoc=*/Loc,
1762  /*Id=*/nullptr, FieldType, TSI, /*BW=*/nullptr,
1763  /*Mutable=*/false, ICIS_NoInit);
1764  // If the variable being captured has an invalid type, mark the class as
1765  // invalid as well.
1766  if (!FieldType->isDependentType()) {
1767  if (RequireCompleteSizedType(Loc, FieldType,
1768  diag::err_field_incomplete_or_sizeless)) {
1769  RD->setInvalidDecl();
1770  Field->setInvalidDecl();
1771  } else {
1772  NamedDecl *Def;
1773  FieldType->isIncompleteType(&Def);
1774  if (Def && Def->isInvalidDecl()) {
1775  RD->setInvalidDecl();
1776  Field->setInvalidDecl();
1777  }
1778  }
1779  }
1780  Field->setImplicit(true);
1781  Field->setAccess(AS_private);
1782  RD->addDecl(Field);
1783 
1784  if (Capture.isVLATypeCapture())
1785  Field->setCapturedVLAType(Capture.getCapturedVLAType());
1786 
1787  return Field;
1788 }
1789 
1791  LambdaScopeInfo *LSI) {
1792  // Collect information from the lambda scope.
1794  SmallVector<Expr *, 4> CaptureInits;
1795  SourceLocation CaptureDefaultLoc = LSI->CaptureDefaultLoc;
1796  LambdaCaptureDefault CaptureDefault =
1798  CXXRecordDecl *Class;
1799  CXXMethodDecl *CallOperator;
1800  SourceRange IntroducerRange;
1801  bool ExplicitParams;
1802  bool ExplicitResultType;
1803  CleanupInfo LambdaCleanup;
1804  bool ContainsUnexpandedParameterPack;
1805  bool IsGenericLambda;
1806  {
1807  CallOperator = LSI->CallOperator;
1808  Class = LSI->Lambda;
1809  IntroducerRange = LSI->IntroducerRange;
1810  ExplicitParams = LSI->ExplicitParams;
1811  ExplicitResultType = !LSI->HasImplicitReturnType;
1812  LambdaCleanup = LSI->Cleanup;
1813  ContainsUnexpandedParameterPack = LSI->ContainsUnexpandedParameterPack;
1814  IsGenericLambda = Class->isGenericLambda();
1815 
1816  CallOperator->setLexicalDeclContext(Class);
1817  Decl *TemplateOrNonTemplateCallOperatorDecl =
1818  CallOperator->getDescribedFunctionTemplate()
1819  ? CallOperator->getDescribedFunctionTemplate()
1820  : cast<Decl>(CallOperator);
1821 
1822  // FIXME: Is this really the best choice? Keeping the lexical decl context
1823  // set as CurContext seems more faithful to the source.
1824  TemplateOrNonTemplateCallOperatorDecl->setLexicalDeclContext(Class);
1825 
1826  PopExpressionEvaluationContext();
1827 
1828  // True if the current capture has a used capture or default before it.
1829  bool CurHasPreviousCapture = CaptureDefault != LCD_None;
1830  SourceLocation PrevCaptureLoc = CurHasPreviousCapture ?
1831  CaptureDefaultLoc : IntroducerRange.getBegin();
1832 
1833  for (unsigned I = 0, N = LSI->Captures.size(); I != N; ++I) {
1834  const Capture &From = LSI->Captures[I];
1835 
1836  if (From.isInvalid())
1837  return ExprError();
1838 
1839  assert(!From.isBlockCapture() && "Cannot capture __block variables");
1840  bool IsImplicit = I >= LSI->NumExplicitCaptures;
1841  SourceLocation ImplicitCaptureLoc =
1842  IsImplicit ? CaptureDefaultLoc : SourceLocation();
1843 
1844  // Use source ranges of explicit captures for fixits where available.
1845  SourceRange CaptureRange = LSI->ExplicitCaptureRanges[I];
1846 
1847  // Warn about unused explicit captures.
1848  bool IsCaptureUsed = true;
1849  if (!CurContext->isDependentContext() && !IsImplicit &&
1850  !From.isODRUsed()) {
1851  // Initialized captures that are non-ODR used may not be eliminated.
1852  // FIXME: Where did the IsGenericLambda here come from?
1853  bool NonODRUsedInitCapture =
1854  IsGenericLambda && From.isNonODRUsed() && From.isInitCapture();
1855  if (!NonODRUsedInitCapture) {
1856  bool IsLast = (I + 1) == LSI->NumExplicitCaptures;
1857  SourceRange FixItRange;
1858  if (CaptureRange.isValid()) {
1859  if (!CurHasPreviousCapture && !IsLast) {
1860  // If there are no captures preceding this capture, remove the
1861  // following comma.
1862  FixItRange = SourceRange(CaptureRange.getBegin(),
1863  getLocForEndOfToken(CaptureRange.getEnd()));
1864  } else {
1865  // Otherwise, remove the comma since the last used capture.
1866  FixItRange = SourceRange(getLocForEndOfToken(PrevCaptureLoc),
1867  CaptureRange.getEnd());
1868  }
1869  }
1870 
1871  IsCaptureUsed = !DiagnoseUnusedLambdaCapture(FixItRange, From);
1872  }
1873  }
1874 
1875  if (CaptureRange.isValid()) {
1876  CurHasPreviousCapture |= IsCaptureUsed;
1877  PrevCaptureLoc = CaptureRange.getEnd();
1878  }
1879 
1880  // Map the capture to our AST representation.
1881  LambdaCapture Capture = [&] {
1882  if (From.isThisCapture()) {
1883  // Capturing 'this' implicitly with a default of '[=]' is deprecated,
1884  // because it results in a reference capture. Don't warn prior to
1885  // C++2a; there's nothing that can be done about it before then.
1886  if (getLangOpts().CPlusPlus20 && IsImplicit &&
1887  CaptureDefault == LCD_ByCopy) {
1888  Diag(From.getLocation(), diag::warn_deprecated_this_capture);
1889  Diag(CaptureDefaultLoc, diag::note_deprecated_this_capture)
1891  getLocForEndOfToken(CaptureDefaultLoc), ", this");
1892  }
1893  return LambdaCapture(From.getLocation(), IsImplicit,
1894  From.isCopyCapture() ? LCK_StarThis : LCK_This);
1895  } else if (From.isVLATypeCapture()) {
1896  return LambdaCapture(From.getLocation(), IsImplicit, LCK_VLAType);
1897  } else {
1898  assert(From.isVariableCapture() && "unknown kind of capture");
1899  ValueDecl *Var = From.getVariable();
1901  From.isCopyCapture() ? LCK_ByCopy : LCK_ByRef;
1902  return LambdaCapture(From.getLocation(), IsImplicit, Kind, Var,
1903  From.getEllipsisLoc());
1904  }
1905  }();
1906 
1907  // Form the initializer for the capture field.
1908  ExprResult Init = BuildCaptureInit(From, ImplicitCaptureLoc);
1909 
1910  // FIXME: Skip this capture if the capture is not used, the initializer
1911  // has no side-effects, the type of the capture is trivial, and the
1912  // lambda is not externally visible.
1913 
1914  // Add a FieldDecl for the capture and form its initializer.
1915  BuildCaptureField(Class, From);
1916  Captures.push_back(Capture);
1917  CaptureInits.push_back(Init.get());
1918 
1919  if (LangOpts.CUDA)
1920  CUDACheckLambdaCapture(CallOperator, From);
1921  }
1922 
1923  Class->setCaptures(Context, Captures);
1924 
1925  // C++11 [expr.prim.lambda]p6:
1926  // The closure type for a lambda-expression with no lambda-capture
1927  // has a public non-virtual non-explicit const conversion function
1928  // to pointer to function having the same parameter and return
1929  // types as the closure type's function call operator.
1930  if (Captures.empty() && CaptureDefault == LCD_None)
1931  addFunctionPointerConversions(*this, IntroducerRange, Class,
1932  CallOperator);
1933 
1934  // Objective-C++:
1935  // The closure type for a lambda-expression has a public non-virtual
1936  // non-explicit const conversion function to a block pointer having the
1937  // same parameter and return types as the closure type's function call
1938  // operator.
1939  // FIXME: Fix generic lambda to block conversions.
1940  if (getLangOpts().Blocks && getLangOpts().ObjC && !IsGenericLambda)
1941  addBlockPointerConversion(*this, IntroducerRange, Class, CallOperator);
1942 
1943  // Finalize the lambda class.
1944  SmallVector<Decl*, 4> Fields(Class->fields());
1945  ActOnFields(nullptr, Class->getLocation(), Class, Fields, SourceLocation(),
1947  CheckCompletedCXXClass(nullptr, Class);
1948  }
1949 
1950  Cleanup.mergeFrom(LambdaCleanup);
1951 
1952  LambdaExpr *Lambda = LambdaExpr::Create(Context, Class, IntroducerRange,
1953  CaptureDefault, CaptureDefaultLoc,
1954  ExplicitParams, ExplicitResultType,
1955  CaptureInits, EndLoc,
1956  ContainsUnexpandedParameterPack);
1957  // If the lambda expression's call operator is not explicitly marked constexpr
1958  // and we are not in a dependent context, analyze the call operator to infer
1959  // its constexpr-ness, suppressing diagnostics while doing so.
1960  if (getLangOpts().CPlusPlus17 && !CallOperator->isInvalidDecl() &&
1961  !CallOperator->isConstexpr() &&
1962  !isa<CoroutineBodyStmt>(CallOperator->getBody()) &&
1963  !Class->getDeclContext()->isDependentContext()) {
1964  CallOperator->setConstexprKind(
1965  CheckConstexprFunctionDefinition(CallOperator,
1966  CheckConstexprKind::CheckValid)
1969  }
1970 
1971  // Emit delayed shadowing warnings now that the full capture list is known.
1972  DiagnoseShadowingLambdaDecls(LSI);
1973 
1974  if (!CurContext->isDependentContext()) {
1975  switch (ExprEvalContexts.back().Context) {
1976  // C++11 [expr.prim.lambda]p2:
1977  // A lambda-expression shall not appear in an unevaluated operand
1978  // (Clause 5).
1979  case ExpressionEvaluationContext::Unevaluated:
1980  case ExpressionEvaluationContext::UnevaluatedList:
1981  case ExpressionEvaluationContext::UnevaluatedAbstract:
1982  // C++1y [expr.const]p2:
1983  // A conditional-expression e is a core constant expression unless the
1984  // evaluation of e, following the rules of the abstract machine, would
1985  // evaluate [...] a lambda-expression.
1986  //
1987  // This is technically incorrect, there are some constant evaluated contexts
1988  // where this should be allowed. We should probably fix this when DR1607 is
1989  // ratified, it lays out the exact set of conditions where we shouldn't
1990  // allow a lambda-expression.
1991  case ExpressionEvaluationContext::ConstantEvaluated:
1992  case ExpressionEvaluationContext::ImmediateFunctionContext:
1993  // We don't actually diagnose this case immediately, because we
1994  // could be within a context where we might find out later that
1995  // the expression is potentially evaluated (e.g., for typeid).
1996  ExprEvalContexts.back().Lambdas.push_back(Lambda);
1997  break;
1998 
1999  case ExpressionEvaluationContext::DiscardedStatement:
2000  case ExpressionEvaluationContext::PotentiallyEvaluated:
2001  case ExpressionEvaluationContext::PotentiallyEvaluatedIfUsed:
2002  break;
2003  }
2004  }
2005 
2006  return MaybeBindToTemporary(Lambda);
2007 }
2008 
2010  SourceLocation ConvLocation,
2011  CXXConversionDecl *Conv,
2012  Expr *Src) {
2013  // Make sure that the lambda call operator is marked used.
2014  CXXRecordDecl *Lambda = Conv->getParent();
2015  CXXMethodDecl *CallOperator
2016  = cast<CXXMethodDecl>(
2017  Lambda->lookup(
2018  Context.DeclarationNames.getCXXOperatorName(OO_Call)).front());
2019  CallOperator->setReferenced();
2020  CallOperator->markUsed(Context);
2021 
2022  ExprResult Init = PerformCopyInitialization(
2024  CurrentLocation, Src);
2025  if (!Init.isInvalid())
2026  Init = ActOnFinishFullExpr(Init.get(), /*DiscardedValue*/ false);
2027 
2028  if (Init.isInvalid())
2029  return ExprError();
2030 
2031  // Create the new block to be returned.
2032  BlockDecl *Block = BlockDecl::Create(Context, CurContext, ConvLocation);
2033 
2034  // Set the type information.
2035  Block->setSignatureAsWritten(CallOperator->getTypeSourceInfo());
2036  Block->setIsVariadic(CallOperator->isVariadic());
2037  Block->setBlockMissingReturnType(false);
2038 
2039  // Add parameters.
2040  SmallVector<ParmVarDecl *, 4> BlockParams;
2041  for (unsigned I = 0, N = CallOperator->getNumParams(); I != N; ++I) {
2042  ParmVarDecl *From = CallOperator->getParamDecl(I);
2043  BlockParams.push_back(ParmVarDecl::Create(
2044  Context, Block, From->getBeginLoc(), From->getLocation(),
2045  From->getIdentifier(), From->getType(), From->getTypeSourceInfo(),
2046  From->getStorageClass(),
2047  /*DefArg=*/nullptr));
2048  }
2049  Block->setParams(BlockParams);
2050 
2051  Block->setIsConversionFromLambda(true);
2052 
2053  // Add capture. The capture uses a fake variable, which doesn't correspond
2054  // to any actual memory location. However, the initializer copy-initializes
2055  // the lambda object.
2056  TypeSourceInfo *CapVarTSI =
2057  Context.getTrivialTypeSourceInfo(Src->getType());
2058  VarDecl *CapVar = VarDecl::Create(Context, Block, ConvLocation,
2059  ConvLocation, nullptr,
2060  Src->getType(), CapVarTSI,
2061  SC_None);
2062  BlockDecl::Capture Capture(/*variable=*/CapVar, /*byRef=*/false,
2063  /*nested=*/false, /*copy=*/Init.get());
2064  Block->setCaptures(Context, Capture, /*CapturesCXXThis=*/false);
2065 
2066  // Add a fake function body to the block. IR generation is responsible
2067  // for filling in the actual body, which cannot be expressed as an AST.
2068  Block->setBody(new (Context) CompoundStmt(ConvLocation));
2069 
2070  // Create the block literal expression.
2071  Expr *BuildBlock = new (Context) BlockExpr(Block, Conv->getConversionType());
2072  ExprCleanupObjects.push_back(Block);
2073  Cleanup.setExprNeedsCleanups(true);
2074 
2075  return BuildBlock;
2076 }
clang::Decl::setLexicalDeclContext
void setLexicalDeclContext(DeclContext *DC)
Definition: DeclBase.cpp:340
clang::DeclarationNameLoc::makeCXXOperatorNameLoc
static DeclarationNameLoc makeCXXOperatorNameLoc(SourceLocation BeginLoc, SourceLocation EndLoc)
Construct location information for a non-literal C++ operator.
Definition: DeclarationName.h:745
clang::Sema::finishLambdaExplicitCaptures
void finishLambdaExplicitCaptures(sema::LambdaScopeInfo *LSI)
Note that we have finished the explicit captures for the given lambda.
Definition: SemaLambda.cpp:524
clang::ExplicitSpecifier
Store information needed for an explicit specifier.
Definition: DeclCXX.h:1830
clang::TagDecl::hasNameForLinkage
bool hasNameForLinkage() const
Is this tag type named, either directly or via being defined in a typedef of this type?
Definition: Decl.h:3647
clang::Language::CUDA
@ CUDA
clang::DeclaratorChunk::FunctionTypeInfo::NumParams
unsigned NumParams
NumParams - This is the number of formal parameters specified by the declarator.
Definition: DeclSpec.h:1338
clang::sema::Capture::isThisCapture
bool isThisCapture() const
Definition: ScopeInfo.h:617
clang::sema::LambdaScopeInfo::ExplicitTemplateParamsRange
SourceRange ExplicitTemplateParamsRange
Source range covering the explicit template parameter list (if it exists).
Definition: ScopeInfo.h:865
clang::DeclSpec::SetTypeQual
bool SetTypeQual(TQ T, SourceLocation Loc)
Definition: DeclSpec.cpp:980
clang::Type::getNullability
Optional< NullabilityKind > getNullability(const ASTContext &context) const
Determine the nullability of the given type.
Definition: Type.cpp:4146
clang::OpaquePtr::get
PtrTy get() const
Definition: Ownership.h:80
clang::MangleNumberingContext::getManglingNumber
virtual unsigned getManglingNumber(const CXXMethodDecl *CallOperator)=0
Retrieve the mangling number of a new lambda expression with the given call operator within this cont...
clang::ReturnStmt::getRetValue
Expr * getRetValue()
Definition: Stmt.h:2829
clang::sema::Capture::getLocation
SourceLocation getLocation() const
Retrieve the location at which this variable was captured.
Definition: ScopeInfo.h:654
clang::isLambdaCallOperator
bool isLambdaCallOperator(const CXXMethodDecl *MD)
Definition: ASTLambda.h:27
repeatForLambdaConversionFunctionCallingConvs
static void repeatForLambdaConversionFunctionCallingConvs(Sema &S, const FunctionProtoType &CallOpProto, Func F)
Definition: SemaLambda.cpp:1312
clang::TemplateParameterList::Create
static TemplateParameterList * Create(const ASTContext &C, SourceLocation TemplateLoc, SourceLocation LAngleLoc, ArrayRef< NamedDecl * > Params, SourceLocation RAngleLoc, Expr *RequiresClause)
Definition: DeclTemplate.cpp:119
clang::ASTContext::getTypeDeclType
QualType getTypeDeclType(const TypeDecl *Decl, const TypeDecl *PrevDecl=nullptr) const
Return the unique reference to the type for the specified type declaration.
Definition: ASTContext.h:1583
clang::CC_X86FastCall
@ CC_X86FastCall
Definition: Specifiers.h:269
TypeLocBuilder.h
clang::FunctionDecl::getNumParams
unsigned getNumParams() const
Return the number of parameters this function must have based on its FunctionType.
Definition: Decl.cpp:3466
clang::DeclaratorChunk::FunctionTypeInfo::hasTrailingReturnType
bool hasTrailingReturnType() const
Determine whether this function declarator had a trailing-return-type.
Definition: DeclSpec.h:1521
clang::FPOptions::isFPConstrained
bool isFPConstrained() const
Definition: LangOptions.h:733
clang::Sema::deduceClosureReturnType
void deduceClosureReturnType(sema::CapturingScopeInfo &CSI)
Deduce a block or lambda's return type based on the return statements present in the body.
Definition: SemaLambda.cpp:703
clang::TypeSourceInfo::getType
QualType getType() const
Return the type wrapped by this type source info.
Definition: Type.h:6604
getStackIndexOfNearestEnclosingCaptureReadyLambda
static Optional< unsigned > getStackIndexOfNearestEnclosingCaptureReadyLambda(ArrayRef< const clang::sema::FunctionScopeInfo * > FunctionScopes, VarDecl *VarToCapture)
Examines the FunctionScopeInfo stack to determine the nearest enclosing lambda (to the current lambda...
Definition: SemaLambda.cpp:63
clang::LambdaIntroducer
Represents a complete lambda introducer.
Definition: DeclSpec.h:2739
clang::FunctionDecl::getReturnType
QualType getReturnType() const
Definition: Decl.h:2625
clang::DeclaratorDecl::getBeginLoc
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Decl.h:810
clang::DeclarationNameLoc
DeclarationNameLoc - Additional source/type location info for a declaration name.
Definition: DeclarationName.h:659
clang::sema::Capture::isODRUsed
bool isODRUsed() const
Definition: ScopeInfo.h:634
Error
llvm::Error Error
Definition: ByteCodeEmitter.cpp:20
clang::SourceRange
A trivial tuple used to represent a source range.
Definition: SourceLocation.h:210
clang::DeclContext
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1389
clang::sema::LambdaScopeInfo::ExplicitParams
bool ExplicitParams
Whether the (empty) parameter list is explicit.
Definition: ScopeInfo.h:853
clang::PointerTypeLoc
Wrapper for source info for pointers.
Definition: TypeLoc.h:1258
clang::LambdaCapture
Describes the capture of a variable or of this, or of a C++1y init-capture.
Definition: LambdaCapture.h:25
clang::CXXConversionDecl
Represents a C++ conversion function within a class.
Definition: DeclCXX.h:2766
clang::Sema::ActOnLambdaExplicitTemplateParameterList
void ActOnLambdaExplicitTemplateParameterList(SourceLocation LAngleLoc, ArrayRef< NamedDecl * > TParams, SourceLocation RAngleLoc, ExprResult RequiresClause)
This is called after parsing the explicit template parameter list on a lambda (if it exists) in C++2a...
Definition: SemaLambda.cpp:528
clang::TargetInfo::checkCallingConvention
virtual CallingConvCheckResult checkCallingConvention(CallingConv CC) const
Determines whether a given calling convention is valid for the target.
Definition: TargetInfo.h:1563
clang::FixItHint::CreateInsertion
static FixItHint CreateInsertion(SourceLocation InsertionLoc, StringRef Code, bool BeforePreviousInsertions=false)
Create a code modification hint that inserts the given code string at a specific location.
Definition: Diagnostic.h:97
clang::Sema::getASTContext
ASTContext & getASTContext() const
Definition: Sema.h:1637
clang::ReferenceTypeLoc
Definition: TypeLoc.h:1339
clang::Declarator::getNumTypeObjects
unsigned getNumTypeObjects() const
Return the number of types applied to this declarator.
Definition: DeclSpec.h:2299
clang::FunctionDecl::isConstexpr
bool isConstexpr() const
Whether this is a (C++11) constexpr function or constexpr constructor.
Definition: Decl.h:2354
Diag
static DiagnosticBuilder Diag(DiagnosticsEngine *Diags, const LangOptions &Features, FullSourceLoc TokLoc, const char *TokBegin, const char *TokRangeBegin, const char *TokRangeEnd, unsigned DiagID)
Produce a diagnostic highlighting some portion of a literal.
Definition: LiteralSupport.cpp:79
clang::DeclaratorChunk::FunctionTypeInfo::hasMutableQualifier
bool hasMutableQualifier() const
Determine whether this lambda-declarator contains a 'mutable' qualifier.
Definition: DeclSpec.h:1493
SemaInternal.h
clang::BindingDecl
A binding in a decomposition declaration.
Definition: DeclCXX.h:4008
clang::sema::Capture::isInitCapture
bool isInitCapture() const
Determine whether this capture is an init-capture.
Definition: ScopeInfo.cpp:220
clang::DeclSpec::SCS_static
@ SCS_static
Definition: DeclSpec.h:238
clang::ASTContext::VoidTy
CanQualType VoidTy
Definition: ASTContext.h:1107
clang::sema::LambdaScopeInfo::Mutable
bool Mutable
Whether this is a mutable lambda.
Definition: ScopeInfo.h:850
llvm::SmallVector
Definition: LLVM.h:38
Lookup.h
clang::IdentifierTable::get
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
Definition: IdentifierTable.h:597
clang::Declarator::getSourceRange
SourceRange getSourceRange() const LLVM_READONLY
Get the source range that spans this declarator.
Definition: DeclSpec.h:2004
clang::if
if(T->getSizeExpr()) TRY_TO(TraverseStmt(T -> getSizeExpr()))
Definition: RecursiveASTVisitor.h:1081
clang::SourceLocation
Encodes a location in the source.
Definition: SourceLocation.h:86
clang::ASTContext::getManglingNumberContext
MangleNumberingContext & getManglingNumberContext(const DeclContext *DC)
Retrieve the context for computing mangling numbers in the given DeclContext.
Definition: ASTContext.cpp:12025
clang::VarDecl::isInitCapture
bool isInitCapture() const
Whether this variable is the implicit variable for a lambda init-capture.
Definition: Decl.h:1518
clang::NamedDecl
This represents a decl that may have a name.
Definition: Decl.h:247
clang::ParenListExpr
Definition: Expr.h:5542
clang::SourceRange::getBegin
SourceLocation getBegin() const
Definition: SourceLocation.h:219
clang::AS_private
@ AS_private
Definition: Specifiers.h:114
clang::VarDecl::setInit
void setInit(Expr *I)
Definition: Decl.cpp:2380
TargetInfo.h
clang::LambdaIntroducer::Captures
SmallVector< LambdaCapture, 4 > Captures
Definition: DeclSpec.h:2764
clang::sema::LambdaScopeInfo::NumExplicitCaptures
unsigned NumExplicitCaptures
The number of captures in the Captures list that are explicit captures.
Definition: ScopeInfo.h:847
clang::ASTContext::DeclarationNames
DeclarationNameTable DeclarationNames
Definition: ASTContext.h:664
clang::TypeLocBuilder::getTypeSourceInfo
TypeSourceInfo * getTypeSourceInfo(ASTContext &Context, QualType T)
Creates a TypeSourceInfo for the given type.
Definition: TypeLocBuilder.h:107
clang::MultiExprArg
MutableArrayRef< Expr * > MultiExprArg
Definition: Ownership.h:272
clang::QualType
A (possibly-)qualified type.
Definition: Type.h:737
clang::FunctionDecl::getParamDecl
const ParmVarDecl * getParamDecl(unsigned i) const
Definition: Decl.h:2594
clang::InitializedEntity::InitializeLambdaCapture
static InitializedEntity InitializeLambdaCapture(IdentifierInfo *VarID, QualType FieldType, SourceLocation Loc)
Create the initialization entity for a lambda capture.
Definition: Initialization.h:412
clang::FieldDecl
Represents a member of a struct/union/class.
Definition: Decl.h:2930
clang::FunctionProtoType::ExtProtoInfo::RefQualifier
RefQualifierKind RefQualifier
Definition: Type.h:4104
clang::LookupResult
Represents the results of name lookup.
Definition: Lookup.h:46
clang::Qualifiers
The collection of all-type qualifiers we support.
Definition: Type.h:147
clang::ParmVarDecl
Represents a parameter to a function.
Definition: Decl.h:1712
clang::TargetInfo
Exposes information about the current target.
Definition: TargetInfo.h:205
SemaLambda.h
clang::sema::LambdaScopeInfo::GLTemplateParameterList
TemplateParameterList * GLTemplateParameterList
If this is a generic lambda, and the template parameter list has been created (from the TemplateParam...
Definition: ScopeInfo.h:875
clang::DeclarationNameTable::getCXXConversionFunctionName
DeclarationName getCXXConversionFunctionName(CanQualType Ty)
Returns the name of a C++ conversion function for the given Type.
Definition: DeclarationName.cpp:343
clang::ASTContext::getFunctionType
QualType getFunctionType(QualType ResultTy, ArrayRef< QualType > Args, const FunctionProtoType::ExtProtoInfo &EPI) const
Return a normal function type with a typed argument list.
Definition: ASTContext.h:1561
clang::Type::containsUnexpandedParameterPack
bool containsUnexpandedParameterPack() const
Whether this type is or contains an unexpanded parameter pack, used to support C++0x variadic templat...
Definition: Type.h:2004
clang::SourceRange::isValid
bool isValid() const
Definition: SourceLocation.h:225
clang::sema::CapturingScopeInfo::ImplicitCaptureStyle
ImplicitCaptureStyle
Definition: ScopeInfo.h:671
clang::DeclSpec::SCS_unspecified
@ SCS_unspecified
Definition: DeclSpec.h:235
clang::Sema::createLambdaClosureType
CXXRecordDecl * createLambdaClosureType(SourceRange IntroducerRange, TypeSourceInfo *Info, unsigned LambdaDependencyKind, LambdaCaptureDefault CaptureDefault)
Create a new lambda closure type.
Definition: SemaLambda.cpp:242
llvm::Optional< unsigned >
clang::getLambdaAwareParentOfDeclContext
DeclContext * getLambdaAwareParentOfDeclContext(DeclContext *DC)
Definition: ASTLambda.h:80
clang::Type::isVoidType
bool isVoidType() const
Definition: Type.h:7180
clang::InitializationKind::CreateDirect
static InitializationKind CreateDirect(SourceLocation InitLoc, SourceLocation LParenLoc, SourceLocation RParenLoc)
Create a direct initialization.
Definition: Initialization.h:627
clang::QualType::isVolatileQualified
bool isVolatileQualified() const
Determine whether this type is volatile-qualified.
Definition: Type.h:6705
clang::CPlusPlus14
@ CPlusPlus14
Definition: LangStandard.h:55
DeclSpec.h
clang::CXXScopeSpec
Represents a C++ nested-name-specifier or a global scope specifier.
Definition: DeclSpec.h:65
clang::Sema::ActOnStartOfLambdaDefinition
void ActOnStartOfLambdaDefinition(LambdaIntroducer &Intro, Declarator &ParamInfo, Scope *CurScope)
ActOnStartOfLambdaDefinition - This is called just before we start parsing the body of a lambda; it a...
Definition: SemaLambda.cpp:897
clang::sema::Capture
Definition: ScopeInfo.h:533
ASTLambda.h
clang::Sema::BuildCaptureField
FieldDecl * BuildCaptureField(RecordDecl *RD, const sema::Capture &Capture)
Build a FieldDecl suitable to hold the given capture.
Definition: SemaLambda.cpp:1742
clang::CXXRecordDecl::LambdaDependencyKind
LambdaDependencyKind
Definition: DeclCXX.h:280
clang::DeclContext::getLexicalParent
DeclContext * getLexicalParent()
getLexicalParent - Returns the containing lexical DeclContext.
Definition: DeclBase.h:1939
clang::InitializationSequence
Describes the sequence of initializations required to initialize a given object or reference with a s...
Definition: Initialization.h:788
clang::ASTContext::getPackExpansionType
QualType getPackExpansionType(QualType Pattern, Optional< unsigned > NumExpansions, bool ExpectPackInType=true)
Form a pack expansion type with the given pattern.
Definition: ASTContext.cpp:5264
clang::FunctionTemplateDecl::Create
static FunctionTemplateDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name, TemplateParameterList *Params, NamedDecl *Decl)
Create a function template node.
Definition: DeclTemplate.cpp:377
clang::DeclaratorChunk::FunctionTypeInfo::getTrailingReturnType
ParsedType getTrailingReturnType() const
Get the trailing-return-type for this function declarator.
Definition: DeclSpec.h:1524
clang::sema::LambdaScopeInfo::RequiresClause
ExprResult RequiresClause
The requires-clause immediately following the explicit template parameter list, if any.
Definition: ScopeInfo.h:870
clang::sema::LambdaScopeInfo::finishedExplicitCaptures
void finishedExplicitCaptures()
Note when all explicit captures have been added.
Definition: ScopeInfo.h:918
clang::MangleNumberingContext::getDeviceManglingNumber
virtual unsigned getDeviceManglingNumber(const CXXMethodDecl *)
Retrieve the mangling number of a new lambda expression with the given call operator within the devic...
Definition: MangleNumberingContext.h:57
clang::Sema::BuildLambdaExpr
ExprResult BuildLambdaExpr(SourceLocation StartLoc, SourceLocation EndLoc, sema::LambdaScopeInfo *LSI)
Complete a lambda-expression having processed and attached the lambda body.
Definition: SemaLambda.cpp:1790
clang::DeclarationName
The name of a declaration.
Definition: DeclarationName.h:144
clang::sema::FunctionScopeInfo::Returns
SmallVector< ReturnStmt *, 4 > Returns
The list of return statements that occur within the function or block, if there is any chance of appl...
Definition: ScopeInfo.h:205
clang::ASTContext::getTranslationUnitDecl
TranslationUnitDecl * getTranslationUnitDecl() const
Definition: ASTContext.h:1089
clang::sema::LambdaScopeInfo::CallOperator
CXXMethodDecl * CallOperator
The lambda's compiler-generated operator().
Definition: ScopeInfo.h:836
clang::sema::Capture::isCopyCapture
bool isCopyCapture() const
Definition: ScopeInfo.h:622
clang::Decl::markUsed
void markUsed(ASTContext &C)
Mark the declaration used, in the sense of odr-use.
Definition: DeclBase.cpp:472
clang::LambdaCaptureInitKind::DirectInit
@ DirectInit
[a(b)]
clang::CC_X86StdCall
@ CC_X86StdCall
Definition: Specifiers.h:268
clang::FunctionDecl::isConsteval
bool isConsteval() const
Definition: Decl.h:2366
clang::EnumDecl
Represents an enum.
Definition: Decl.h:3705
clang::FunctionProtoType::isVariadic
bool isVariadic() const
Whether this function prototype is variadic.
Definition: Type.h:4349
clang::ASTContext::getCanonicalFunctionResultType
CanQualType getCanonicalFunctionResultType(QualType ResultType) const
Adjust the given function result type.
Definition: ASTContext.cpp:4376
clang::Declarator::getTrailingRequiresClause
Expr * getTrailingRequiresClause()
Sets a trailing requires clause for this declarator.
Definition: DeclSpec.h:2538
clang::Sema::Context
ASTContext & Context
Definition: Sema.h:409
clang::Type
The base class of the type hierarchy.
Definition: Type.h:1565
clang::FieldDecl::Create
static FieldDecl * Create(const ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, Expr *BW, bool Mutable, InClassInitStyle InitStyle)
Definition: Decl.cpp:4275
clang::ReturnStmt::setRetValue
void setRetValue(Expr *E)
Definition: Stmt.h:2831
clang::ExprError
ExprResult ExprError()
Definition: Ownership.h:278
clang::ConditionalOperator
ConditionalOperator - The ?: ternary operator.
Definition: Expr.h:4150
clang::CXXMethodDecl::Create
static CXXMethodDecl * Create(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo, StorageClass SC, bool UsesFPIntrin, bool isInline, ConstexprSpecKind ConstexprKind, SourceLocation EndLocation, Expr *TrailingRequiresClause=nullptr)
Definition: DeclCXX.cpp:2216
clang::sema::CapturingScopeInfo::ImpCap_Block
@ ImpCap_Block
Definition: ScopeInfo.h:672
clang::CPlusPlus17
@ CPlusPlus17
Definition: LangStandard.h:56
clang::ASTContext::getBlockPointerType
QualType getBlockPointerType(QualType T) const
Return the uniqued reference to the type for a block of the specified type.
Definition: ASTContext.cpp:3433
clang::Sema::getLangOpts
const LangOptions & getLangOpts() const
Definition: Sema.h:1630
clang::DeclarationNameLoc::makeNamedTypeLoc
static DeclarationNameLoc makeNamedTypeLoc(TypeSourceInfo *TInfo)
Construct location information for a constructor, destructor or conversion operator.
Definition: DeclarationName.h:738
clang::sema::LambdaScopeInfo::Lambda
CXXRecordDecl * Lambda
The class that describes the lambda.
Definition: ScopeInfo.h:833
clang::Declarator::getDeclSpec
const DeclSpec & getDeclSpec() const
getDeclSpec - Return the declaration-specifier that this declarator was declared with.
Definition: DeclSpec.h:1969
clang::CXXRecordDecl::CreateLambda
static CXXRecordDecl * CreateLambda(const ASTContext &C, DeclContext *DC, TypeSourceInfo *Info, SourceLocation Loc, unsigned DependencyKind, bool IsGeneric, LambdaCaptureDefault CaptureDefault)
Definition: DeclCXX.cpp:148
clang::VarDecl::isParameterPack
bool isParameterPack() const
Determine whether this variable is actually a function parameter pack or init-capture pack.
Definition: Decl.cpp:2579
clang::CXXRecordDecl::LDK_Unknown
@ LDK_Unknown
Definition: DeclCXX.h:281
clang::FunctionTemplateDecl
Declaration of a template function.
Definition: DeclTemplate.h:1006
clang::sema::CapturingScopeInfo::addCapture
void addCapture(ValueDecl *Var, bool isBlock, bool isByref, bool isNested, SourceLocation Loc, SourceLocation EllipsisLoc, QualType CaptureType, bool Invalid)
Definition: ScopeInfo.h:699
llvm::MutableArrayRef
Definition: LLVM.h:35
clang::Type::isReferenceType
bool isReferenceType() const
Definition: Type.h:6895
clang::TypeLocBuilder::push
TyLocType push(QualType T)
Pushes space for a new TypeLoc of the given type.
Definition: TypeLocBuilder.h:99
clang::FunctionDecl::setConstexprKind
void setConstexprKind(ConstexprSpecKind CSK)
Definition: Decl.h:2357
clang::PackExpansionTypeLoc
Definition: TypeLoc.h:2521
clang::Sema::ActOnLambdaError
void ActOnLambdaError(SourceLocation StartLoc, Scope *CurScope, bool IsInstantiation=false)
ActOnLambdaError - If there is an error parsing a lambda, this callback is invoked to pop the informa...
Definition: SemaLambda.cpp:1288
getLambdaConversionFunctionCallConv
static CallingConv getLambdaConversionFunctionCallConv(Sema &S, const FunctionProtoType *CallOpProto)
Definition: SemaLambda.cpp:1360
clang::CompoundStmt
CompoundStmt - This represents a group of statements like { stmt stmt }.
Definition: Stmt.h:1410
clang::PackExpansionType
Represents a pack expansion of types.
Definition: Type.h:5830
clang::FTIHasNonVoidParameters
bool FTIHasNonVoidParameters(const DeclaratorChunk::FunctionTypeInfo &FTI)
Definition: SemaInternal.h:36
clang::InitializedEntity::InitializeLambdaToBlock
static InitializedEntity InitializeLambdaToBlock(SourceLocation BlockVarLoc, QualType Type)
Definition: Initialization.h:314
clang::CXXMethodDecl::isInstance
bool isInstance() const
Definition: DeclCXX.h:2010
clang::Scope::getTemplateParamParent
Scope * getTemplateParamParent()
Definition: Scope.h:289
clang::BlockDecl
Represents a block literal declaration, which is like an unnamed FunctionDecl.
Definition: Decl.h:4283
clang::QualType::getAddressSpace
LangAS getAddressSpace() const
Return the address space of this type.
Definition: Type.h:6756
clang::ASTContext::getDefaultCallingConvention
CallingConv getDefaultCallingConvention(bool IsVariadic, bool IsCXXMethod, bool IsBuiltin=false) const
Retrieves the default calling convention for the current target.
Definition: ASTContext.cpp:11828
clang::BinaryOperator
A builtin binary operation expression such as "x + y" or "x <= y".
Definition: Expr.h:3812
clang::Decl::setAccess
void setAccess(AccessSpecifier AS)
Definition: DeclBase.h:486
Id
int Id
Definition: ASTDiff.cpp:189
clang::LambdaExpr
A C++ lambda expression, which produces a function object (of unspecified type) that can be invoked l...
Definition: ExprCXX.h:1872
clang::Scope
Scope - A scope is a transient data structure that is used while parsing the program.
Definition: Scope.h:40
clang::sema::Capture::getCapturedVLAType
const VariableArrayType * getCapturedVLAType() const
Definition: ScopeInfo.h:648
clang::sema::LambdaScopeInfo::PotentialThisCaptureLocation
SourceLocation PotentialThisCaptureLocation
Definition: ScopeInfo.h:910
clang::SourceRange::getEnd
SourceLocation getEnd() const
Definition: SourceLocation.h:220
clang::sema::Capture::getCaptureType
QualType getCaptureType() const
Retrieve the capture type for this capture, which is effectively the type of the non-static data memb...
Definition: ScopeInfo.h:663
clang::AS_public
@ AS_public
Definition: Specifiers.h:112
clang::sema::CapturingScopeInfo::ImpCap_None
@ ImpCap_None
Definition: ScopeInfo.h:672
clang::ASTContext::DependentTy
CanQualType DependentTy
Definition: ASTContext.h:1135
clang::FPOptionsOverride
Represents difference between two FPOptions values.
Definition: LangOptions.h:803
clang::ASTContext
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:209
clang::ExprResult
ActionResult< Expr * > ExprResult
Definition: Ownership.h:262
clang::DeclContextLookupResult::front
reference front() const
Definition: DeclBase.h:1357
clang::CPlusPlus
@ CPlusPlus
Definition: LangStandard.h:53
clang::sema::Capture::isInvalid
bool isInvalid() const
Definition: ScopeInfo.h:629
clang::DeclarationNameTable::getCXXOperatorName
DeclarationName getCXXOperatorName(OverloadedOperatorKind Op)
Get the name of the overloadable C++ operator corresponding to Op.
Definition: DeclarationName.h:648
clang::Sema::getLambdaConversionFunctionResultType
QualType getLambdaConversionFunctionResultType(const FunctionProtoType *CallOpType, CallingConv CC)
Get the return type to use for a lambda's conversion function(s) to function pointer type,...
Definition: SemaLambda.cpp:1375
clang::Sema::TryCapture_Implicit
@ TryCapture_Implicit
Definition: Sema.h:5394
clang::DeclaratorChunk::FunctionTypeInfo::getOrCreateMethodQualifiers
DeclSpec & getOrCreateMethodQualifiers()
Definition: DeclSpec.h:1432
clang::sema::Capture::isNonODRUsed
bool isNonODRUsed() const
Definition: ScopeInfo.h:635
clang::FunctionDecl::getBody
Stmt * getBody(const FunctionDecl *&Definition) const
Retrieve the body (definition) of the function.
Definition: Decl.cpp:3116
clang::DeclaratorChunk::FunctionTypeInfo
Definition: DeclSpec.h:1299
clang::Type::getAs
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:7386
clang::Decl::isInvalidDecl
bool isInvalidDecl() const
Definition: DeclBase.h:571
clang::FunctionType::getCallConv
CallingConv getCallConv() const
Definition: Type.h:3951
clang::TargetInfo::CCCR_OK
@ CCCR_OK
Definition: TargetInfo.h:1553
clang::VarDecl::setInitCapture
void setInitCapture(bool IC)
Definition: Decl.h:1521
clang::LambdaCaptureDefault
LambdaCaptureDefault
The default, if any, capture method for a lambda expression.
Definition: Lambda.h:22
getGenericLambdaTemplateParameterList
static TemplateParameterList * getGenericLambdaTemplateParameterList(LambdaScopeInfo *LSI, Sema &SemaRef)
Definition: SemaLambda.cpp:228
clang::Stmt::getEndLoc
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Stmt.cpp:348
clang::ASTContext::getAutoDeductType
QualType getAutoDeductType() const
C++11 deduction pattern for 'auto' type.
Definition: ASTContext.cpp:5903
clang::ParenListExpr::getNumExprs
unsigned getNumExprs() const
Return the number of expressions in this paren list.
Definition: Expr.h:5568
clang::ImplicitCastExpr::Create
static ImplicitCastExpr * Create(const ASTContext &Context, QualType T, CastKind Kind, Expr *Operand, const CXXCastPath *BasePath, ExprValueKind Cat, FPOptionsOverride FPO)
Definition: Expr.cpp:2062
clang::DeclContext::isTranslationUnit
bool isTranslationUnit() const
Definition: DeclBase.h:1998
clang::FunctionProtoType::ExtProtoInfo::ExtInfo
FunctionType::ExtInfo ExtInfo
Definition: Type.h:4100
clang::sema::CapturingScopeInfo::ImpCap_CapturedRegion
@ ImpCap_CapturedRegion
Definition: ScopeInfo.h:673
clang::Sema::CheckCXXThisCapture
bool CheckCXXThisCapture(SourceLocation Loc, bool Explicit=false, bool BuildAndDiagnose=true, const unsigned *const FunctionScopeIndexToStopAt=nullptr, bool ByCopy=false)
Make sure the value of 'this' is actually available in the current context, if it is a potentially ev...
Definition: SemaExprCXX.cpp:1262
clang::CPlusPlus20
@ CPlusPlus20
Definition: LangStandard.h:57
clang::LCD_ByCopy
@ LCD_ByCopy
Definition: Lambda.h:24
clang::CallingConv
CallingConv
CallingConv - Specifies the calling convention that a function uses.
Definition: Specifiers.h:266
clang::VarDecl
Represents a variable declaration or definition.
Definition: Decl.h:906
clang::FunctionProtoType::getParamTypes
ArrayRef< QualType > getParamTypes() const
Definition: Type.h:4234
clang::ConstexprSpecKind::Constexpr
@ Constexpr
clang::LambdaIntroducer::Default
LambdaCaptureDefault Default
Definition: DeclSpec.h:2763
clang::TemplateParameterList
Stores a list of template parameters for a TemplateDecl and its derived classes.
Definition: DeclTemplate.h:70
clang::DeclSpec::getStorageClassSpec
SCS getStorageClassSpec() const
Definition: DeclSpec.h:459
clang::ExprWithCleanups
Represents an expression – generally a full-expression – that introduces cleanups to be run at the en...
Definition: ExprCXX.h:3366
clang::ASTContext::getCanonicalType
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
Definition: ASTContext.h:2528
clang::Type::getAsCXXRecordDecl
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
Definition: Type.cpp:1760
clang::RQ_None
@ RQ_None
No ref-qualifier was provided.
Definition: Type.h:1518
clang::Sema::getCurFPFeatures
FPOptions & getCurFPFeatures()
Definition: Sema.h:1632
clang::FunctionType::ExtInfo::withCallingConv
ExtInfo withCallingConv(CallingConv cc) const
Definition: Type.h:3901
clang::EnumConstantDecl
An instance of this object exists for each enum constant that is defined.
Definition: Decl.h:3145
clang::FunctionDecl::setParams
void setParams(ArrayRef< ParmVarDecl * > NewParamInfo)
Definition: Decl.h:2602
ExprCXX.h
clang::LCD_None
@ LCD_None
Definition: Lambda.h:23
clang::DeclContext::isRecord
bool isRecord() const
Definition: DeclBase.h:2002
clang::getStackIndexOfNearestEnclosingCaptureCapableLambda
Optional< unsigned > getStackIndexOfNearestEnclosingCaptureCapableLambda(ArrayRef< const sema::FunctionScopeInfo * > FunctionScopes, VarDecl *VarToCapture, Sema &S)
Examines the FunctionScopeInfo stack to determine the nearest enclosing lambda (to the current lambda...
Definition: SemaLambda.cpp:173
clang::DeclaratorChunk::FunctionTypeInfo::Params
ParamInfo * Params
Params - This is a pointer to a new[]'d array of ParamInfo objects that describe the parameters speci...
Definition: DeclSpec.h:1363
clang::Decl::setImplicit
void setImplicit(bool I=true)
Definition: DeclBase.h:577
clang::sema::CapturingScopeInfo::ImpCaptureStyle
ImplicitCaptureStyle ImpCaptureStyle
Definition: ScopeInfo.h:676
clang::Declarator::isFunctionDeclarator
bool isFunctionDeclarator(unsigned &idx) const
isFunctionDeclarator - This method returns true if the declarator is a function declarator (looking t...
Definition: DeclSpec.h:2361
clang::VarDecl::Create
static VarDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, const IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, StorageClass S)
Definition: Decl.cpp:2076
clang::TypeLocBuilder
Definition: TypeLocBuilder.h:22
clang::DeclaratorChunk::ParamInfo::Param
Decl * Param
Definition: DeclSpec.h:1277
clang::AutoTypeLoc
Definition: TypeLoc.h:2115
clang::SC_Static
@ SC_Static
Definition: Specifiers.h:240
clang::sema::CapturingScopeInfo::ImpCap_LambdaByval
@ ImpCap_LambdaByval
Definition: ScopeInfo.h:672
clang::TemplateDecl::getTemplateParameters
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
Definition: DeclTemplate.h:427
clang::BlockDecl::Create
static BlockDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L)
Definition: Decl.cpp:5067
clang::CC_C
@ CC_C
Definition: Specifiers.h:267
clang::FullExpr::getSubExpr
const Expr * getSubExpr() const
Definition: Expr.h:1026
clang::LangAS
LangAS
Defines the address space values used by the address space qualifier of QualType.
Definition: AddressSpaces.h:25
clang::Sema::getCurGenericLambda
sema::LambdaScopeInfo * getCurGenericLambda()
Retrieve the current generic lambda info, if any.
Definition: Sema.cpp:2355
clang::Type::castAs
const T * castAs() const
Member-template castAs<specific type>.
Definition: Type.h:7453
clang::ConstexprSpecKind
ConstexprSpecKind
Define the kind of constexpr specifier.
Definition: Specifiers.h:32
clang::Sema::addInitCapture
void addInitCapture(sema::LambdaScopeInfo *LSI, VarDecl *Var)
Add an init-capture to a lambda scope.
Definition: SemaLambda.cpp:890
clang::VarDecl::ListInit
@ ListInit
Direct list-initialization (C++11)
Definition: Decl.h:917
clang::InitializationSequence::Perform
ExprResult Perform(Sema &S, const InitializedEntity &Entity, const InitializationKind &Kind, MultiExprArg Args, QualType *ResultType=nullptr)
Perform the actual initialization of the given entity based on the computed initialization sequence.
Definition: SemaInit.cpp:8056
clang::CXXRecordDecl
Represents a C++ struct/union/class.
Definition: DeclCXX.h:254
P
StringRef P
Definition: ASTMatchersInternal.cpp:563
clang::Type::isDependentType
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
Definition: Type.h:2304
clang::VK_PRValue
@ VK_PRValue
A pr-value expression (in the C++11 taxonomy) produces a temporary value.
Definition: Specifiers.h:123
clang::LambdaCaptureKind
LambdaCaptureKind
The different capture forms in a lambda introducer.
Definition: Lambda.h:33
clang::LCD_ByRef
@ LCD_ByRef
Definition: Lambda.h:25
clang::sema::CapturingScopeInfo::Captures
SmallVector< Capture, 4 > Captures
Captures - The captures.
Definition: ScopeInfo.h:689
clang::LookupResult::empty
bool empty() const
Return true if no decls were found.
Definition: Lookup.h:339
clang::LambdaCaptureInitKind::ListInit
@ ListInit
[a{b}]
clang::Declarator::getFunctionTypeInfo
DeclaratorChunk::FunctionTypeInfo & getFunctionTypeInfo()
getFunctionTypeInfo - Retrieves the function type info object (looking through parentheses).
Definition: DeclSpec.h:2392
clang::sema::LambdaScopeInfo::Cleanup
CleanupInfo Cleanup
Whether any of the capture expressions requires cleanups.
Definition: ScopeInfo.h:856
clang::ActionResult::get
PtrTy get() const
Definition: Ownership.h:169
clang::LCK_ByRef
@ LCK_ByRef
Capturing by reference.
Definition: Lambda.h:37
clang::NamedDecl::getIdentifier
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
Definition: Decl.h:268
clang::ValueDecl
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition: Decl.h:701
clang::InventedTemplateParameterInfo::TemplateParams
SmallVector< NamedDecl *, 4 > TemplateParams
Store the list of the template parameters for a generic lambda or an abbreviated function template.
Definition: DeclSpec.h:2804
clang::VarDecl::getStorageClass
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Definition: Decl.h:1115
clang::DeclContext::addDecl
void addDecl(Decl *D)
Add the declaration D into this context.
Definition: DeclBase.cpp:1606
isInInlineFunction
static bool isInInlineFunction(const DeclContext *DC)
Determine whether the given context is or is enclosed in an inline function.
Definition: SemaLambda.cpp:261
clang::FunctionProtoType
Represents a prototype with parameter type info, e.g.
Definition: Type.h:4016
clang::ASTContext::Idents
IdentifierTable & Idents
Definition: ASTContext.h:660
clang::DeclContext::getParent
DeclContext * getParent()
getParent - Returns the containing DeclContext.
Definition: DeclBase.h:1923
clang::CXXConversionDecl::getConversionType
QualType getConversionType() const
Returns the type that this conversion function is converting to.
Definition: DeclCXX.h:2806
clang::TypeLoc::getAs
T getAs() const
Convert to the specified TypeLoc type, returning a null TypeLoc if this TypeLoc is not of the desired...
Definition: TypeLoc.h:88
clang::sema::CapturingScopeInfo::isCaptured
bool isCaptured(ValueDecl *Var) const
Determine whether the given variable has been captured.
Definition: ScopeInfo.h:726
clang::sema::Capture::isVLATypeCapture
bool isVLATypeCapture() const
Definition: ScopeInfo.h:625
clang::QualType::isNull
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition: Type.h:802
clang::Sema::BuildCaptureInit
ExprResult BuildCaptureInit(const sema::Capture &Capture, SourceLocation ImplicitCaptureLoc, bool IsOpenMPMapping=false)
Initialize the given capture with a suitable expression.
Definition: SemaLambda.cpp:1610
clang::BlockExpr
BlockExpr - Adaptor class for mixing a BlockDecl with expressions.
Definition: Expr.h:5975
clang::StmtExpr
StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
Definition: Expr.h:4354
llvm::ArrayRef
Definition: LLVM.h:34
clang::Decl
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:83
Scope.h
clang::LCK_StarThis
@ LCK_StarThis
Capturing the *this object by copy.
Definition: Lambda.h:35
clang::Sema
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:358
addBlockPointerConversion
static void addBlockPointerConversion(Sema &S, SourceRange IntroducerRange, CXXRecordDecl *Class, CXXMethodDecl *CallOperator)
Add a lambda's conversion to block pointer.
Definition: SemaLambda.cpp:1576
clang::VarDecl::setInitStyle
void setInitStyle(InitializationStyle Style)
Definition: Decl.h:1392
clang::Qualifiers::addConst
void addConst()
Definition: Type.h:267
clang::hasWeakerNullability
bool hasWeakerNullability(NullabilityKind L, NullabilityKind R)
Return true if L has a weaker nullability annotation than R.
Definition: Specifiers.h:339
clang::DeclSpec::getConstexprSpecifier
ConstexprSpecKind getConstexprSpecifier() const
Definition: DeclSpec.h:777
clang::DeclContext::isFileContext
bool isFileContext() const
Definition: DeclBase.h:1993
clang::CC_X86VectorCall
@ CC_X86VectorCall
Definition: Specifiers.h:271
clang::sema::LambdaScopeInfo::IntroducerRange
SourceRange IntroducerRange
Source range covering the lambda introducer [...].
Definition: ScopeInfo.h:839
clang::IdentifierInfo
One of these records is kept for each identifier that is lexed.
Definition: IdentifierTable.h:85
clang::Sema::DiagnoseUnusedLambdaCapture
bool DiagnoseUnusedLambdaCapture(SourceRange CaptureRange, const sema::Capture &From)
Diagnose if an explicit lambda capture is unused.
Definition: SemaLambda.cpp:1722
clang::ASTContext::getTargetInfo
const TargetInfo & getTargetInfo() const
Definition: ASTContext.h:773
findEnumForBlockReturn
static EnumDecl * findEnumForBlockReturn(Expr *E)
If this expression is an enumerator-like expression of some type T, return the type T; otherwise,...
Definition: SemaLambda.cpp:583
clang::Sema::addLambdaParameters
void addLambdaParameters(ArrayRef< LambdaIntroducer::LambdaCapture > Captures, CXXMethodDecl *CallOperator, Scope *CurScope)
Introduce the lambda parameters into scope.
Definition: SemaLambda.cpp:547
clang::ObjCPropertyAttribute::Kind
Kind
Definition: DeclObjCCommon.h:22
clang::DeclaratorChunk::FunctionTypeInfo::getTrailingReturnTypeLoc
SourceLocation getTrailingReturnTypeLoc() const
Get the trailing-return-type location for this function declarator.
Definition: DeclSpec.h:1530
clang::InitializationKind
Describes the kind of initialization being performed, along with location information for tokens rela...
Definition: Initialization.h:566
clang::ActionResult< Expr * >
clang::LCK_ByCopy
@ LCK_ByCopy
Capturing by copy (a.k.a., by value)
Definition: Lambda.h:36
clang::FunctionProtoType::ExceptionSpecInfo::Type
ExceptionSpecificationType Type
The kind of exception specification this is.
Definition: Type.h:4075
clang::LCK_VLAType
@ LCK_VLAType
Capturing variable-length array type.
Definition: Lambda.h:38
clang::MangleNumberingContext
Keeps track of the mangled names of lambda expressions and block literals within a particular context...
Definition: MangleNumberingContext.h:29
clang::LambdaCaptureInitKind::NoInit
@ NoInit
[a]
clang::FunctionProtoType::ExtProtoInfo::ExceptionSpec
ExceptionSpecInfo ExceptionSpec
Definition: Type.h:4105
clang::DeclFilterCCC
Simple template class for restricting typo correction candidates to ones having a single Decl* of the...
Definition: TypoCorrection.h:366
clang::InitializationKind::CreateDirectList
static InitializationKind CreateDirectList(SourceLocation InitLoc)
Definition: Initialization.h:634
clang::VarDecl::InitializationStyle
InitializationStyle
Initialization styles.
Definition: Decl.h:909
clang::Sema::tryCaptureVariable
bool tryCaptureVariable(ValueDecl *Var, SourceLocation Loc, TryCaptureKind Kind, SourceLocation EllipsisLoc, bool BuildAndDiagnose, QualType &CaptureType, QualType &DeclRefType, const unsigned *const FunctionScopeIndexToStopAt)
Try to capture the given variable.
Definition: SemaExpr.cpp:18793
clang::sema::LambdaScopeInfo
Definition: ScopeInfo.h:829
ScopeInfo.h
clang::LangAS::Default
@ Default
clang::Type::getBaseElementTypeUnsafe
const Type * getBaseElementTypeUnsafe() const
Get the base element type of this type, potentially discarding type qualifiers.
Definition: Type.h:7336
clang::sema::LambdaScopeInfo::ContainsUnexpandedParameterPack
bool ContainsUnexpandedParameterPack
Whether the lambda contains an unexpanded parameter pack.
Definition: ScopeInfo.h:859
clang::LambdaIntroducer::DefaultLoc
SourceLocation DefaultLoc
Definition: DeclSpec.h:2762
clang::sema::CapturingScopeInfo::ImpCap_LambdaByref
@ ImpCap_LambdaByref
Definition: ScopeInfo.h:672
clang::interp::This
bool This(InterpState &S, CodePtr OpPC)
Definition: Interp.h:1137
clang::VarDecl::CInit
@ CInit
C-style initialization with assignment.
Definition: Decl.h:911
clang::Decl::isParameterPack
bool isParameterPack() const
Whether this declaration is a parameter pack.
Definition: DeclBase.cpp:220
clang::FunctionProtoType::ExtProtoInfo
Extra information about a function prototype.
Definition: Type.h:4099
clang::CXXMethodDecl::isConst
bool isConst() const
Definition: DeclCXX.h:2024
clang::Expr::IgnoreParens
Expr * IgnoreParens() LLVM_READONLY
Skip past any parentheses which might surround this expression until reaching a fixed point.
Definition: Expr.cpp:3031
clang
Definition: CalledOnceCheck.h:17
clang::DeclContext::lookup
lookup_result lookup(DeclarationName Name) const
lookup - Find the declarations (if any) with the given Name in this context.
Definition: DeclBase.cpp:1692
clang::FunctionProtoType::ExtProtoInfo::HasTrailingReturn
bool HasTrailingReturn
Definition: Type.h:4102
clang::Type::isIntegralOrUnscopedEnumerationType
bool isIntegralOrUnscopedEnumerationType() const
Determine whether this type is an integral or unscoped enumeration type.
Definition: Type.cpp:1944
clang::FunctionDecl::setDescribedFunctionTemplate
void setDescribedFunctionTemplate(FunctionTemplateDecl *Template)
Definition: Decl.cpp:3807
clang::Sema::createLambdaInitCaptureVarDecl
VarDecl * createLambdaInitCaptureVarDecl(SourceLocation Loc, QualType InitCaptureType, SourceLocation EllipsisLoc, IdentifierInfo *Id, unsigned InitStyle, Expr *Init)
Create a dummy variable within the declcontext of the lambda's call operator, for name lookup purpose...
Definition: SemaLambda.cpp:862
clang::sema::LambdaScopeInfo::ExplicitCaptureRanges
llvm::DenseMap< unsigned, SourceRange > ExplicitCaptureRanges
A map of explicit capture indices to their introducer source ranges.
Definition: ScopeInfo.h:899
clang::DeclaratorContext::Block
@ Block
clang::Stmt
Stmt - This represents one statement.
Definition: Stmt.h:71
clang::EST_BasicNoexcept
@ EST_BasicNoexcept
noexcept
Definition: ExceptionSpecificationType.h:26
clang::Sema::buildLambdaScope
void buildLambdaScope(sema::LambdaScopeInfo *LSI, CXXMethodDecl *CallOperator, SourceRange IntroducerRange, LambdaCaptureDefault CaptureDefault, SourceLocation CaptureDefaultLoc, bool ExplicitParams, bool ExplicitResultType, bool Mutable)
Endow the lambda scope info with the relevant properties.
Definition: SemaLambda.cpp:489
clang::Declarator
Information about one declarator, including the parsed type information and the identifier.
Definition: DeclSpec.h:1834
clang::Sema::handleLambdaNumbering
void handleLambdaNumbering(CXXRecordDecl *Class, CXXMethodDecl *Method, Optional< std::tuple< bool, unsigned, unsigned, Decl * >> Mangling=None)
Number lambda for linkage purposes if necessary.
Definition: SemaLambda.cpp:434
clang::LambdaCaptureInitKind::CopyInit
@ CopyInit
[a = b], [a = {b}]
clang::ReturnStmt::getBeginLoc
SourceLocation getBeginLoc() const
Definition: Stmt.h:2855
clang::Sema::CaptureHasSideEffects
bool CaptureHasSideEffects(const sema::Capture &From)
Does copying/destroying the captured variable have side effects?
Definition: SemaLambda.cpp:1697
clang::Expr::getType
QualType getType() const
Definition: Expr.h:141
clang::SourceLocation::isValid
bool isValid() const
Return true if this is a valid SourceLocation object.
Definition: SourceLocation.h:110
findCommonEnumForBlockReturns
static EnumDecl * findCommonEnumForBlockReturns(ArrayRef< ReturnStmt * > returns)
Attempt to find a common type T for which all of the returned expressions in a block are enumerator-l...
Definition: SemaLambda.cpp:655
clang::Attr
Attr - This represents one attribute.
Definition: Attr.h:40
clang::Qualifiers::addAddressSpace
void addAddressSpace(LangAS space)
Definition: Type.h:404
clang::TypeSourceInfo
A container of type source information.
Definition: Type.h:6593
clang::FunctionType::getReturnType
QualType getReturnType() const
Definition: Type.h:3940
clang::OverloadCandidateParamOrder::Normal
@ Normal
clang::NamedDecl::getDeclName
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Definition: Decl.h:313
clang::CXXRecordDecl::LDK_AlwaysDependent
@ LDK_AlwaysDependent
Definition: DeclCXX.h:282
clang::FixItHint::CreateRemoval
static FixItHint CreateRemoval(CharSourceRange RemoveRange)
Create a code modification hint that removes the given source range.
Definition: Diagnostic.h:123
clang::sema::CapturingScopeInfo::HasImplicitReturnType
bool HasImplicitReturnType
Definition: ScopeInfo.h:693
clang::DeclContext::isDependentContext
bool isDependentContext() const
Determines whether this context is dependent on a template parameter.
Definition: DeclBase.cpp:1173
addFunctionPointerConversions
static void addFunctionPointerConversions(Sema &S, SourceRange IntroducerRange, CXXRecordDecl *Class, CXXMethodDecl *CallOperator)
Add a lambda's conversion to function pointers, as described in C++11 [expr.prim.lambda]p6.
Definition: SemaLambda.cpp:1560
clang::SC_Auto
@ SC_Auto
Definition: Specifiers.h:244
clang::FunctionProtoType::ExtProtoInfo::TypeQuals
Qualifiers TypeQuals
Definition: Type.h:4103
clang::LCK_This
@ LCK_This
Capturing the *this object by reference.
Definition: Lambda.h:34
clang::sema::CapturingScopeInfo
Definition: ScopeInfo.h:666
clang::InitializedEntity
Describes an entity that is being initialized.
Definition: Initialization.h:47
clang::FunctionDecl::isVariadic
bool isVariadic() const
Whether this function is variadic.
Definition: Decl.cpp:3004
clang::ParenListExpr::getExprs
Expr ** getExprs()
Definition: Expr.h:5579
clang::LookupResult::getAsSingle
DeclClass * getAsSingle() const
Definition: Lookup.h:533
clang::FunctionTypeLoc::getReturnLoc
TypeLoc getReturnLoc() const
Definition: TypeLoc.h:1467
mapImplicitCaptureStyle
static LambdaCaptureDefault mapImplicitCaptureStyle(CapturingScopeInfo::ImplicitCaptureStyle ICS)
Definition: SemaLambda.cpp:1682
clang::TypeSpecTypeLoc::setNameLoc
void setNameLoc(SourceLocation Loc)
Definition: TypeLoc.h:527
clang::ImplicitCastExpr
ImplicitCastExpr - Allows us to explicitly represent implicit type conversions, which have no direct ...
Definition: Expr.h:3624
clang::sema::Capture::isBlockCapture
bool isBlockCapture() const
Definition: ScopeInfo.h:624
clang::ASTContext::getTrivialTypeSourceInfo
TypeSourceInfo * getTrivialTypeSourceInfo(QualType T, SourceLocation Loc=SourceLocation()) const
Allocate a TypeSourceInfo where all locations have been initialized to a given location,...
Definition: ASTContext.cpp:3030
clang::ASTContext::getPointerType
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
Definition: ASTContext.cpp:3341
clang::DeclSpec::TQ_const
@ TQ_const
Definition: DeclSpec.h:311
clang::sema::CapturingScopeInfo::getCXXThisCapture
Capture & getCXXThisCapture()
Retrieve the capture of C++ 'this', if it has been captured.
Definition: ScopeInfo.h:720
clang::Sema::startLambdaDefinition
CXXMethodDecl * startLambdaDefinition(CXXRecordDecl *Class, SourceRange IntroducerRange, TypeSourceInfo *MethodType, SourceLocation EndLoc, ArrayRef< ParmVarDecl * > Params, ConstexprSpecKind ConstexprKind, StorageClass SC, Expr *TrailingRequiresClause)
Start the definition of a lambda expression.
Definition: SemaLambda.cpp:365
clang::FunctionProtoTypeLoc
Definition: TypeLoc.h:1498
clang::Decl::setInvalidDecl
void setInvalidDecl(bool Invalid=true)
setInvalidDecl - Indicates the Decl had a semantic error.
Definition: DeclBase.cpp:132
clang::ASTContext::hasSameType
bool hasSameType(QualType T1, QualType T2) const
Determine whether the given types T1 and T2 are equivalent.
Definition: ASTContext.h:2544
clang::sema::CapturingScopeInfo::getCapture
Capture & getCapture(ValueDecl *Var)
Retrieve the capture of the given variable, if it has been captured already.
Definition: ScopeInfo.h:733
clang::InventedTemplateParameterInfo::NumExplicitTemplateParams
unsigned NumExplicitTemplateParams
The number of parameters in the template parameter list that were explicitly specified by the user,...
Definition: DeclSpec.h:2791
clang::SC_None
@ SC_None
Definition: Specifiers.h:238
clang::ValueDecl::getType
QualType getType() const
Definition: Decl.h:712
clang::DeducedType
Common base class for placeholders for types that get replaced by placeholder type deduction: C++11 a...
Definition: Type.h:5212
clang::ParsedAttributesView
Definition: ParsedAttr.h:920
clang::Expr
This represents one expression.
Definition: Expr.h:109
clang::HLSL
@ HLSL
Definition: LangStandard.h:63
clang::Sema::getCurrentMangleNumberContext
std::tuple< MangleNumberingContext *, Decl * > getCurrentMangleNumberContext(const DeclContext *DC)
Compute the mangling number context for a lambda expression or block literal.
Definition: SemaLambda.cpp:274
clang::sema::Capture::getVariable
ValueDecl * getVariable() const
Definition: ScopeInfo.h:643
clang::FunctionDecl::getDescribedFunctionTemplate
FunctionTemplateDecl * getDescribedFunctionTemplate() const
Retrieves the function template that is described by this function declaration.
Definition: Decl.cpp:3802
clang::ParmVarDecl::Create
static ParmVarDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, StorageClass S, Expr *DefArg)
Definition: Decl.cpp:2831
clang::Sema::buildLambdaInitCaptureInitialization
QualType buildLambdaInitCaptureInitialization(SourceLocation Loc, bool ByRef, SourceLocation EllipsisLoc, Optional< unsigned > NumExpansions, IdentifierInfo *Id, bool DirectInit, Expr *&Init)
Definition: SemaLambda.cpp:796
clang::VarDecl::hasLocalStorage
bool hasLocalStorage() const
Returns true if a variable with function scope is a non-static local variable.
Definition: Decl.h:1131
clang::sema::Capture::isVariableCapture
bool isVariableCapture() const
Definition: ScopeInfo.h:618
clang::CleanupInfo
Definition: CleanupInfo.h:19
clang::BlockDecl::Capture
A class which contains all the information about a particular captured value.
Definition: Decl.h:4289
clang::EnumType
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of enums.
Definition: Type.h:4842
clang::DeclContext::isFunctionOrMethod
bool isFunctionOrMethod() const
Definition: DeclBase.h:1975
clang::FunctionProtoType::getExtProtoInfo
ExtProtoInfo getExtProtoInfo() const
Definition: Type.h:4238
clang::Sema::ActOnLambdaExpr
ExprResult ActOnLambdaExpr(SourceLocation StartLoc, Stmt *Body, Scope *CurScope)
ActOnLambdaExpr - This is called when the body of a lambda expression was successfully completed.
Definition: SemaLambda.cpp:1674
addFunctionPointerConversion
static void addFunctionPointerConversion(Sema &S, SourceRange IntroducerRange, CXXRecordDecl *Class, CXXMethodDecl *CallOperator, QualType InvokerFunctionTy)
Add a lambda's conversion to function pointer, as described in C++11 [expr.prim.lambda]p6.
Definition: SemaLambda.cpp:1390
clang::Sema::TryCaptureKind
TryCaptureKind
Definition: Sema.h:5393
clang::DeclarationNameInfo
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspnd...
Definition: DeclarationName.h:767
clang::Type::isIncompleteType
bool isIncompleteType(NamedDecl **Def=nullptr) const
Types are partitioned into 3 broad categories (C99 6.2.5p1): object types, function types,...
Definition: Type.cpp:2235
clang::FullExpr::setSubExpr
void setSubExpr(Expr *E)
As with any mutator of the AST, be very careful when modifying an existing AST to preserve its invari...
Definition: Expr.h:1031
clang::InitializationKind::CreateCopy
static InitializationKind CreateCopy(SourceLocation InitLoc, SourceLocation EqualLoc, bool AllowExplicitConvs=false)
Create a copy initialization.
Definition: Initialization.h:673
clang::FunctionDecl::parameters
ArrayRef< ParmVarDecl * > parameters() const
Definition: Decl.h:2571
clang::Sema::BuildBlockForLambdaConversion
ExprResult BuildBlockForLambdaConversion(SourceLocation CurrentLocation, SourceLocation ConvLocation, CXXConversionDecl *Conv, Expr *Src)
Definition: SemaLambda.cpp:2009
clang::Decl::getLocation
SourceLocation getLocation() const
Definition: DeclBase.h:432
clang::sema::CapturingScopeInfo::ReturnType
QualType ReturnType
ReturnType - The target type of return statements in this context, or null if unknown.
Definition: ScopeInfo.h:697
clang::Decl::addAttr
void addAttr(Attr *A)
Definition: DeclBase.cpp:902
clang::Decl::setReferenced
void setReferenced(bool R=true)
Definition: DeclBase.h:606
clang::sema::Capture::getEllipsisLoc
SourceLocation getEllipsisLoc() const
Retrieve the source location of the ellipsis, whose presence indicates that the capture is a pack exp...
Definition: ScopeInfo.h:658
clang::LambdaExpr::Create
static LambdaExpr * Create(const ASTContext &C, CXXRecordDecl *Class, SourceRange IntroducerRange, LambdaCaptureDefault CaptureDefault, SourceLocation CaptureDefaultLoc, bool ExplicitParams, bool ExplicitResultType, ArrayRef< Expr * > CaptureInits, SourceLocation ClosingBrace, bool ContainsUnexpandedParameterPack)
Construct a new lambda expression.
Definition: ExprCXX.cpp:1167
clang::DeclRefExpr
A reference to a declared variable, function, enum, etc.
Definition: Expr.h:1232
clang::FunctionDecl
Represents a function declaration or definition.
Definition: Decl.h:1904
clang::RecordDecl
Represents a struct/union/class.
Definition: Decl.h:3983
clang::DeclContext::Equals
bool Equals(const DeclContext *DC) const
Determine whether this declaration context is equivalent to the declaration context DC.
Definition: DeclBase.h:2047
clang::ASTContext::NeedExtraManglingDecl
@ NeedExtraManglingDecl
Definition: ASTContext.h:3114
clang::CXXConversionDecl::Create
static CXXConversionDecl * Create(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo, bool UsesFPIntrin, bool isInline, ExplicitSpecifier ES, ConstexprSpecKind ConstexprKind, SourceLocation EndLocation, Expr *TrailingRequiresClause=nullptr)
Definition: DeclCXX.cpp:2807
clang::getLambdaStaticInvokerName
StringRef getLambdaStaticInvokerName()
Definition: ASTLambda.h:22
adjustBlockReturnsToEnum
static void adjustBlockReturnsToEnum(Sema &S, ArrayRef< ReturnStmt * > returns, QualType returnType)
Adjust the given return statements so that they formally return the given type.
Definition: SemaLambda.cpp:676
clang::DeclaratorDecl::getTypeSourceInfo
TypeSourceInfo * getTypeSourceInfo() const
Definition: Decl.h:787
clang::ICIS_NoInit
@ ICIS_NoInit
No in-class initializer.
Definition: Specifiers.h:260
ContextKind
tok::TokenKind ContextKind
Definition: TokenAnnotator.cpp:1596
clang::ReturnStmt
ReturnStmt - This represents a return, optionally of an expression: return; return 4;.
Definition: Stmt.h:2796
clang::VarDecl::CallInit
@ CallInit
Call-style initialization (C++98)
Definition: Decl.h:914
clang::TypeSourceInfo::getTypeLoc
TypeLoc getTypeLoc() const
Return the TypeLoc wrapper for the type source info.
Definition: TypeLoc.h:244
Initialization.h
clang::CXXMethodDecl::getParent
const CXXRecordDecl * getParent() const
Return the parent of this method declaration, which is the class in which this method is defined.
Definition: DeclCXX.h:2098
clang::CXXMethodDecl
Represents a static or instance method of a struct/union/class.
Definition: DeclCXX.h:1983
clang::LambdaIntroducer::Range
SourceRange Range
Definition: DeclSpec.h:2761
clang::Type::isUndeducedType
bool isUndeducedType() const
Determine whether this type is an undeduced type, meaning that it somehow involves a C++11 'auto' typ...
Definition: Type.h:7302
clang::LookupResult::isAmbiguous
bool isAmbiguous() const
Definition: Lookup.h:301
clang::ConstexprSpecKind::Unspecified
@ Unspecified
clang::Decl::getDeclContext
DeclContext * getDeclContext()
Definition: DeclBase.h:441
clang::sema::LambdaScopeInfo::CaptureDefaultLoc
SourceLocation CaptureDefaultLoc
Source location of the '&' or '=' specifying the default capture type, if any.
Definition: ScopeInfo.h:843
clang::sema::CapturingScopeInfo::isCXXThisCaptured
bool isCXXThisCaptured() const
Determine whether the C++ 'this' is captured.
Definition: ScopeInfo.h:717
clang::StorageClass
StorageClass
Storage classes.
Definition: Specifiers.h:236