clang  13.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.getValue();
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 
242  TypeSourceInfo *Info,
243  bool KnownDependent,
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.
251  CXXRecordDecl *Class = CXXRecordDecl::CreateLambda(Context, DC, Info,
252  IntroducerRange.getBegin(),
253  KnownDependent,
254  IsGenericLambda,
255  CaptureDefault);
256  DC->addDecl(Class);
257 
258  return Class;
259 }
260 
261 /// Determine whether the given context is or is enclosed in an inline
262 /// function.
263 static bool isInInlineFunction(const DeclContext *DC) {
264  while (!DC->isFileContext()) {
265  if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(DC))
266  if (FD->isInlined())
267  return true;
268 
269  DC = DC->getLexicalParent();
270  }
271 
272  return false;
273 }
274 
275 std::tuple<MangleNumberingContext *, Decl *>
277  // Compute the context for allocating mangling numbers in the current
278  // expression, if the ABI requires them.
279  Decl *ManglingContextDecl = ExprEvalContexts.back().ManglingContextDecl;
280 
281  enum ContextKind {
282  Normal,
283  DefaultArgument,
284  DataMember,
285  StaticDataMember,
286  InlineVariable,
287  VariableTemplate
288  } Kind = Normal;
289 
290  // Default arguments of member function parameters that appear in a class
291  // definition, as well as the initializers of data members, receive special
292  // treatment. Identify them.
293  if (ManglingContextDecl) {
294  if (ParmVarDecl *Param = dyn_cast<ParmVarDecl>(ManglingContextDecl)) {
295  if (const DeclContext *LexicalDC
296  = Param->getDeclContext()->getLexicalParent())
297  if (LexicalDC->isRecord())
298  Kind = DefaultArgument;
299  } else if (VarDecl *Var = dyn_cast<VarDecl>(ManglingContextDecl)) {
300  if (Var->getDeclContext()->isRecord())
301  Kind = StaticDataMember;
302  else if (Var->getMostRecentDecl()->isInline())
303  Kind = InlineVariable;
304  else if (Var->getDescribedVarTemplate())
305  Kind = VariableTemplate;
306  else if (auto *VTS = dyn_cast<VarTemplateSpecializationDecl>(Var)) {
307  if (!VTS->isExplicitSpecialization())
308  Kind = VariableTemplate;
309  }
310  } else if (isa<FieldDecl>(ManglingContextDecl)) {
311  Kind = DataMember;
312  }
313  }
314 
315  // Itanium ABI [5.1.7]:
316  // In the following contexts [...] the one-definition rule requires closure
317  // types in different translation units to "correspond":
318  bool IsInNonspecializedTemplate =
319  inTemplateInstantiation() || CurContext->isDependentContext();
320  switch (Kind) {
321  case Normal: {
322  // -- the bodies of non-exported nonspecialized template functions
323  // -- the bodies of inline functions
324  if ((IsInNonspecializedTemplate &&
325  !(ManglingContextDecl && isa<ParmVarDecl>(ManglingContextDecl))) ||
326  isInInlineFunction(CurContext)) {
327  while (auto *CD = dyn_cast<CapturedDecl>(DC))
328  DC = CD->getParent();
329  return std::make_tuple(&Context.getManglingNumberContext(DC), nullptr);
330  }
331 
332  return std::make_tuple(nullptr, nullptr);
333  }
334 
335  case StaticDataMember:
336  // -- the initializers of nonspecialized static members of template classes
337  if (!IsInNonspecializedTemplate)
338  return std::make_tuple(nullptr, ManglingContextDecl);
339  // Fall through to get the current context.
340  LLVM_FALLTHROUGH;
341 
342  case DataMember:
343  // -- the in-class initializers of class members
344  case DefaultArgument:
345  // -- default arguments appearing in class definitions
346  case InlineVariable:
347  // -- the initializers of inline variables
348  case VariableTemplate:
349  // -- the initializers of templated variables
350  return std::make_tuple(
352  ManglingContextDecl),
353  ManglingContextDecl);
354  }
355 
356  llvm_unreachable("unexpected context");
357 }
358 
360  SourceRange IntroducerRange,
361  TypeSourceInfo *MethodTypeInfo,
362  SourceLocation EndLoc,
364  ConstexprSpecKind ConstexprKind,
365  Expr *TrailingRequiresClause) {
366  QualType MethodType = MethodTypeInfo->getType();
367  TemplateParameterList *TemplateParams =
368  getGenericLambdaTemplateParameterList(getCurLambda(), *this);
369  // If a lambda appears in a dependent context or is a generic lambda (has
370  // template parameters) and has an 'auto' return type, deduce it to a
371  // dependent type.
372  if (Class->isDependentContext() || TemplateParams) {
373  const FunctionProtoType *FPT = MethodType->castAs<FunctionProtoType>();
374  QualType Result = FPT->getReturnType();
375  if (Result->isUndeducedType()) {
376  Result = SubstAutoType(Result, Context.DependentTy);
377  MethodType = Context.getFunctionType(Result, FPT->getParamTypes(),
378  FPT->getExtProtoInfo());
379  }
380  }
381 
382  // C++11 [expr.prim.lambda]p5:
383  // The closure type for a lambda-expression has a public inline function
384  // call operator (13.5.4) whose parameters and return type are described by
385  // the lambda-expression's parameter-declaration-clause and
386  // trailing-return-type respectively.
387  DeclarationName MethodName
388  = Context.DeclarationNames.getCXXOperatorName(OO_Call);
389  DeclarationNameLoc MethodNameLoc =
392  Context, Class, EndLoc,
393  DeclarationNameInfo(MethodName, IntroducerRange.getBegin(),
394  MethodNameLoc),
395  MethodType, MethodTypeInfo, SC_None,
396  /*isInline=*/true, ConstexprKind, EndLoc, TrailingRequiresClause);
397  Method->setAccess(AS_public);
398  if (!TemplateParams)
399  Class->addDecl(Method);
400 
401  // Temporarily set the lexical declaration context to the current
402  // context, so that the Scope stack matches the lexical nesting.
403  Method->setLexicalDeclContext(CurContext);
404  // Create a function template if we have a template parameter list
405  FunctionTemplateDecl *const TemplateMethod = TemplateParams ?
406  FunctionTemplateDecl::Create(Context, Class,
407  Method->getLocation(), MethodName,
408  TemplateParams,
409  Method) : nullptr;
410  if (TemplateMethod) {
411  TemplateMethod->setAccess(AS_public);
412  Method->setDescribedFunctionTemplate(TemplateMethod);
413  Class->addDecl(TemplateMethod);
414  TemplateMethod->setLexicalDeclContext(CurContext);
415  }
416 
417  // Add parameters.
418  if (!Params.empty()) {
419  Method->setParams(Params);
420  CheckParmsForFunctionDef(Params,
421  /*CheckParameterNames=*/false);
422 
423  for (auto P : Method->parameters())
424  P->setOwningFunction(Method);
425  }
426 
427  return Method;
428 }
429 
431  CXXRecordDecl *Class, CXXMethodDecl *Method,
432  Optional<std::tuple<bool, unsigned, unsigned, Decl *>> Mangling) {
433  if (Mangling) {
434  bool HasKnownInternalLinkage;
435  unsigned ManglingNumber, DeviceManglingNumber;
436  Decl *ManglingContextDecl;
437  std::tie(HasKnownInternalLinkage, ManglingNumber, DeviceManglingNumber,
438  ManglingContextDecl) = Mangling.getValue();
439  Class->setLambdaMangling(ManglingNumber, ManglingContextDecl,
440  HasKnownInternalLinkage);
441  Class->setDeviceLambdaManglingNumber(DeviceManglingNumber);
442  return;
443  }
444 
445  auto getMangleNumberingContext =
446  [this](CXXRecordDecl *Class,
447  Decl *ManglingContextDecl) -> MangleNumberingContext * {
448  // Get mangle numbering context if there's any extra decl context.
449  if (ManglingContextDecl)
450  return &Context.getManglingNumberContext(
451  ASTContext::NeedExtraManglingDecl, ManglingContextDecl);
452  // Otherwise, from that lambda's decl context.
453  auto DC = Class->getDeclContext();
454  while (auto *CD = dyn_cast<CapturedDecl>(DC))
455  DC = CD->getParent();
456  return &Context.getManglingNumberContext(DC);
457  };
458 
460  Decl *ManglingContextDecl;
461  std::tie(MCtx, ManglingContextDecl) =
462  getCurrentMangleNumberContext(Class->getDeclContext());
463  bool HasKnownInternalLinkage = false;
464  if (!MCtx && getLangOpts().CUDA) {
465  // Force lambda numbering in CUDA/HIP as we need to name lambdas following
466  // ODR. Both device- and host-compilation need to have a consistent naming
467  // on kernel functions. As lambdas are potential part of these `__global__`
468  // function names, they needs numbering following ODR.
469  MCtx = getMangleNumberingContext(Class, ManglingContextDecl);
470  assert(MCtx && "Retrieving mangle numbering context failed!");
471  HasKnownInternalLinkage = true;
472  }
473  if (MCtx) {
474  unsigned ManglingNumber = MCtx->getManglingNumber(Method);
475  Class->setLambdaMangling(ManglingNumber, ManglingContextDecl,
476  HasKnownInternalLinkage);
477  Class->setDeviceLambdaManglingNumber(MCtx->getDeviceManglingNumber(Method));
478  }
479 }
480 
482  CXXMethodDecl *CallOperator,
483  SourceRange IntroducerRange,
484  LambdaCaptureDefault CaptureDefault,
485  SourceLocation CaptureDefaultLoc,
486  bool ExplicitParams,
487  bool ExplicitResultType,
488  bool Mutable) {
489  LSI->CallOperator = CallOperator;
490  CXXRecordDecl *LambdaClass = CallOperator->getParent();
491  LSI->Lambda = LambdaClass;
492  if (CaptureDefault == LCD_ByCopy)
494  else if (CaptureDefault == LCD_ByRef)
496  LSI->CaptureDefaultLoc = CaptureDefaultLoc;
497  LSI->IntroducerRange = IntroducerRange;
498  LSI->ExplicitParams = ExplicitParams;
499  LSI->Mutable = Mutable;
500 
501  if (ExplicitResultType) {
502  LSI->ReturnType = CallOperator->getReturnType();
503 
504  if (!LSI->ReturnType->isDependentType() &&
505  !LSI->ReturnType->isVoidType()) {
506  if (RequireCompleteType(CallOperator->getBeginLoc(), LSI->ReturnType,
507  diag::err_lambda_incomplete_result)) {
508  // Do nothing.
509  }
510  }
511  } else {
512  LSI->HasImplicitReturnType = true;
513  }
514 }
515 
518 }
519 
521  ArrayRef<NamedDecl *> TParams,
522  SourceLocation RAngleLoc,
523  ExprResult RequiresClause) {
524  LambdaScopeInfo *LSI = getCurLambda();
525  assert(LSI && "Expected a lambda scope");
526  assert(LSI->NumExplicitTemplateParams == 0 &&
527  "Already acted on explicit template parameters");
528  assert(LSI->TemplateParams.empty() &&
529  "Explicit template parameters should come "
530  "before invented (auto) ones");
531  assert(!TParams.empty() &&
532  "No template parameters to act on");
533  LSI->TemplateParams.append(TParams.begin(), TParams.end());
534  LSI->NumExplicitTemplateParams = TParams.size();
535  LSI->ExplicitTemplateParamsRange = {LAngleLoc, RAngleLoc};
536  LSI->RequiresClause = RequiresClause;
537 }
538 
541  CXXMethodDecl *CallOperator, Scope *CurScope) {
542  // Introduce our parameters into the function scope
543  for (unsigned p = 0, NumParams = CallOperator->getNumParams();
544  p < NumParams; ++p) {
545  ParmVarDecl *Param = CallOperator->getParamDecl(p);
546 
547  // If this has an identifier, add it to the scope stack.
548  if (CurScope && Param->getIdentifier()) {
549  bool Error = false;
550  // Resolution of CWG 2211 in C++17 renders shadowing ill-formed, but we
551  // retroactively apply it.
552  for (const auto &Capture : Captures) {
553  if (Capture.Id == Param->getIdentifier()) {
554  Error = true;
555  Diag(Param->getLocation(), diag::err_parameter_shadow_capture);
556  Diag(Capture.Loc, diag::note_var_explicitly_captured_here)
557  << Capture.Id << true;
558  }
559  }
560  if (!Error)
561  CheckShadow(CurScope, Param);
562 
563  PushOnScopeChains(Param, CurScope);
564  }
565  }
566 }
567 
568 /// If this expression is an enumerator-like expression of some type
569 /// T, return the type T; otherwise, return null.
570 ///
571 /// Pointer comparisons on the result here should always work because
572 /// it's derived from either the parent of an EnumConstantDecl
573 /// (i.e. the definition) or the declaration returned by
574 /// EnumType::getDecl() (i.e. the definition).
576  // An expression is an enumerator-like expression of type T if,
577  // ignoring parens and parens-like expressions:
578  E = E->IgnoreParens();
579 
580  // - it is an enumerator whose enum type is T or
581  if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E)) {
582  if (EnumConstantDecl *D
583  = dyn_cast<EnumConstantDecl>(DRE->getDecl())) {
584  return cast<EnumDecl>(D->getDeclContext());
585  }
586  return nullptr;
587  }
588 
589  // - it is a comma expression whose RHS is an enumerator-like
590  // expression of type T or
591  if (BinaryOperator *BO = dyn_cast<BinaryOperator>(E)) {
592  if (BO->getOpcode() == BO_Comma)
593  return findEnumForBlockReturn(BO->getRHS());
594  return nullptr;
595  }
596 
597  // - it is a statement-expression whose value expression is an
598  // enumerator-like expression of type T or
599  if (StmtExpr *SE = dyn_cast<StmtExpr>(E)) {
600  if (Expr *last = dyn_cast_or_null<Expr>(SE->getSubStmt()->body_back()))
601  return findEnumForBlockReturn(last);
602  return nullptr;
603  }
604 
605  // - it is a ternary conditional operator (not the GNU ?:
606  // extension) whose second and third operands are
607  // enumerator-like expressions of type T or
608  if (ConditionalOperator *CO = dyn_cast<ConditionalOperator>(E)) {
609  if (EnumDecl *ED = findEnumForBlockReturn(CO->getTrueExpr()))
610  if (ED == findEnumForBlockReturn(CO->getFalseExpr()))
611  return ED;
612  return nullptr;
613  }
614 
615  // (implicitly:)
616  // - it is an implicit integral conversion applied to an
617  // enumerator-like expression of type T or
618  if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) {
619  // We can sometimes see integral conversions in valid
620  // enumerator-like expressions.
621  if (ICE->getCastKind() == CK_IntegralCast)
622  return findEnumForBlockReturn(ICE->getSubExpr());
623 
624  // Otherwise, just rely on the type.
625  }
626 
627  // - it is an expression of that formal enum type.
628  if (const EnumType *ET = E->getType()->getAs<EnumType>()) {
629  return ET->getDecl();
630  }
631 
632  // Otherwise, nope.
633  return nullptr;
634 }
635 
636 /// Attempt to find a type T for which the returned expression of the
637 /// given statement is an enumerator-like expression of that type.
639  if (Expr *retValue = ret->getRetValue())
640  return findEnumForBlockReturn(retValue);
641  return nullptr;
642 }
643 
644 /// Attempt to find a common type T for which all of the returned
645 /// expressions in a block are enumerator-like expressions of that
646 /// type.
648  ArrayRef<ReturnStmt*>::iterator i = returns.begin(), e = returns.end();
649 
650  // Try to find one for the first return.
652  if (!ED) return nullptr;
653 
654  // Check that the rest of the returns have the same enum.
655  for (++i; i != e; ++i) {
656  if (findEnumForBlockReturn(*i) != ED)
657  return nullptr;
658  }
659 
660  // Never infer an anonymous enum type.
661  if (!ED->hasNameForLinkage()) return nullptr;
662 
663  return ED;
664 }
665 
666 /// Adjust the given return statements so that they formally return
667 /// the given type. It should require, at most, an IntegralCast.
669  QualType returnType) {
671  i = returns.begin(), e = returns.end(); i != e; ++i) {
672  ReturnStmt *ret = *i;
673  Expr *retValue = ret->getRetValue();
674  if (S.Context.hasSameType(retValue->getType(), returnType))
675  continue;
676 
677  // Right now we only support integral fixup casts.
678  assert(returnType->isIntegralOrUnscopedEnumerationType());
679  assert(retValue->getType()->isIntegralOrUnscopedEnumerationType());
680 
681  ExprWithCleanups *cleanups = dyn_cast<ExprWithCleanups>(retValue);
682 
683  Expr *E = (cleanups ? cleanups->getSubExpr() : retValue);
684  E = ImplicitCastExpr::Create(S.Context, returnType, CK_IntegralCast, E,
685  /*base path*/ nullptr, VK_RValue,
687  if (cleanups) {
688  cleanups->setSubExpr(E);
689  } else {
690  ret->setRetValue(E);
691  }
692  }
693 }
694 
696  assert(CSI.HasImplicitReturnType);
697  // If it was ever a placeholder, it had to been deduced to DependentTy.
698  assert(CSI.ReturnType.isNull() || !CSI.ReturnType->isUndeducedType());
699  assert((!isa<LambdaScopeInfo>(CSI) || !getLangOpts().CPlusPlus14) &&
700  "lambda expressions use auto deduction in C++14 onwards");
701 
702  // C++ core issue 975:
703  // If a lambda-expression does not include a trailing-return-type,
704  // it is as if the trailing-return-type denotes the following type:
705  // - if there are no return statements in the compound-statement,
706  // or all return statements return either an expression of type
707  // void or no expression or braced-init-list, the type void;
708  // - otherwise, if all return statements return an expression
709  // and the types of the returned expressions after
710  // lvalue-to-rvalue conversion (4.1 [conv.lval]),
711  // array-to-pointer conversion (4.2 [conv.array]), and
712  // function-to-pointer conversion (4.3 [conv.func]) are the
713  // same, that common type;
714  // - otherwise, the program is ill-formed.
715  //
716  // C++ core issue 1048 additionally removes top-level cv-qualifiers
717  // from the types of returned expressions to match the C++14 auto
718  // deduction rules.
719  //
720  // In addition, in blocks in non-C++ modes, if all of the return
721  // statements are enumerator-like expressions of some type T, where
722  // T has a name for linkage, then we infer the return type of the
723  // block to be that type.
724 
725  // First case: no return statements, implicit void return type.
726  ASTContext &Ctx = getASTContext();
727  if (CSI.Returns.empty()) {
728  // It's possible there were simply no /valid/ return statements.
729  // In this case, the first one we found may have at least given us a type.
730  if (CSI.ReturnType.isNull())
731  CSI.ReturnType = Ctx.VoidTy;
732  return;
733  }
734 
735  // Second case: at least one return statement has dependent type.
736  // Delay type checking until instantiation.
737  assert(!CSI.ReturnType.isNull() && "We should have a tentative return type.");
738  if (CSI.ReturnType->isDependentType())
739  return;
740 
741  // Try to apply the enum-fuzz rule.
742  if (!getLangOpts().CPlusPlus) {
743  assert(isa<BlockScopeInfo>(CSI));
745  if (ED) {
746  CSI.ReturnType = Context.getTypeDeclType(ED);
748  return;
749  }
750  }
751 
752  // Third case: only one return statement. Don't bother doing extra work!
753  if (CSI.Returns.size() == 1)
754  return;
755 
756  // General case: many return statements.
757  // Check that they all have compatible return types.
758 
759  // We require the return types to strictly match here.
760  // Note that we've already done the required promotions as part of
761  // processing the return statement.
762  for (const ReturnStmt *RS : CSI.Returns) {
763  const Expr *RetE = RS->getRetValue();
764 
765  QualType ReturnType =
766  (RetE ? RetE->getType() : Context.VoidTy).getUnqualifiedType();
767  if (Context.getCanonicalFunctionResultType(ReturnType) ==
769  // Use the return type with the strictest possible nullability annotation.
770  auto RetTyNullability = ReturnType->getNullability(Ctx);
771  auto BlockNullability = CSI.ReturnType->getNullability(Ctx);
772  if (BlockNullability &&
773  (!RetTyNullability ||
774  hasWeakerNullability(*RetTyNullability, *BlockNullability)))
775  CSI.ReturnType = ReturnType;
776  continue;
777  }
778 
779  // FIXME: This is a poor diagnostic for ReturnStmts without expressions.
780  // TODO: It's possible that the *first* return is the divergent one.
781  Diag(RS->getBeginLoc(),
782  diag::err_typecheck_missing_return_type_incompatible)
783  << ReturnType << CSI.ReturnType << isa<LambdaScopeInfo>(CSI);
784  // Continue iterating so that we keep emitting diagnostics.
785  }
786 }
787 
789  SourceLocation Loc, bool ByRef, SourceLocation EllipsisLoc,
790  Optional<unsigned> NumExpansions, IdentifierInfo *Id, bool IsDirectInit,
791  Expr *&Init) {
792  // Create an 'auto' or 'auto&' TypeSourceInfo that we can use to
793  // deduce against.
794  QualType DeductType = Context.getAutoDeductType();
795  TypeLocBuilder TLB;
796  AutoTypeLoc TL = TLB.push<AutoTypeLoc>(DeductType);
797  TL.setNameLoc(Loc);
798  if (ByRef) {
799  DeductType = BuildReferenceType(DeductType, true, Loc, Id);
800  assert(!DeductType.isNull() && "can't build reference to auto");
801  TLB.push<ReferenceTypeLoc>(DeductType).setSigilLoc(Loc);
802  }
803  if (EllipsisLoc.isValid()) {
804  if (Init->containsUnexpandedParameterPack()) {
805  Diag(EllipsisLoc, getLangOpts().CPlusPlus20
806  ? diag::warn_cxx17_compat_init_capture_pack
807  : diag::ext_init_capture_pack);
808  DeductType = Context.getPackExpansionType(DeductType, NumExpansions,
809  /*ExpectPackInType=*/false);
810  TLB.push<PackExpansionTypeLoc>(DeductType).setEllipsisLoc(EllipsisLoc);
811  } else {
812  // Just ignore the ellipsis for now and form a non-pack variable. We'll
813  // diagnose this later when we try to capture it.
814  }
815  }
816  TypeSourceInfo *TSI = TLB.getTypeSourceInfo(Context, DeductType);
817 
818  // Deduce the type of the init capture.
819  QualType DeducedType = deduceVarTypeFromInitializer(
820  /*VarDecl*/nullptr, DeclarationName(Id), DeductType, TSI,
821  SourceRange(Loc, Loc), IsDirectInit, Init);
822  if (DeducedType.isNull())
823  return QualType();
824 
825  // Are we a non-list direct initialization?
826  ParenListExpr *CXXDirectInit = dyn_cast<ParenListExpr>(Init);
827 
828  // Perform initialization analysis and ensure any implicit conversions
829  // (such as lvalue-to-rvalue) are enforced.
830  InitializedEntity Entity =
833  IsDirectInit
834  ? (CXXDirectInit ? InitializationKind::CreateDirect(
835  Loc, Init->getBeginLoc(), Init->getEndLoc())
837  : InitializationKind::CreateCopy(Loc, Init->getBeginLoc());
838 
839  MultiExprArg Args = Init;
840  if (CXXDirectInit)
841  Args =
842  MultiExprArg(CXXDirectInit->getExprs(), CXXDirectInit->getNumExprs());
843  QualType DclT;
844  InitializationSequence InitSeq(*this, Entity, Kind, Args);
845  ExprResult Result = InitSeq.Perform(*this, Entity, Kind, Args, &DclT);
846 
847  if (Result.isInvalid())
848  return QualType();
849 
850  Init = Result.getAs<Expr>();
851  return DeducedType;
852 }
853 
855  QualType InitCaptureType,
856  SourceLocation EllipsisLoc,
858  unsigned InitStyle, Expr *Init) {
859  // FIXME: Retain the TypeSourceInfo from buildLambdaInitCaptureInitialization
860  // rather than reconstructing it here.
861  TypeSourceInfo *TSI = Context.getTrivialTypeSourceInfo(InitCaptureType, Loc);
862  if (auto PETL = TSI->getTypeLoc().getAs<PackExpansionTypeLoc>())
863  PETL.setEllipsisLoc(EllipsisLoc);
864 
865  // Create a dummy variable representing the init-capture. This is not actually
866  // used as a variable, and only exists as a way to name and refer to the
867  // init-capture.
868  // FIXME: Pass in separate source locations for '&' and identifier.
869  VarDecl *NewVD = VarDecl::Create(Context, CurContext, Loc,
870  Loc, Id, InitCaptureType, TSI, SC_Auto);
871  NewVD->setInitCapture(true);
872  NewVD->setReferenced(true);
873  // FIXME: Pass in a VarDecl::InitializationStyle.
874  NewVD->setInitStyle(static_cast<VarDecl::InitializationStyle>(InitStyle));
875  NewVD->markUsed(Context);
876  NewVD->setInit(Init);
877  if (NewVD->isParameterPack())
878  getCurLambda()->LocalPacks.push_back(NewVD);
879  return NewVD;
880 }
881 
883  assert(Var->isInitCapture() && "init capture flag should be set");
884  LSI->addCapture(Var, /*isBlock*/false, Var->getType()->isReferenceType(),
885  /*isNested*/false, Var->getLocation(), SourceLocation(),
886  Var->getType(), /*Invalid*/false);
887 }
888 
890  Declarator &ParamInfo,
891  Scope *CurScope) {
892  LambdaScopeInfo *const LSI = getCurLambda();
893  assert(LSI && "LambdaScopeInfo should be on stack!");
894 
895  // Determine if we're within a context where we know that the lambda will
896  // be dependent, because there are template parameters in scope.
897  bool KnownDependent;
898  if (LSI->NumExplicitTemplateParams > 0) {
899  auto *TemplateParamScope = CurScope->getTemplateParamParent();
900  assert(TemplateParamScope &&
901  "Lambda with explicit template param list should establish a "
902  "template param scope");
903  assert(TemplateParamScope->getParent());
904  KnownDependent = TemplateParamScope->getParent()
905  ->getTemplateParamParent() != nullptr;
906  } else {
907  KnownDependent = CurScope->getTemplateParamParent() != nullptr;
908  }
909 
910  // Determine the signature of the call operator.
911  TypeSourceInfo *MethodTyInfo;
912  bool ExplicitParams = true;
913  bool ExplicitResultType = true;
914  bool ContainsUnexpandedParameterPack = false;
915  SourceLocation EndLoc;
917  if (ParamInfo.getNumTypeObjects() == 0) {
918  // C++11 [expr.prim.lambda]p4:
919  // If a lambda-expression does not include a lambda-declarator, it is as
920  // if the lambda-declarator were ().
922  /*IsVariadic=*/false, /*IsCXXMethod=*/true));
923  EPI.HasTrailingReturn = true;
924  EPI.TypeQuals.addConst();
925  LangAS AS = getDefaultCXXMethodAddrSpace();
926  if (AS != LangAS::Default)
927  EPI.TypeQuals.addAddressSpace(AS);
928 
929  // C++1y [expr.prim.lambda]:
930  // The lambda return type is 'auto', which is replaced by the
931  // trailing-return type if provided and/or deduced from 'return'
932  // statements
933  // We don't do this before C++1y, because we don't support deduced return
934  // types there.
935  QualType DefaultTypeForNoTrailingReturn =
936  getLangOpts().CPlusPlus14 ? Context.getAutoDeductType()
937  : Context.DependentTy;
938  QualType MethodTy =
939  Context.getFunctionType(DefaultTypeForNoTrailingReturn, None, EPI);
940  MethodTyInfo = Context.getTrivialTypeSourceInfo(MethodTy);
941  ExplicitParams = false;
942  ExplicitResultType = false;
943  EndLoc = Intro.Range.getEnd();
944  } else {
945  assert(ParamInfo.isFunctionDeclarator() &&
946  "lambda-declarator is a function");
948 
949  // C++11 [expr.prim.lambda]p5:
950  // This function call operator is declared const (9.3.1) if and only if
951  // the lambda-expression's parameter-declaration-clause is not followed
952  // by mutable. It is neither virtual nor declared volatile. [...]
953  if (!FTI.hasMutableQualifier()) {
955  SourceLocation());
956  }
957 
958  MethodTyInfo = GetTypeForDeclarator(ParamInfo, CurScope);
959  assert(MethodTyInfo && "no type from lambda-declarator");
960  EndLoc = ParamInfo.getSourceRange().getEnd();
961 
962  ExplicitResultType = FTI.hasTrailingReturnType();
963 
964  if (FTIHasNonVoidParameters(FTI)) {
965  Params.reserve(FTI.NumParams);
966  for (unsigned i = 0, e = FTI.NumParams; i != e; ++i)
967  Params.push_back(cast<ParmVarDecl>(FTI.Params[i].Param));
968  }
969 
970  // Check for unexpanded parameter packs in the method type.
971  if (MethodTyInfo->getType()->containsUnexpandedParameterPack())
972  DiagnoseUnexpandedParameterPack(Intro.Range.getBegin(), MethodTyInfo,
973  UPPC_DeclarationType);
974  }
975 
976  CXXRecordDecl *Class = createLambdaClosureType(Intro.Range, MethodTyInfo,
977  KnownDependent, Intro.Default);
978  CXXMethodDecl *Method =
979  startLambdaDefinition(Class, Intro.Range, MethodTyInfo, EndLoc, Params,
980  ParamInfo.getDeclSpec().getConstexprSpecifier(),
981  ParamInfo.getTrailingRequiresClause());
982  if (ExplicitParams)
983  CheckCXXDefaultArguments(Method);
984 
985  // This represents the function body for the lambda function, check if we
986  // have to apply optnone due to a pragma.
987  AddRangeBasedOptnone(Method);
988 
989  // code_seg attribute on lambda apply to the method.
990  if (Attr *A = getImplicitCodeSegOrSectionAttrForFunction(Method, /*IsDefinition=*/true))
991  Method->addAttr(A);
992 
993  // Attributes on the lambda apply to the method.
994  ProcessDeclAttributes(CurScope, Method, ParamInfo);
995 
996  // CUDA lambdas get implicit host and device attributes.
997  if (getLangOpts().CUDA)
998  CUDASetLambdaAttrs(Method);
999 
1000  // OpenMP lambdas might get assumumption attributes.
1001  if (LangOpts.OpenMP)
1002  ActOnFinishedFunctionDefinitionInOpenMPAssumeScope(Method);
1003 
1004  // Number the lambda for linkage purposes if necessary.
1005  handleLambdaNumbering(Class, Method);
1006 
1007  // Introduce the function call operator as the current declaration context.
1008  PushDeclContext(CurScope, Method);
1009 
1010  // Build the lambda scope.
1011  buildLambdaScope(LSI, Method, Intro.Range, Intro.Default, Intro.DefaultLoc,
1012  ExplicitParams, ExplicitResultType, !Method->isConst());
1013 
1014  // C++11 [expr.prim.lambda]p9:
1015  // A lambda-expression whose smallest enclosing scope is a block scope is a
1016  // local lambda expression; any other lambda expression shall not have a
1017  // capture-default or simple-capture in its lambda-introducer.
1018  //
1019  // For simple-captures, this is covered by the check below that any named
1020  // entity is a variable that can be captured.
1021  //
1022  // For DR1632, we also allow a capture-default in any context where we can
1023  // odr-use 'this' (in particular, in a default initializer for a non-static
1024  // data member).
1025  if (Intro.Default != LCD_None && !Class->getParent()->isFunctionOrMethod() &&
1026  (getCurrentThisType().isNull() ||
1027  CheckCXXThisCapture(SourceLocation(), /*Explicit*/true,
1028  /*BuildAndDiagnose*/false)))
1029  Diag(Intro.DefaultLoc, diag::err_capture_default_non_local);
1030 
1031  // Distinct capture names, for diagnostics.
1032  llvm::SmallSet<IdentifierInfo*, 8> CaptureNames;
1033 
1034  // Handle explicit captures.
1035  SourceLocation PrevCaptureLoc
1036  = Intro.Default == LCD_None? Intro.Range.getBegin() : Intro.DefaultLoc;
1037  for (auto C = Intro.Captures.begin(), E = Intro.Captures.end(); C != E;
1038  PrevCaptureLoc = C->Loc, ++C) {
1039  if (C->Kind == LCK_This || C->Kind == LCK_StarThis) {
1040  if (C->Kind == LCK_StarThis)
1041  Diag(C->Loc, !getLangOpts().CPlusPlus17
1042  ? diag::ext_star_this_lambda_capture_cxx17
1043  : diag::warn_cxx14_compat_star_this_lambda_capture);
1044 
1045  // C++11 [expr.prim.lambda]p8:
1046  // An identifier or this shall not appear more than once in a
1047  // lambda-capture.
1048  if (LSI->isCXXThisCaptured()) {
1049  Diag(C->Loc, diag::err_capture_more_than_once)
1050  << "'this'" << SourceRange(LSI->getCXXThisCapture().getLocation())
1052  SourceRange(getLocForEndOfToken(PrevCaptureLoc), C->Loc));
1053  continue;
1054  }
1055 
1056  // C++2a [expr.prim.lambda]p8:
1057  // If a lambda-capture includes a capture-default that is =,
1058  // each simple-capture of that lambda-capture shall be of the form
1059  // "&identifier", "this", or "* this". [ Note: The form [&,this] is
1060  // redundant but accepted for compatibility with ISO C++14. --end note ]
1061  if (Intro.Default == LCD_ByCopy && C->Kind != LCK_StarThis)
1062  Diag(C->Loc, !getLangOpts().CPlusPlus20
1063  ? diag::ext_equals_this_lambda_capture_cxx20
1064  : diag::warn_cxx17_compat_equals_this_lambda_capture);
1065 
1066  // C++11 [expr.prim.lambda]p12:
1067  // If this is captured by a local lambda expression, its nearest
1068  // enclosing function shall be a non-static member function.
1069  QualType ThisCaptureType = getCurrentThisType();
1070  if (ThisCaptureType.isNull()) {
1071  Diag(C->Loc, diag::err_this_capture) << true;
1072  continue;
1073  }
1074 
1075  CheckCXXThisCapture(C->Loc, /*Explicit=*/true, /*BuildAndDiagnose*/ true,
1076  /*FunctionScopeIndexToStopAtPtr*/ nullptr,
1077  C->Kind == LCK_StarThis);
1078  if (!LSI->Captures.empty())
1079  LSI->ExplicitCaptureRanges[LSI->Captures.size() - 1] = C->ExplicitRange;
1080  continue;
1081  }
1082 
1083  assert(C->Id && "missing identifier for capture");
1084 
1085  if (C->Init.isInvalid())
1086  continue;
1087 
1088  VarDecl *Var = nullptr;
1089  if (C->Init.isUsable()) {
1090  Diag(C->Loc, getLangOpts().CPlusPlus14
1091  ? diag::warn_cxx11_compat_init_capture
1092  : diag::ext_init_capture);
1093 
1094  // If the initializer expression is usable, but the InitCaptureType
1095  // is not, then an error has occurred - so ignore the capture for now.
1096  // for e.g., [n{0}] { }; <-- if no <initializer_list> is included.
1097  // FIXME: we should create the init capture variable and mark it invalid
1098  // in this case.
1099  if (C->InitCaptureType.get().isNull())
1100  continue;
1101 
1102  if (C->Init.get()->containsUnexpandedParameterPack() &&
1103  !C->InitCaptureType.get()->getAs<PackExpansionType>())
1104  DiagnoseUnexpandedParameterPack(C->Init.get(), UPPC_Initializer);
1105 
1106  unsigned InitStyle;
1107  switch (C->InitKind) {
1109  llvm_unreachable("not an init-capture?");
1111  InitStyle = VarDecl::CInit;
1112  break;
1114  InitStyle = VarDecl::CallInit;
1115  break;
1117  InitStyle = VarDecl::ListInit;
1118  break;
1119  }
1120  Var = createLambdaInitCaptureVarDecl(C->Loc, C->InitCaptureType.get(),
1121  C->EllipsisLoc, C->Id, InitStyle,
1122  C->Init.get());
1123  // C++1y [expr.prim.lambda]p11:
1124  // An init-capture behaves as if it declares and explicitly
1125  // captures a variable [...] whose declarative region is the
1126  // lambda-expression's compound-statement
1127  if (Var)
1128  PushOnScopeChains(Var, CurScope, false);
1129  } else {
1130  assert(C->InitKind == LambdaCaptureInitKind::NoInit &&
1131  "init capture has valid but null init?");
1132 
1133  // C++11 [expr.prim.lambda]p8:
1134  // If a lambda-capture includes a capture-default that is &, the
1135  // identifiers in the lambda-capture shall not be preceded by &.
1136  // If a lambda-capture includes a capture-default that is =, [...]
1137  // each identifier it contains shall be preceded by &.
1138  if (C->Kind == LCK_ByRef && Intro.Default == LCD_ByRef) {
1139  Diag(C->Loc, diag::err_reference_capture_with_reference_default)
1141  SourceRange(getLocForEndOfToken(PrevCaptureLoc), C->Loc));
1142  continue;
1143  } else if (C->Kind == LCK_ByCopy && Intro.Default == LCD_ByCopy) {
1144  Diag(C->Loc, diag::err_copy_capture_with_copy_default)
1146  SourceRange(getLocForEndOfToken(PrevCaptureLoc), C->Loc));
1147  continue;
1148  }
1149 
1150  // C++11 [expr.prim.lambda]p10:
1151  // The identifiers in a capture-list are looked up using the usual
1152  // rules for unqualified name lookup (3.4.1)
1153  DeclarationNameInfo Name(C->Id, C->Loc);
1154  LookupResult R(*this, Name, LookupOrdinaryName);
1155  LookupName(R, CurScope);
1156  if (R.isAmbiguous())
1157  continue;
1158  if (R.empty()) {
1159  // FIXME: Disable corrections that would add qualification?
1160  CXXScopeSpec ScopeSpec;
1161  DeclFilterCCC<VarDecl> Validator{};
1162  if (DiagnoseEmptyLookup(CurScope, ScopeSpec, R, Validator))
1163  continue;
1164  }
1165 
1166  Var = R.getAsSingle<VarDecl>();
1167  if (Var && DiagnoseUseOfDecl(Var, C->Loc))
1168  continue;
1169  }
1170 
1171  // C++11 [expr.prim.lambda]p8:
1172  // An identifier or this shall not appear more than once in a
1173  // lambda-capture.
1174  if (!CaptureNames.insert(C->Id).second) {
1175  if (Var && LSI->isCaptured(Var)) {
1176  Diag(C->Loc, diag::err_capture_more_than_once)
1177  << C->Id << SourceRange(LSI->getCapture(Var).getLocation())
1179  SourceRange(getLocForEndOfToken(PrevCaptureLoc), C->Loc));
1180  } else
1181  // Previous capture captured something different (one or both was
1182  // an init-cpature): no fixit.
1183  Diag(C->Loc, diag::err_capture_more_than_once) << C->Id;
1184  continue;
1185  }
1186 
1187  // C++11 [expr.prim.lambda]p10:
1188  // [...] each such lookup shall find a variable with automatic storage
1189  // duration declared in the reaching scope of the local lambda expression.
1190  // Note that the 'reaching scope' check happens in tryCaptureVariable().
1191  if (!Var) {
1192  Diag(C->Loc, diag::err_capture_does_not_name_variable) << C->Id;
1193  continue;
1194  }
1195 
1196  // Ignore invalid decls; they'll just confuse the code later.
1197  if (Var->isInvalidDecl())
1198  continue;
1199 
1200  if (!Var->hasLocalStorage()) {
1201  Diag(C->Loc, diag::err_capture_non_automatic_variable) << C->Id;
1202  Diag(Var->getLocation(), diag::note_previous_decl) << C->Id;
1203  continue;
1204  }
1205 
1206  // C++11 [expr.prim.lambda]p23:
1207  // A capture followed by an ellipsis is a pack expansion (14.5.3).
1208  SourceLocation EllipsisLoc;
1209  if (C->EllipsisLoc.isValid()) {
1210  if (Var->isParameterPack()) {
1211  EllipsisLoc = C->EllipsisLoc;
1212  } else {
1213  Diag(C->EllipsisLoc, diag::err_pack_expansion_without_parameter_packs)
1214  << (C->Init.isUsable() ? C->Init.get()->getSourceRange()
1215  : SourceRange(C->Loc));
1216 
1217  // Just ignore the ellipsis.
1218  }
1219  } else if (Var->isParameterPack()) {
1220  ContainsUnexpandedParameterPack = true;
1221  }
1222 
1223  if (C->Init.isUsable()) {
1224  addInitCapture(LSI, Var);
1225  } else {
1226  TryCaptureKind Kind = C->Kind == LCK_ByRef ? TryCapture_ExplicitByRef :
1227  TryCapture_ExplicitByVal;
1228  tryCaptureVariable(Var, C->Loc, Kind, EllipsisLoc);
1229  }
1230  if (!LSI->Captures.empty())
1231  LSI->ExplicitCaptureRanges[LSI->Captures.size() - 1] = C->ExplicitRange;
1232  }
1233  finishLambdaExplicitCaptures(LSI);
1234 
1235  LSI->ContainsUnexpandedParameterPack |= ContainsUnexpandedParameterPack;
1236 
1237  // Add lambda parameters into scope.
1238  addLambdaParameters(Intro.Captures, Method, CurScope);
1239 
1240  // Enter a new evaluation context to insulate the lambda from any
1241  // cleanups from the enclosing full-expression.
1242  PushExpressionEvaluationContext(
1243  LSI->CallOperator->isConsteval()
1244  ? ExpressionEvaluationContext::ConstantEvaluated
1245  : ExpressionEvaluationContext::PotentiallyEvaluated);
1246 }
1247 
1249  bool IsInstantiation) {
1250  LambdaScopeInfo *LSI = cast<LambdaScopeInfo>(FunctionScopes.back());
1251 
1252  // Leave the expression-evaluation context.
1253  DiscardCleanupsInEvaluationContext();
1254  PopExpressionEvaluationContext();
1255 
1256  // Leave the context of the lambda.
1257  if (!IsInstantiation)
1258  PopDeclContext();
1259 
1260  // Finalize the lambda.
1261  CXXRecordDecl *Class = LSI->Lambda;
1262  Class->setInvalidDecl();
1263  SmallVector<Decl*, 4> Fields(Class->fields());
1264  ActOnFields(nullptr, Class->getLocation(), Class, Fields, SourceLocation(),
1266  CheckCompletedCXXClass(nullptr, Class);
1267 
1268  PopFunctionScopeInfo();
1269 }
1270 
1271 template <typename Func>
1273  Sema &S, const FunctionProtoType &CallOpProto, Func F) {
1275  CallOpProto.isVariadic(), /*IsCXXMethod=*/false);
1277  CallOpProto.isVariadic(), /*IsCXXMethod=*/true);
1278  CallingConv CallOpCC = CallOpProto.getCallConv();
1279 
1280  /// Implement emitting a version of the operator for many of the calling
1281  /// conventions for MSVC, as described here:
1282  /// https://devblogs.microsoft.com/oldnewthing/20150220-00/?p=44623.
1283  /// Experimentally, we determined that cdecl, stdcall, fastcall, and
1284  /// vectorcall are generated by MSVC when it is supported by the target.
1285  /// Additionally, we are ensuring that the default-free/default-member and
1286  /// call-operator calling convention are generated as well.
1287  /// NOTE: We intentionally generate a 'thiscall' on Win32 implicitly from the
1288  /// 'member default', despite MSVC not doing so. We do this in order to ensure
1289  /// that someone who intentionally places 'thiscall' on the lambda call
1290  /// operator will still get that overload, since we don't have the a way of
1291  /// detecting the attribute by the time we get here.
1292  if (S.getLangOpts().MSVCCompat) {
1293  CallingConv Convs[] = {
1295  DefaultFree, DefaultMember, CallOpCC};
1296  llvm::sort(Convs);
1297  llvm::iterator_range<CallingConv *> Range(
1298  std::begin(Convs), std::unique(std::begin(Convs), std::end(Convs)));
1299  const TargetInfo &TI = S.getASTContext().getTargetInfo();
1300 
1301  for (CallingConv C : Range) {
1303  F(C);
1304  }
1305  return;
1306  }
1307 
1308  if (CallOpCC == DefaultMember && DefaultMember != DefaultFree) {
1309  F(DefaultFree);
1310  F(DefaultMember);
1311  } else {
1312  F(CallOpCC);
1313  }
1314 }
1315 
1316 // Returns the 'standard' calling convention to be used for the lambda
1317 // conversion function, that is, the 'free' function calling convention unless
1318 // it is overridden by a non-default calling convention attribute.
1319 static CallingConv
1321  const FunctionProtoType *CallOpProto) {
1323  CallOpProto->isVariadic(), /*IsCXXMethod=*/false);
1325  CallOpProto->isVariadic(), /*IsCXXMethod=*/true);
1326  CallingConv CallOpCC = CallOpProto->getCallConv();
1327 
1328  // If the call-operator hasn't been changed, return both the 'free' and
1329  // 'member' function calling convention.
1330  if (CallOpCC == DefaultMember && DefaultMember != DefaultFree)
1331  return DefaultFree;
1332  return CallOpCC;
1333 }
1334 
1336  const FunctionProtoType *CallOpProto, CallingConv CC) {
1337  const FunctionProtoType::ExtProtoInfo CallOpExtInfo =
1338  CallOpProto->getExtProtoInfo();
1339  FunctionProtoType::ExtProtoInfo InvokerExtInfo = CallOpExtInfo;
1340  InvokerExtInfo.ExtInfo = InvokerExtInfo.ExtInfo.withCallingConv(CC);
1341  InvokerExtInfo.TypeQuals = Qualifiers();
1342  assert(InvokerExtInfo.RefQualifier == RQ_None &&
1343  "Lambda's call operator should not have a reference qualifier");
1344  return Context.getFunctionType(CallOpProto->getReturnType(),
1345  CallOpProto->getParamTypes(), InvokerExtInfo);
1346 }
1347 
1348 /// Add a lambda's conversion to function pointer, as described in
1349 /// C++11 [expr.prim.lambda]p6.
1350 static void addFunctionPointerConversion(Sema &S, SourceRange IntroducerRange,
1351  CXXRecordDecl *Class,
1352  CXXMethodDecl *CallOperator,
1353  QualType InvokerFunctionTy) {
1354  // This conversion is explicitly disabled if the lambda's function has
1355  // pass_object_size attributes on any of its parameters.
1356  auto HasPassObjectSizeAttr = [](const ParmVarDecl *P) {
1357  return P->hasAttr<PassObjectSizeAttr>();
1358  };
1359  if (llvm::any_of(CallOperator->parameters(), HasPassObjectSizeAttr))
1360  return;
1361 
1362  // Add the conversion to function pointer.
1363  QualType PtrToFunctionTy = S.Context.getPointerType(InvokerFunctionTy);
1364 
1365  // Create the type of the conversion function.
1366  FunctionProtoType::ExtProtoInfo ConvExtInfo(
1368  /*IsVariadic=*/false, /*IsCXXMethod=*/true));
1369  // The conversion function is always const and noexcept.
1370  ConvExtInfo.TypeQuals = Qualifiers();
1371  ConvExtInfo.TypeQuals.addConst();
1372  ConvExtInfo.ExceptionSpec.Type = EST_BasicNoexcept;
1373  QualType ConvTy =
1374  S.Context.getFunctionType(PtrToFunctionTy, None, ConvExtInfo);
1375 
1376  SourceLocation Loc = IntroducerRange.getBegin();
1377  DeclarationName ConversionName
1379  S.Context.getCanonicalType(PtrToFunctionTy));
1380  // Construct a TypeSourceInfo for the conversion function, and wire
1381  // all the parameters appropriately for the FunctionProtoTypeLoc
1382  // so that everything works during transformation/instantiation of
1383  // generic lambdas.
1384  // The main reason for wiring up the parameters of the conversion
1385  // function with that of the call operator is so that constructs
1386  // like the following work:
1387  // auto L = [](auto b) { <-- 1
1388  // return [](auto a) -> decltype(a) { <-- 2
1389  // return a;
1390  // };
1391  // };
1392  // int (*fp)(int) = L(5);
1393  // Because the trailing return type can contain DeclRefExprs that refer
1394  // to the original call operator's variables, we hijack the call
1395  // operators ParmVarDecls below.
1396  TypeSourceInfo *ConvNamePtrToFunctionTSI =
1397  S.Context.getTrivialTypeSourceInfo(PtrToFunctionTy, Loc);
1398  DeclarationNameLoc ConvNameLoc =
1399  DeclarationNameLoc::makeNamedTypeLoc(ConvNamePtrToFunctionTSI);
1400 
1401  // The conversion function is a conversion to a pointer-to-function.
1402  TypeSourceInfo *ConvTSI = S.Context.getTrivialTypeSourceInfo(ConvTy, Loc);
1403  FunctionProtoTypeLoc ConvTL =
1404  ConvTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
1405  // Get the result of the conversion function which is a pointer-to-function.
1406  PointerTypeLoc PtrToFunctionTL =
1407  ConvTL.getReturnLoc().getAs<PointerTypeLoc>();
1408  // Do the same for the TypeSourceInfo that is used to name the conversion
1409  // operator.
1410  PointerTypeLoc ConvNamePtrToFunctionTL =
1411  ConvNamePtrToFunctionTSI->getTypeLoc().getAs<PointerTypeLoc>();
1412 
1413  // Get the underlying function types that the conversion function will
1414  // be converting to (should match the type of the call operator).
1415  FunctionProtoTypeLoc CallOpConvTL =
1416  PtrToFunctionTL.getPointeeLoc().getAs<FunctionProtoTypeLoc>();
1417  FunctionProtoTypeLoc CallOpConvNameTL =
1418  ConvNamePtrToFunctionTL.getPointeeLoc().getAs<FunctionProtoTypeLoc>();
1419 
1420  // Wire up the FunctionProtoTypeLocs with the call operator's parameters.
1421  // These parameter's are essentially used to transform the name and
1422  // the type of the conversion operator. By using the same parameters
1423  // as the call operator's we don't have to fix any back references that
1424  // the trailing return type of the call operator's uses (such as
1425  // decltype(some_type<decltype(a)>::type{} + decltype(a){}) etc.)
1426  // - we can simply use the return type of the call operator, and
1427  // everything should work.
1428  SmallVector<ParmVarDecl *, 4> InvokerParams;
1429  for (unsigned I = 0, N = CallOperator->getNumParams(); I != N; ++I) {
1430  ParmVarDecl *From = CallOperator->getParamDecl(I);
1431 
1432  InvokerParams.push_back(ParmVarDecl::Create(
1433  S.Context,
1434  // Temporarily add to the TU. This is set to the invoker below.
1436  From->getLocation(), From->getIdentifier(), From->getType(),
1437  From->getTypeSourceInfo(), From->getStorageClass(),
1438  /*DefArg=*/nullptr));
1439  CallOpConvTL.setParam(I, From);
1440  CallOpConvNameTL.setParam(I, From);
1441  }
1442 
1444  S.Context, Class, Loc,
1445  DeclarationNameInfo(ConversionName, Loc, ConvNameLoc), ConvTy, ConvTSI,
1446  /*isInline=*/true, ExplicitSpecifier(),
1447  S.getLangOpts().CPlusPlus17 ? ConstexprSpecKind::Constexpr
1449  CallOperator->getBody()->getEndLoc());
1450  Conversion->setAccess(AS_public);
1451  Conversion->setImplicit(true);
1452 
1453  if (Class->isGenericLambda()) {
1454  // Create a template version of the conversion operator, using the template
1455  // parameter list of the function call operator.
1456  FunctionTemplateDecl *TemplateCallOperator =
1457  CallOperator->getDescribedFunctionTemplate();
1458  FunctionTemplateDecl *ConversionTemplate =
1460  Loc, ConversionName,
1461  TemplateCallOperator->getTemplateParameters(),
1462  Conversion);
1463  ConversionTemplate->setAccess(AS_public);
1464  ConversionTemplate->setImplicit(true);
1465  Conversion->setDescribedFunctionTemplate(ConversionTemplate);
1466  Class->addDecl(ConversionTemplate);
1467  } else
1468  Class->addDecl(Conversion);
1469  // Add a non-static member function that will be the result of
1470  // the conversion with a certain unique ID.
1471  DeclarationName InvokerName = &S.Context.Idents.get(
1473  // FIXME: Instead of passing in the CallOperator->getTypeSourceInfo()
1474  // we should get a prebuilt TrivialTypeSourceInfo from Context
1475  // using FunctionTy & Loc and get its TypeLoc as a FunctionProtoTypeLoc
1476  // then rewire the parameters accordingly, by hoisting up the InvokeParams
1477  // loop below and then use its Params to set Invoke->setParams(...) below.
1478  // This would avoid the 'const' qualifier of the calloperator from
1479  // contaminating the type of the invoker, which is currently adjusted
1480  // in SemaTemplateDeduction.cpp:DeduceTemplateArguments. Fixing the
1481  // trailing return type of the invoker would require a visitor to rebuild
1482  // the trailing return type and adjusting all back DeclRefExpr's to refer
1483  // to the new static invoker parameters - not the call operator's.
1485  S.Context, Class, Loc, DeclarationNameInfo(InvokerName, Loc),
1486  InvokerFunctionTy, CallOperator->getTypeSourceInfo(), SC_Static,
1487  /*isInline=*/true, ConstexprSpecKind::Unspecified,
1488  CallOperator->getBody()->getEndLoc());
1489  for (unsigned I = 0, N = CallOperator->getNumParams(); I != N; ++I)
1490  InvokerParams[I]->setOwningFunction(Invoke);
1491  Invoke->setParams(InvokerParams);
1492  Invoke->setAccess(AS_private);
1493  Invoke->setImplicit(true);
1494  if (Class->isGenericLambda()) {
1495  FunctionTemplateDecl *TemplateCallOperator =
1496  CallOperator->getDescribedFunctionTemplate();
1497  FunctionTemplateDecl *StaticInvokerTemplate = FunctionTemplateDecl::Create(
1498  S.Context, Class, Loc, InvokerName,
1499  TemplateCallOperator->getTemplateParameters(),
1500  Invoke);
1501  StaticInvokerTemplate->setAccess(AS_private);
1502  StaticInvokerTemplate->setImplicit(true);
1503  Invoke->setDescribedFunctionTemplate(StaticInvokerTemplate);
1504  Class->addDecl(StaticInvokerTemplate);
1505  } else
1506  Class->addDecl(Invoke);
1507 }
1508 
1509 /// Add a lambda's conversion to function pointers, as described in
1510 /// C++11 [expr.prim.lambda]p6. Note that in most cases, this should emit only a
1511 /// single pointer conversion. In the event that the default calling convention
1512 /// for free and member functions is different, it will emit both conventions.
1513 static void addFunctionPointerConversions(Sema &S, SourceRange IntroducerRange,
1514  CXXRecordDecl *Class,
1515  CXXMethodDecl *CallOperator) {
1516  const FunctionProtoType *CallOpProto =
1517  CallOperator->getType()->castAs<FunctionProtoType>();
1518 
1520  S, *CallOpProto, [&](CallingConv CC) {
1521  QualType InvokerFunctionTy =
1522  S.getLambdaConversionFunctionResultType(CallOpProto, CC);
1523  addFunctionPointerConversion(S, IntroducerRange, Class, CallOperator,
1524  InvokerFunctionTy);
1525  });
1526 }
1527 
1528 /// Add a lambda's conversion to block pointer.
1530  SourceRange IntroducerRange,
1531  CXXRecordDecl *Class,
1532  CXXMethodDecl *CallOperator) {
1533  const FunctionProtoType *CallOpProto =
1534  CallOperator->getType()->castAs<FunctionProtoType>();
1536  CallOpProto, getLambdaConversionFunctionCallConv(S, CallOpProto));
1537  QualType BlockPtrTy = S.Context.getBlockPointerType(FunctionTy);
1538 
1539  FunctionProtoType::ExtProtoInfo ConversionEPI(
1541  /*IsVariadic=*/false, /*IsCXXMethod=*/true));
1542  ConversionEPI.TypeQuals = Qualifiers();
1543  ConversionEPI.TypeQuals.addConst();
1544  QualType ConvTy = S.Context.getFunctionType(BlockPtrTy, None, ConversionEPI);
1545 
1546  SourceLocation Loc = IntroducerRange.getBegin();
1547  DeclarationName Name
1549  S.Context.getCanonicalType(BlockPtrTy));
1551  S.Context.getTrivialTypeSourceInfo(BlockPtrTy, Loc));
1553  S.Context, Class, Loc, DeclarationNameInfo(Name, Loc, NameLoc), ConvTy,
1554  S.Context.getTrivialTypeSourceInfo(ConvTy, Loc),
1555  /*isInline=*/true, ExplicitSpecifier(), ConstexprSpecKind::Unspecified,
1556  CallOperator->getBody()->getEndLoc());
1557  Conversion->setAccess(AS_public);
1558  Conversion->setImplicit(true);
1559  Class->addDecl(Conversion);
1560 }
1561 
1563  SourceLocation ImplicitCaptureLoc,
1564  bool IsOpenMPMapping) {
1565  // VLA captures don't have a stored initialization expression.
1566  if (Cap.isVLATypeCapture())
1567  return ExprResult();
1568 
1569  // An init-capture is initialized directly from its stored initializer.
1570  if (Cap.isInitCapture())
1571  return Cap.getVariable()->getInit();
1572 
1573  // For anything else, build an initialization expression. For an implicit
1574  // capture, the capture notionally happens at the capture-default, so use
1575  // that location here.
1576  SourceLocation Loc =
1577  ImplicitCaptureLoc.isValid() ? ImplicitCaptureLoc : Cap.getLocation();
1578 
1579  // C++11 [expr.prim.lambda]p21:
1580  // When the lambda-expression is evaluated, the entities that
1581  // are captured by copy are used to direct-initialize each
1582  // corresponding non-static data member of the resulting closure
1583  // object. (For array members, the array elements are
1584  // direct-initialized in increasing subscript order.) These
1585  // initializations are performed in the (unspecified) order in
1586  // which the non-static data members are declared.
1587 
1588  // C++ [expr.prim.lambda]p12:
1589  // An entity captured by a lambda-expression is odr-used (3.2) in
1590  // the scope containing the lambda-expression.
1591  ExprResult Init;
1592  IdentifierInfo *Name = nullptr;
1593  if (Cap.isThisCapture()) {
1594  QualType ThisTy = getCurrentThisType();
1595  Expr *This = BuildCXXThisExpr(Loc, ThisTy, ImplicitCaptureLoc.isValid());
1596  if (Cap.isCopyCapture())
1597  Init = CreateBuiltinUnaryOp(Loc, UO_Deref, This);
1598  else
1599  Init = This;
1600  } else {
1601  assert(Cap.isVariableCapture() && "unknown kind of capture");
1602  VarDecl *Var = Cap.getVariable();
1603  Name = Var->getIdentifier();
1604  Init = BuildDeclarationNameExpr(
1605  CXXScopeSpec(), DeclarationNameInfo(Var->getDeclName(), Loc), Var);
1606  }
1607 
1608  // In OpenMP, the capture kind doesn't actually describe how to capture:
1609  // variables are "mapped" onto the device in a process that does not formally
1610  // make a copy, even for a "copy capture".
1611  if (IsOpenMPMapping)
1612  return Init;
1613 
1614  if (Init.isInvalid())
1615  return ExprError();
1616 
1617  Expr *InitExpr = Init.get();
1619  Name, Cap.getCaptureType(), Loc);
1620  InitializationKind InitKind =
1621  InitializationKind::CreateDirect(Loc, Loc, Loc);
1622  InitializationSequence InitSeq(*this, Entity, InitKind, InitExpr);
1623  return InitSeq.Perform(*this, Entity, InitKind, InitExpr);
1624 }
1625 
1627  Scope *CurScope) {
1628  LambdaScopeInfo LSI = *cast<LambdaScopeInfo>(FunctionScopes.back());
1629  ActOnFinishFunctionBody(LSI.CallOperator, Body);
1630  return BuildLambdaExpr(StartLoc, Body->getEndLoc(), &LSI);
1631 }
1632 
1633 static LambdaCaptureDefault
1635  switch (ICS) {
1637  return LCD_None;
1639  return LCD_ByCopy;
1642  return LCD_ByRef;
1644  llvm_unreachable("block capture in lambda");
1645  }
1646  llvm_unreachable("Unknown implicit capture style");
1647 }
1648 
1650  if (From.isInitCapture()) {
1651  Expr *Init = From.getVariable()->getInit();
1652  if (Init && Init->HasSideEffects(Context))
1653  return true;
1654  }
1655 
1656  if (!From.isCopyCapture())
1657  return false;
1658 
1659  const QualType T = From.isThisCapture()
1660  ? getCurrentThisType()->getPointeeType()
1661  : From.getCaptureType();
1662 
1663  if (T.isVolatileQualified())
1664  return true;
1665 
1666  const Type *BaseT = T->getBaseElementTypeUnsafe();
1667  if (const CXXRecordDecl *RD = BaseT->getAsCXXRecordDecl())
1668  return !RD->isCompleteDefinition() || !RD->hasTrivialCopyConstructor() ||
1669  !RD->hasTrivialDestructor();
1670 
1671  return false;
1672 }
1673 
1675  const Capture &From) {
1676  if (CaptureHasSideEffects(From))
1677  return false;
1678 
1679  if (From.isVLATypeCapture())
1680  return false;
1681 
1682  auto diag = Diag(From.getLocation(), diag::warn_unused_lambda_capture);
1683  if (From.isThisCapture())
1684  diag << "'this'";
1685  else
1686  diag << From.getVariable();
1687  diag << From.isNonODRUsed();
1688  diag << FixItHint::CreateRemoval(CaptureRange);
1689  return true;
1690 }
1691 
1692 /// Create a field within the lambda class or captured statement record for the
1693 /// given capture.
1695  const sema::Capture &Capture) {
1697  QualType FieldType = Capture.getCaptureType();
1698 
1699  TypeSourceInfo *TSI = nullptr;
1700  if (Capture.isVariableCapture()) {
1701  auto *Var = Capture.getVariable();
1702  if (Var->isInitCapture())
1704  }
1705 
1706  // FIXME: Should we really be doing this? A null TypeSourceInfo seems more
1707  // appropriate, at least for an implicit capture.
1708  if (!TSI)
1709  TSI = Context.getTrivialTypeSourceInfo(FieldType, Loc);
1710 
1711  // Build the non-static data member.
1712  FieldDecl *Field =
1713  FieldDecl::Create(Context, RD, /*StartLoc=*/Loc, /*IdLoc=*/Loc,
1714  /*Id=*/nullptr, FieldType, TSI, /*BW=*/nullptr,
1715  /*Mutable=*/false, ICIS_NoInit);
1716  // If the variable being captured has an invalid type, mark the class as
1717  // invalid as well.
1718  if (!FieldType->isDependentType()) {
1719  if (RequireCompleteSizedType(Loc, FieldType,
1720  diag::err_field_incomplete_or_sizeless)) {
1721  RD->setInvalidDecl();
1722  Field->setInvalidDecl();
1723  } else {
1724  NamedDecl *Def;
1725  FieldType->isIncompleteType(&Def);
1726  if (Def && Def->isInvalidDecl()) {
1727  RD->setInvalidDecl();
1728  Field->setInvalidDecl();
1729  }
1730  }
1731  }
1732  Field->setImplicit(true);
1733  Field->setAccess(AS_private);
1734  RD->addDecl(Field);
1735 
1736  if (Capture.isVLATypeCapture())
1737  Field->setCapturedVLAType(Capture.getCapturedVLAType());
1738 
1739  return Field;
1740 }
1741 
1743  LambdaScopeInfo *LSI) {
1744  // Collect information from the lambda scope.
1746  SmallVector<Expr *, 4> CaptureInits;
1747  SourceLocation CaptureDefaultLoc = LSI->CaptureDefaultLoc;
1748  LambdaCaptureDefault CaptureDefault =
1750  CXXRecordDecl *Class;
1751  CXXMethodDecl *CallOperator;
1752  SourceRange IntroducerRange;
1753  bool ExplicitParams;
1754  bool ExplicitResultType;
1755  CleanupInfo LambdaCleanup;
1756  bool ContainsUnexpandedParameterPack;
1757  bool IsGenericLambda;
1758  {
1759  CallOperator = LSI->CallOperator;
1760  Class = LSI->Lambda;
1761  IntroducerRange = LSI->IntroducerRange;
1762  ExplicitParams = LSI->ExplicitParams;
1763  ExplicitResultType = !LSI->HasImplicitReturnType;
1764  LambdaCleanup = LSI->Cleanup;
1765  ContainsUnexpandedParameterPack = LSI->ContainsUnexpandedParameterPack;
1766  IsGenericLambda = Class->isGenericLambda();
1767 
1768  CallOperator->setLexicalDeclContext(Class);
1769  Decl *TemplateOrNonTemplateCallOperatorDecl =
1770  CallOperator->getDescribedFunctionTemplate()
1771  ? CallOperator->getDescribedFunctionTemplate()
1772  : cast<Decl>(CallOperator);
1773 
1774  // FIXME: Is this really the best choice? Keeping the lexical decl context
1775  // set as CurContext seems more faithful to the source.
1776  TemplateOrNonTemplateCallOperatorDecl->setLexicalDeclContext(Class);
1777 
1778  PopExpressionEvaluationContext();
1779 
1780  // True if the current capture has a used capture or default before it.
1781  bool CurHasPreviousCapture = CaptureDefault != LCD_None;
1782  SourceLocation PrevCaptureLoc = CurHasPreviousCapture ?
1783  CaptureDefaultLoc : IntroducerRange.getBegin();
1784 
1785  for (unsigned I = 0, N = LSI->Captures.size(); I != N; ++I) {
1786  const Capture &From = LSI->Captures[I];
1787 
1788  if (From.isInvalid())
1789  return ExprError();
1790 
1791  assert(!From.isBlockCapture() && "Cannot capture __block variables");
1792  bool IsImplicit = I >= LSI->NumExplicitCaptures;
1793  SourceLocation ImplicitCaptureLoc =
1794  IsImplicit ? CaptureDefaultLoc : SourceLocation();
1795 
1796  // Use source ranges of explicit captures for fixits where available.
1797  SourceRange CaptureRange = LSI->ExplicitCaptureRanges[I];
1798 
1799  // Warn about unused explicit captures.
1800  bool IsCaptureUsed = true;
1801  if (!CurContext->isDependentContext() && !IsImplicit &&
1802  !From.isODRUsed()) {
1803  // Initialized captures that are non-ODR used may not be eliminated.
1804  // FIXME: Where did the IsGenericLambda here come from?
1805  bool NonODRUsedInitCapture =
1806  IsGenericLambda && From.isNonODRUsed() && From.isInitCapture();
1807  if (!NonODRUsedInitCapture) {
1808  bool IsLast = (I + 1) == LSI->NumExplicitCaptures;
1809  SourceRange FixItRange;
1810  if (CaptureRange.isValid()) {
1811  if (!CurHasPreviousCapture && !IsLast) {
1812  // If there are no captures preceding this capture, remove the
1813  // following comma.
1814  FixItRange = SourceRange(CaptureRange.getBegin(),
1815  getLocForEndOfToken(CaptureRange.getEnd()));
1816  } else {
1817  // Otherwise, remove the comma since the last used capture.
1818  FixItRange = SourceRange(getLocForEndOfToken(PrevCaptureLoc),
1819  CaptureRange.getEnd());
1820  }
1821  }
1822 
1823  IsCaptureUsed = !DiagnoseUnusedLambdaCapture(FixItRange, From);
1824  }
1825  }
1826 
1827  if (CaptureRange.isValid()) {
1828  CurHasPreviousCapture |= IsCaptureUsed;
1829  PrevCaptureLoc = CaptureRange.getEnd();
1830  }
1831 
1832  // Map the capture to our AST representation.
1833  LambdaCapture Capture = [&] {
1834  if (From.isThisCapture()) {
1835  // Capturing 'this' implicitly with a default of '[=]' is deprecated,
1836  // because it results in a reference capture. Don't warn prior to
1837  // C++2a; there's nothing that can be done about it before then.
1838  if (getLangOpts().CPlusPlus20 && IsImplicit &&
1839  CaptureDefault == LCD_ByCopy) {
1840  Diag(From.getLocation(), diag::warn_deprecated_this_capture);
1841  Diag(CaptureDefaultLoc, diag::note_deprecated_this_capture)
1843  getLocForEndOfToken(CaptureDefaultLoc), ", this");
1844  }
1845  return LambdaCapture(From.getLocation(), IsImplicit,
1846  From.isCopyCapture() ? LCK_StarThis : LCK_This);
1847  } else if (From.isVLATypeCapture()) {
1848  return LambdaCapture(From.getLocation(), IsImplicit, LCK_VLAType);
1849  } else {
1850  assert(From.isVariableCapture() && "unknown kind of capture");
1851  VarDecl *Var = From.getVariable();
1853  From.isCopyCapture() ? LCK_ByCopy : LCK_ByRef;
1854  return LambdaCapture(From.getLocation(), IsImplicit, Kind, Var,
1855  From.getEllipsisLoc());
1856  }
1857  }();
1858 
1859  // Form the initializer for the capture field.
1860  ExprResult Init = BuildCaptureInit(From, ImplicitCaptureLoc);
1861 
1862  // FIXME: Skip this capture if the capture is not used, the initializer
1863  // has no side-effects, the type of the capture is trivial, and the
1864  // lambda is not externally visible.
1865 
1866  // Add a FieldDecl for the capture and form its initializer.
1867  BuildCaptureField(Class, From);
1868  Captures.push_back(Capture);
1869  CaptureInits.push_back(Init.get());
1870 
1871  if (LangOpts.CUDA)
1872  CUDACheckLambdaCapture(CallOperator, From);
1873  }
1874 
1875  Class->setCaptures(Context, Captures);
1876 
1877  // C++11 [expr.prim.lambda]p6:
1878  // The closure type for a lambda-expression with no lambda-capture
1879  // has a public non-virtual non-explicit const conversion function
1880  // to pointer to function having the same parameter and return
1881  // types as the closure type's function call operator.
1882  if (Captures.empty() && CaptureDefault == LCD_None)
1883  addFunctionPointerConversions(*this, IntroducerRange, Class,
1884  CallOperator);
1885 
1886  // Objective-C++:
1887  // The closure type for a lambda-expression has a public non-virtual
1888  // non-explicit const conversion function to a block pointer having the
1889  // same parameter and return types as the closure type's function call
1890  // operator.
1891  // FIXME: Fix generic lambda to block conversions.
1892  if (getLangOpts().Blocks && getLangOpts().ObjC && !IsGenericLambda)
1893  addBlockPointerConversion(*this, IntroducerRange, Class, CallOperator);
1894 
1895  // Finalize the lambda class.
1896  SmallVector<Decl*, 4> Fields(Class->fields());
1897  ActOnFields(nullptr, Class->getLocation(), Class, Fields, SourceLocation(),
1899  CheckCompletedCXXClass(nullptr, Class);
1900  }
1901 
1902  Cleanup.mergeFrom(LambdaCleanup);
1903 
1904  LambdaExpr *Lambda = LambdaExpr::Create(Context, Class, IntroducerRange,
1905  CaptureDefault, CaptureDefaultLoc,
1906  ExplicitParams, ExplicitResultType,
1907  CaptureInits, EndLoc,
1908  ContainsUnexpandedParameterPack);
1909  // If the lambda expression's call operator is not explicitly marked constexpr
1910  // and we are not in a dependent context, analyze the call operator to infer
1911  // its constexpr-ness, suppressing diagnostics while doing so.
1912  if (getLangOpts().CPlusPlus17 && !CallOperator->isInvalidDecl() &&
1913  !CallOperator->isConstexpr() &&
1914  !isa<CoroutineBodyStmt>(CallOperator->getBody()) &&
1915  !Class->getDeclContext()->isDependentContext()) {
1916  CallOperator->setConstexprKind(
1917  CheckConstexprFunctionDefinition(CallOperator,
1918  CheckConstexprKind::CheckValid)
1921  }
1922 
1923  // Emit delayed shadowing warnings now that the full capture list is known.
1924  DiagnoseShadowingLambdaDecls(LSI);
1925 
1926  if (!CurContext->isDependentContext()) {
1927  switch (ExprEvalContexts.back().Context) {
1928  // C++11 [expr.prim.lambda]p2:
1929  // A lambda-expression shall not appear in an unevaluated operand
1930  // (Clause 5).
1931  case ExpressionEvaluationContext::Unevaluated:
1932  case ExpressionEvaluationContext::UnevaluatedList:
1933  case ExpressionEvaluationContext::UnevaluatedAbstract:
1934  // C++1y [expr.const]p2:
1935  // A conditional-expression e is a core constant expression unless the
1936  // evaluation of e, following the rules of the abstract machine, would
1937  // evaluate [...] a lambda-expression.
1938  //
1939  // This is technically incorrect, there are some constant evaluated contexts
1940  // where this should be allowed. We should probably fix this when DR1607 is
1941  // ratified, it lays out the exact set of conditions where we shouldn't
1942  // allow a lambda-expression.
1943  case ExpressionEvaluationContext::ConstantEvaluated:
1944  // We don't actually diagnose this case immediately, because we
1945  // could be within a context where we might find out later that
1946  // the expression is potentially evaluated (e.g., for typeid).
1947  ExprEvalContexts.back().Lambdas.push_back(Lambda);
1948  break;
1949 
1950  case ExpressionEvaluationContext::DiscardedStatement:
1951  case ExpressionEvaluationContext::PotentiallyEvaluated:
1952  case ExpressionEvaluationContext::PotentiallyEvaluatedIfUsed:
1953  break;
1954  }
1955  }
1956 
1957  return MaybeBindToTemporary(Lambda);
1958 }
1959 
1961  SourceLocation ConvLocation,
1962  CXXConversionDecl *Conv,
1963  Expr *Src) {
1964  // Make sure that the lambda call operator is marked used.
1965  CXXRecordDecl *Lambda = Conv->getParent();
1966  CXXMethodDecl *CallOperator
1967  = cast<CXXMethodDecl>(
1968  Lambda->lookup(
1969  Context.DeclarationNames.getCXXOperatorName(OO_Call)).front());
1970  CallOperator->setReferenced();
1971  CallOperator->markUsed(Context);
1972 
1973  ExprResult Init = PerformCopyInitialization(
1975  /*NRVO=*/false),
1976  CurrentLocation, Src);
1977  if (!Init.isInvalid())
1978  Init = ActOnFinishFullExpr(Init.get(), /*DiscardedValue*/ false);
1979 
1980  if (Init.isInvalid())
1981  return ExprError();
1982 
1983  // Create the new block to be returned.
1984  BlockDecl *Block = BlockDecl::Create(Context, CurContext, ConvLocation);
1985 
1986  // Set the type information.
1987  Block->setSignatureAsWritten(CallOperator->getTypeSourceInfo());
1988  Block->setIsVariadic(CallOperator->isVariadic());
1989  Block->setBlockMissingReturnType(false);
1990 
1991  // Add parameters.
1992  SmallVector<ParmVarDecl *, 4> BlockParams;
1993  for (unsigned I = 0, N = CallOperator->getNumParams(); I != N; ++I) {
1994  ParmVarDecl *From = CallOperator->getParamDecl(I);
1995  BlockParams.push_back(ParmVarDecl::Create(
1996  Context, Block, From->getBeginLoc(), From->getLocation(),
1997  From->getIdentifier(), From->getType(), From->getTypeSourceInfo(),
1998  From->getStorageClass(),
1999  /*DefArg=*/nullptr));
2000  }
2001  Block->setParams(BlockParams);
2002 
2003  Block->setIsConversionFromLambda(true);
2004 
2005  // Add capture. The capture uses a fake variable, which doesn't correspond
2006  // to any actual memory location. However, the initializer copy-initializes
2007  // the lambda object.
2008  TypeSourceInfo *CapVarTSI =
2009  Context.getTrivialTypeSourceInfo(Src->getType());
2010  VarDecl *CapVar = VarDecl::Create(Context, Block, ConvLocation,
2011  ConvLocation, nullptr,
2012  Src->getType(), CapVarTSI,
2013  SC_None);
2014  BlockDecl::Capture Capture(/*variable=*/CapVar, /*byRef=*/false,
2015  /*nested=*/false, /*copy=*/Init.get());
2016  Block->setCaptures(Context, Capture, /*CapturesCXXThis=*/false);
2017 
2018  // Add a fake function body to the block. IR generation is responsible
2019  // for filling in the actual body, which cannot be expressed as an AST.
2020  Block->setBody(new (Context) CompoundStmt(ConvLocation));
2021 
2022  // Create the block literal expression.
2023  Expr *BuildBlock = new (Context) BlockExpr(Block, Conv->getConversionType());
2024  ExprCleanupObjects.push_back(Block);
2025  Cleanup.setExprNeedsCleanups(true);
2026 
2027  return BuildBlock;
2028 }
clang::Decl::setLexicalDeclContext
void setLexicalDeclContext(DeclContext *DC)
Definition: DeclBase.cpp:331
clang::DeclarationNameLoc::makeCXXOperatorNameLoc
static DeclarationNameLoc makeCXXOperatorNameLoc(SourceLocation BeginLoc, SourceLocation EndLoc)
Construct location information for a non-literal C++ operator.
Definition: DeclarationName.h:736
clang::Sema::finishLambdaExplicitCaptures
void finishLambdaExplicitCaptures(sema::LambdaScopeInfo *LSI)
Note that we have finished the explicit captures for the given lambda.
Definition: SemaLambda.cpp:516
clang::ExplicitSpecifier
Store information needed for an explicit specifier.
Definition: DeclCXX.h:1793
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:3491
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:1315
clang::sema::CapturingScopeInfo::addCapture
void addCapture(VarDecl *Var, bool isBlock, bool isByref, bool isNested, SourceLocation Loc, SourceLocation EllipsisLoc, QualType CaptureType, bool Invalid)
Definition: ScopeInfo.h:686
clang::sema::Capture::isThisCapture
bool isThisCapture() const
Definition: ScopeInfo.h:604
clang::sema::LambdaScopeInfo::ExplicitTemplateParamsRange
SourceRange ExplicitTemplateParamsRange
Source range covering the explicit template parameter list (if it exists).
Definition: ScopeInfo.h:854
clang::DeclSpec::SetTypeQual
bool SetTypeQual(TQ T, SourceLocation Loc)
Definition: DeclSpec.cpp:971
clang::Type::getNullability
Optional< NullabilityKind > getNullability(const ASTContext &context) const
Determine the nullability of the given type.
Definition: Type.cpp:4025
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:2760
clang::sema::Capture::getLocation
SourceLocation getLocation() const
Retrieve the location at which this variable was captured.
Definition: ScopeInfo.h:641
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:1272
clang::TemplateParameterList::Create
static TemplateParameterList * Create(const ASTContext &C, SourceLocation TemplateLoc, SourceLocation LAngleLoc, ArrayRef< NamedDecl * > Params, SourceLocation RAngleLoc, Expr *RequiresClause)
Definition: DeclTemplate.cpp:90
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:1453
clang::CC_X86FastCall
@ CC_X86FastCall
Definition: Specifiers.h:256
TypeLocBuilder.h
clang::FunctionDecl::getNumParams
unsigned getNumParams() const
Return the number of parameters this function must have based on its FunctionType.
Definition: Decl.cpp:3321
clang::DeclaratorChunk::FunctionTypeInfo::hasTrailingReturnType
bool hasTrailingReturnType() const
Determine whether this function declarator had a trailing-return-type.
Definition: DeclSpec.h:1498
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:695
clang::TypeSourceInfo::getType
QualType getType() const
Return the type wrapped by this type source info.
Definition: Type.h:6402
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:2665
clang::FunctionDecl::getReturnType
QualType getReturnType() const
Definition: Decl.h:2502
clang::DeclaratorDecl::getBeginLoc
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Decl.h:748
clang::DeclarationNameLoc
DeclarationNameLoc - Additional source/type location info for a declaration name.
Definition: DeclarationName.h:650
clang::sema::Capture::isODRUsed
bool isODRUsed() const
Definition: ScopeInfo.h:621
Error
llvm::Error Error
Definition: ByteCodeEmitter.cpp:19
clang::SourceRange
A trivial tuple used to represent a source range.
Definition: SourceLocation.h:212
clang::DeclContext
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1347
clang::sema::LambdaScopeInfo::ExplicitParams
bool ExplicitParams
Whether the (empty) parameter list is explicit.
Definition: ScopeInfo.h:842
clang::PointerTypeLoc
Wrapper for source info for pointers.
Definition: TypeLoc.h:1226
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:2721
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:520
clang::TargetInfo::checkCallingConvention
virtual CallingConvCheckResult checkCallingConvention(CallingConv CC) const
Determines whether a given calling convention is valid for the target.
Definition: TargetInfo.h:1435
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:96
clang::Sema::getASTContext
ASTContext & getASTContext() const
Definition: Sema.h:1537
clang::ReferenceTypeLoc
Definition: TypeLoc.h:1307
clang::Declarator::getNumTypeObjects
unsigned getNumTypeObjects() const
Return the number of types applied to this declarator.
Definition: DeclSpec.h:2236
clang::FunctionDecl::isConstexpr
bool isConstexpr() const
Whether this is a (C++11) constexpr function or constexpr constructor.
Definition: Decl.h:2248
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:78
clang::DeclaratorChunk::FunctionTypeInfo::hasMutableQualifier
bool hasMutableQualifier() const
Determine whether this lambda-declarator contains a 'mutable' qualifier.
Definition: DeclSpec.h:1470
SemaInternal.h
clang::sema::Capture::isInitCapture
bool isInitCapture() const
Determine whether this capture is an init-capture.
Definition: ScopeInfo.cpp:220
clang::ASTContext::VoidTy
CanQualType VoidTy
Definition: ASTContext.h:995
clang::sema::Capture::getVariable
VarDecl * getVariable() const
Definition: ScopeInfo.h:630
clang::sema::LambdaScopeInfo::Mutable
bool Mutable
Whether this is a mutable lambda.
Definition: ScopeInfo.h:839
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:528
clang::Declarator::getSourceRange
SourceRange getSourceRange() const LLVM_READONLY
Get the source range that spans this declarator.
Definition: DeclSpec.h:1945
clang::if
if(T->getSizeExpr()) TRY_TO(TraverseStmt(T -> getSizeExpr()))
Definition: RecursiveASTVisitor.h:996
clang::SourceLocation
Encodes a location in the source.
Definition: SourceLocation.h:89
clang::ASTContext::getManglingNumberContext
MangleNumberingContext & getManglingNumberContext(const DeclContext *DC)
Retrieve the context for computing mangling numbers in the given DeclContext.
Definition: ASTContext.cpp:11143
clang::VarDecl::isInitCapture
bool isInitCapture() const
Whether this variable is the implicit variable for a lambda init-capture.
Definition: Decl.h:1456
clang::NamedDecl
This represents a decl that may have a name.
Definition: Decl.h:223
clang::ParenListExpr
Definition: Expr.h:5456
clang::SourceRange::getBegin
SourceLocation getBegin() const
Definition: SourceLocation.h:221
clang::AS_private
@ AS_private
Definition: Specifiers.h:101
clang::VarDecl::setInit
void setInit(Expr *I)
Definition: Decl.cpp:2295
TargetInfo.h
clang::LambdaIntroducer::Captures
SmallVector< LambdaCapture, 4 > Captures
Definition: DeclSpec.h:2690
clang::sema::LambdaScopeInfo::NumExplicitCaptures
unsigned NumExplicitCaptures
The number of captures in the Captures list that are explicit captures.
Definition: ScopeInfo.h:836
clang::ASTContext::DeclarationNames
DeclarationNameTable DeclarationNames
Definition: ASTContext.h:614
clang::TypeLocBuilder::getTypeSourceInfo
TypeSourceInfo * getTypeSourceInfo(ASTContext &Context, QualType T)
Creates a TypeSourceInfo for the given type.
Definition: TypeLocBuilder.h:101
clang::MultiExprArg
MutableArrayRef< Expr * > MultiExprArg
Definition: Ownership.h:272
clang::QualType
A (possibly-)qualified type.
Definition: Type.h:661
clang::FunctionDecl::getParamDecl
const ParmVarDecl * getParamDecl(unsigned i) const
Definition: Decl.h:2471
clang::InitializedEntity::InitializeLambdaCapture
static InitializedEntity InitializeLambdaCapture(IdentifierInfo *VarID, QualType FieldType, SourceLocation Loc)
Create the initialization entity for a lambda capture.
Definition: Initialization.h:406
clang::FieldDecl
Represents a member of a struct/union/class.
Definition: Decl.h:2792
clang::FunctionProtoType::ExtProtoInfo::RefQualifier
RefQualifierKind RefQualifier
Definition: Type.h:3968
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:145
clang::ParmVarDecl
Represents a parameter to a function.
Definition: Decl.h:1630
clang::TargetInfo
Exposes information about the current target.
Definition: TargetInfo.h:188
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:864
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:1437
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:1866
clang::SourceRange::isValid
bool isValid() const
Definition: SourceLocation.h:227
clang::sema::CapturingScopeInfo::ImplicitCaptureStyle
ImplicitCaptureStyle
Definition: ScopeInfo.h:658
llvm::Optional< unsigned >
clang::getLambdaAwareParentOfDeclContext
DeclContext * getLambdaAwareParentOfDeclContext(DeclContext *DC)
Definition: ASTLambda.h:81
clang::Type::isVoidType
bool isVoidType() const
Definition: Type.h:6951
clang::InitializationKind::CreateDirect
static InitializationKind CreateDirect(SourceLocation InitLoc, SourceLocation LParenLoc, SourceLocation RParenLoc)
Create a direct initialization.
Definition: Initialization.h:621
clang::QualType::isVolatileQualified
bool isVolatileQualified() const
Determine whether this type is volatile-qualified.
Definition: Type.h:6490
clang::CPlusPlus14
@ CPlusPlus14
Definition: LangStandard.h:50
DeclSpec.h
clang::CXXScopeSpec
Represents a C++ nested-name-specifier or a global scope specifier.
Definition: DeclSpec.h:64
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:889
clang::sema::Capture
Definition: ScopeInfo.h:521
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:1694
clang::CXXMethodDecl::Create
static CXXMethodDecl * Create(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo, StorageClass SC, bool isInline, ConstexprSpecKind ConstexprKind, SourceLocation EndLocation, Expr *TrailingRequiresClause=nullptr)
Definition: DeclCXX.cpp:2193
clang::DeclContext::getLexicalParent
DeclContext * getLexicalParent()
getLexicalParent - Returns the containing lexical DeclContext.
Definition: DeclBase.h:1876
clang::InitializationSequence
Describes the sequence of initializations required to initialize a given object or reference with a s...
Definition: Initialization.h:782
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:4997
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:302
clang::sema::LambdaScopeInfo::RequiresClause
ExprResult RequiresClause
The requires-clause immediately following the explicit template parameter list, if any.
Definition: ScopeInfo.h:859
clang::sema::LambdaScopeInfo::finishedExplicitCaptures
void finishedExplicitCaptures()
Note when all explicit captures have been added.
Definition: ScopeInfo.h:907
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:59
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:1742
clang::DeclarationName
The name of a declaration.
Definition: DeclarationName.h:145
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:200
clang::ASTContext::getTranslationUnitDecl
TranslationUnitDecl * getTranslationUnitDecl() const
Definition: ASTContext.h:988
clang::sema::LambdaScopeInfo::CallOperator
CXXMethodDecl * CallOperator
The lambda's compiler-generated operator().
Definition: ScopeInfo.h:825
clang::sema::Capture::isCopyCapture
bool isCopyCapture() const
Definition: ScopeInfo.h:609
clang::Decl::markUsed
void markUsed(ASTContext &C)
Mark the declaration used, in the sense of odr-use.
Definition: DeclBase.cpp:458
clang::LambdaCaptureInitKind::DirectInit
@ DirectInit
[a(b)]
clang::CC_X86StdCall
@ CC_X86StdCall
Definition: Specifiers.h:255
clang::FunctionDecl::isConsteval
bool isConsteval() const
Definition: Decl.h:2260
clang::EnumDecl
Represents an enum.
Definition: Decl.h:3547
clang::FunctionProtoType::isVariadic
bool isVariadic() const
Whether this function prototype is variadic.
Definition: Type.h:4212
clang::ASTContext::getCanonicalFunctionResultType
CanQualType getCanonicalFunctionResultType(QualType ResultType) const
Adjust the given function result type.
Definition: ASTContext.cpp:4187
clang::Declarator::getTrailingRequiresClause
Expr * getTrailingRequiresClause()
Sets a trailing requires clause for this declarator.
Definition: DeclSpec.h:2473
clang::Sema::Context
ASTContext & Context
Definition: Sema.h:411
clang::Type
The base class of the type hierarchy.
Definition: Type.h:1478
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:4112
clang::ReturnStmt::setRetValue
void setRetValue(Expr *E)
Definition: Stmt.h:2762
clang::ExprError
ExprResult ExprError()
Definition: Ownership.h:278
clang::ConditionalOperator
ConditionalOperator - The ?: ternary operator.
Definition: Expr.h:4065
clang::sema::CapturingScopeInfo::ImpCap_Block
@ ImpCap_Block
Definition: ScopeInfo.h:659
clang::CPlusPlus17
@ CPlusPlus17
Definition: LangStandard.h:51
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:3267
clang::Sema::getLangOpts
const LangOptions & getLangOpts() const
Definition: Sema.h:1530
clang::DeclarationNameLoc::makeNamedTypeLoc
static DeclarationNameLoc makeNamedTypeLoc(TypeSourceInfo *TInfo)
Construct location information for a constructor, destructor or conversion operator.
Definition: DeclarationName.h:729
clang::sema::LambdaScopeInfo::Lambda
CXXRecordDecl * Lambda
The class that describes the lambda.
Definition: ScopeInfo.h:822
clang::Declarator::getDeclSpec
const DeclSpec & getDeclSpec() const
getDeclSpec - Return the declaration-specifier that this declarator was declared with.
Definition: DeclSpec.h:1910
clang::VarDecl::isParameterPack
bool isParameterPack() const
Determine whether this variable is actually a function parameter pack or init-capture pack.
Definition: Decl.cpp:2494
clang::FunctionTemplateDecl
Declaration of a template function.
Definition: DeclTemplate.h:973
llvm::MutableArrayRef
Definition: LLVM.h:35
clang::Type::isReferenceType
bool isReferenceType() const
Definition: Type.h:6680
clang::TypeLocBuilder::push
TyLocType push(QualType T)
Pushes space for a new TypeLoc of the given type.
Definition: TypeLocBuilder.h:93
clang::FunctionDecl::setConstexprKind
void setConstexprKind(ConstexprSpecKind CSK)
Definition: Decl.h:2251
clang::PackExpansionTypeLoc
Definition: TypeLoc.h:2437
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:1248
getLambdaConversionFunctionCallConv
static CallingConv getLambdaConversionFunctionCallConv(Sema &S, const FunctionProtoType *CallOpProto)
Definition: SemaLambda.cpp:1320
clang::CompoundStmt
CompoundStmt - This represents a group of statements like { stmt stmt }.
Definition: Stmt.h:1398
clang::PackExpansionType
Represents a pack expansion of types.
Definition: Type.h:5627
clang::FTIHasNonVoidParameters
bool FTIHasNonVoidParameters(const DeclaratorChunk::FunctionTypeInfo &FTI)
Definition: SemaInternal.h:36
clang::Scope::getTemplateParamParent
Scope * getTemplateParamParent()
Definition: Scope.h:279
clang::Sema::startLambdaDefinition
CXXMethodDecl * startLambdaDefinition(CXXRecordDecl *Class, SourceRange IntroducerRange, TypeSourceInfo *MethodType, SourceLocation EndLoc, ArrayRef< ParmVarDecl * > Params, ConstexprSpecKind ConstexprKind, Expr *TrailingRequiresClause)
Start the definition of a lambda expression.
Definition: SemaLambda.cpp:359
clang::BlockDecl
Represents a block literal declaration, which is like an unnamed FunctionDecl.
Definition: Decl.h:4110
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:10989
clang::BinaryOperator
A builtin binary operation expression such as "x + y" or "x <= y".
Definition: Expr.h:3727
clang::Decl::setAccess
void setAccess(AccessSpecifier AS)
Definition: DeclBase.h:473
Id
int Id
Definition: ASTDiff.cpp:191
clang::LambdaExpr
A C++ lambda expression, which produces a function object (of unspecified type) that can be invoked l...
Definition: ExprCXX.h:1865
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:635
clang::sema::LambdaScopeInfo::PotentialThisCaptureLocation
SourceLocation PotentialThisCaptureLocation
Definition: ScopeInfo.h:899
clang::SourceRange::getEnd
SourceLocation getEnd() const
Definition: SourceLocation.h:222
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:650
clang::AS_public
@ AS_public
Definition: Specifiers.h:99
clang::sema::CapturingScopeInfo::ImpCap_None
@ ImpCap_None
Definition: ScopeInfo.h:659
clang::ASTContext::DependentTy
CanQualType DependentTy
Definition: ASTContext.h:1025
clang::FPOptionsOverride
Represents difference between two FPOptions values.
Definition: LangOptions.h:551
clang::ASTContext
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:187
clang::ExprResult
ActionResult< Expr * > ExprResult
Definition: Ownership.h:262
clang::DeclContextLookupResult::front
reference front() const
Definition: DeclBase.h:1315
clang::CPlusPlus
@ CPlusPlus
Definition: LangStandard.h:48
clang::sema::Capture::isInvalid
bool isInvalid() const
Definition: ScopeInfo.h:616
clang::DeclarationNameTable::getCXXOperatorName
DeclarationName getCXXOperatorName(OverloadedOperatorKind Op)
Get the name of the overloadable C++ operator corresponding to Op.
Definition: DeclarationName.h:639
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:1335
clang::Sema::TryCapture_Implicit
@ TryCapture_Implicit
Definition: Sema.h:4976
clang::DeclaratorChunk::FunctionTypeInfo::getOrCreateMethodQualifiers
DeclSpec & getOrCreateMethodQualifiers()
Definition: DeclSpec.h:1409
clang::Sema::createLambdaClosureType
CXXRecordDecl * createLambdaClosureType(SourceRange IntroducerRange, TypeSourceInfo *Info, bool KnownDependent, LambdaCaptureDefault CaptureDefault)
Create a new lambda closure type.
Definition: SemaLambda.cpp:241
clang::sema::Capture::isNonODRUsed
bool isNonODRUsed() const
Definition: ScopeInfo.h:622
clang::FunctionDecl::getBody
Stmt * getBody(const FunctionDecl *&Definition) const
Retrieve the body (definition) of the function.
Definition: Decl.cpp:2980
clang::DeclaratorChunk::FunctionTypeInfo
Definition: DeclSpec.h:1276
clang::Type::getAs
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:7153
clang::Decl::isInvalidDecl
bool isInvalidDecl() const
Definition: DeclBase.h:558
clang::FunctionType::getCallConv
CallingConv getCallConv() const
Definition: Type.h:3815
clang::TargetInfo::CCCR_OK
@ CCCR_OK
Definition: TargetInfo.h:1425
clang::VarDecl::setInitCapture
void setInitCapture(bool IC)
Definition: Decl.h:1459
clang::LambdaCaptureDefault
LambdaCaptureDefault
The default, if any, capture method for a lambda expression.
Definition: Lambda.h:22
clang::Sema::tryCaptureVariable
bool tryCaptureVariable(VarDecl *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:17619
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:5589
clang::ParenListExpr::getNumExprs
unsigned getNumExprs() const
Return the number of expressions in this paren list.
Definition: Expr.h:5482
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:1864
clang::DeclContext::isTranslationUnit
bool isTranslationUnit() const
Definition: DeclBase.h:1935
clang::FunctionProtoType::ExtProtoInfo::ExtInfo
FunctionType::ExtInfo ExtInfo
Definition: Type.h:3964
clang::sema::CapturingScopeInfo::ImpCap_CapturedRegion
@ ImpCap_CapturedRegion
Definition: ScopeInfo.h:660
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:1241
clang::CPlusPlus20
@ CPlusPlus20
Definition: LangStandard.h:52
clang::LCD_ByCopy
@ LCD_ByCopy
Definition: Lambda.h:24
clang::CallingConv
CallingConv
CallingConv - Specifies the calling convention that a function uses.
Definition: Specifiers.h:253
clang::VarDecl
Represents a variable declaration or definition.
Definition: Decl.h:844
clang::FunctionProtoType::getParamTypes
ArrayRef< QualType > getParamTypes() const
Definition: Type.h:4097
clang::sema::CapturingScopeInfo::getCapture
Capture & getCapture(VarDecl *Var)
Retrieve the capture of the given variable, if it has been captured already.
Definition: ScopeInfo.h:722
clang::ConstexprSpecKind::Constexpr
@ Constexpr
clang::LambdaIntroducer::Default
LambdaCaptureDefault Default
Definition: DeclSpec.h:2689
clang::TemplateParameterList
Stores a list of template parameters for a TemplateDecl and its derived classes.
Definition: DeclTemplate.h:69
clang::ExprWithCleanups
Represents an expression – generally a full-expression – that introduces cleanups to be run at the en...
Definition: ExprCXX.h:3342
clang::ASTContext::getCanonicalType
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
Definition: ASTContext.h:2375
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:1753
clang::RQ_None
@ RQ_None
No ref-qualifier was provided.
Definition: Type.h:1431
clang::FunctionType::ExtInfo::withCallingConv
ExtInfo withCallingConv(CallingConv cc) const
Definition: Type.h:3767
clang::EnumConstantDecl
An instance of this object exists for each enum constant that is defined.
Definition: Decl.h:3007
clang::FunctionDecl::setParams
void setParams(ArrayRef< ParmVarDecl * > NewParamInfo)
Definition: Decl.h:2479
ExprCXX.h
clang::LCD_None
@ LCD_None
Definition: Lambda.h:23
clang::DeclContext::isRecord
bool isRecord() const
Definition: DeclBase.h:1939
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:1340
clang::Decl::setImplicit
void setImplicit(bool I=true)
Definition: DeclBase.h:564
clang::sema::CapturingScopeInfo::ImpCaptureStyle
ImplicitCaptureStyle ImpCaptureStyle
Definition: ScopeInfo.h:663
clang::CXXConversionDecl::Create
static CXXConversionDecl * Create(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo, bool isInline, ExplicitSpecifier ES, ConstexprSpecKind ConstexprKind, SourceLocation EndLocation, Expr *TrailingRequiresClause=nullptr)
Definition: DeclCXX.cpp:2789
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:2298
clang::TypeLocBuilder
Definition: TypeLocBuilder.h:22
clang::DeclaratorChunk::ParamInfo::Param
Decl * Param
Definition: DeclSpec.h:1254
clang::AutoTypeLoc
Definition: TypeLoc.h:2054
clang::SC_Static
@ SC_Static
Definition: Specifiers.h:227
clang::sema::CapturingScopeInfo::ImpCap_LambdaByval
@ ImpCap_LambdaByval
Definition: ScopeInfo.h:659
clang::TemplateDecl::getTemplateParameters
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
Definition: DeclTemplate.h:417
clang::BlockDecl::Create
static BlockDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L)
Definition: Decl.cpp:4842
clang::CC_C
@ CC_C
Definition: Specifiers.h:254
clang::FullExpr::getSubExpr
const Expr * getSubExpr() const
Definition: Expr.h:1007
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:2155
clang::Type::castAs
const T * castAs() const
Member-template castAs<specific type>.
Definition: Type.h:7218
clang::InitializedEntity::InitializeLambdaToBlock
static InitializedEntity InitializeLambdaToBlock(SourceLocation BlockVarLoc, QualType Type, bool NRVO)
Definition: Initialization.h:315
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:882
clang::VarDecl::ListInit
@ ListInit
Direct list-initialization (C++11)
Definition: Decl.h:855
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:7985
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:2161
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:676
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:2329
clang::sema::LambdaScopeInfo::Cleanup
CleanupInfo Cleanup
Whether any of the capture expressions requires cleanups.
Definition: ScopeInfo.h:845
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:244
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:2726
clang::VarDecl::getStorageClass
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Definition: Decl.h:1053
clang::DeclContext::addDecl
void addDecl(Decl *D)
Add the declaration D into this context.
Definition: DeclBase.cpp:1541
isInInlineFunction
static bool isInInlineFunction(const DeclContext *DC)
Determine whether the given context is or is enclosed in an inline function.
Definition: SemaLambda.cpp:263
clang::FunctionProtoType
Represents a prototype with parameter type info, e.g.
Definition: Type.h:3880
clang::ASTContext::Idents
IdentifierTable & Idents
Definition: ASTContext.h:611
clang::DeclContext::getParent
DeclContext * getParent()
getParent - Returns the containing DeclContext.
Definition: DeclBase.h:1860
clang::CXXConversionDecl::getConversionType
QualType getConversionType() const
Returns the type that this conversion function is converting to.
Definition: DeclCXX.h:2759
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::Capture::isVLATypeCapture
bool isVLATypeCapture() const
Definition: ScopeInfo.h:612
clang::QualType::isNull
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition: Type.h:726
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:1562
clang::BlockExpr
BlockExpr - Adaptor class for mixing a BlockDecl with expressions.
Definition: Expr.h:5889
clang::StmtExpr
StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
Definition: Expr.h:4269
llvm::ArrayRef
Definition: LLVM.h:34
clang::Decl
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:89
Scope.h
clang::LCK_StarThis
@ LCK_StarThis
Definition: Lambda.h:35
clang::Sema
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:352
addBlockPointerConversion
static void addBlockPointerConversion(Sema &S, SourceRange IntroducerRange, CXXRecordDecl *Class, CXXMethodDecl *CallOperator)
Add a lambda's conversion to block pointer.
Definition: SemaLambda.cpp:1529
clang::VarDecl::setInitStyle
void setInitStyle(InitializationStyle Style)
Definition: Decl.h:1330
clang::Qualifiers::addConst
void addConst()
Definition: Type.h:265
clang::hasWeakerNullability
bool hasWeakerNullability(NullabilityKind L, NullabilityKind R)
Return true if L has a weaker nullability annotation than R.
Definition: Specifiers.h:322
clang::DeclSpec::getConstexprSpecifier
ConstexprSpecKind getConstexprSpecifier() const
Definition: DeclSpec.h:754
clang::DeclContext::isFileContext
bool isFileContext() const
Definition: DeclBase.h:1930
clang::CC_X86VectorCall
@ CC_X86VectorCall
Definition: Specifiers.h:258
clang::sema::LambdaScopeInfo::IntroducerRange
SourceRange IntroducerRange
Source range covering the lambda introducer [...].
Definition: ScopeInfo.h:828
clang::sema::CapturingScopeInfo::isCaptured
bool isCaptured(VarDecl *Var) const
Determine whether the given variable has been captured.
Definition: ScopeInfo.h:713
clang::VarDecl::getInit
const Expr * getInit() const
Definition: Decl.h:1253
clang::IdentifierInfo
One of these records is kept for each identifier that is lexed.
Definition: IdentifierTable.h:59
clang::Sema::DiagnoseUnusedLambdaCapture
bool DiagnoseUnusedLambdaCapture(SourceRange CaptureRange, const sema::Capture &From)
Diagnose if an explicit lambda capture is unused.
Definition: SemaLambda.cpp:1674
clang::ASTContext::getTargetInfo
const TargetInfo & getTargetInfo() const
Definition: ASTContext.h:692
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:575
clang::Sema::addLambdaParameters
void addLambdaParameters(ArrayRef< LambdaIntroducer::LambdaCapture > Captures, CXXMethodDecl *CallOperator, Scope *CurScope)
Introduce the lambda parameters into scope.
Definition: SemaLambda.cpp:539
clang::CXXRecordDecl::CreateLambda
static CXXRecordDecl * CreateLambda(const ASTContext &C, DeclContext *DC, TypeSourceInfo *Info, SourceLocation Loc, bool DependentLambda, bool IsGeneric, LambdaCaptureDefault CaptureDefault)
Definition: DeclCXX.cpp:147
clang::ObjCPropertyAttribute::Kind
Kind
Definition: DeclObjCCommon.h:22
clang::InitializationKind
Describes the kind of initialization being performed, along with location information for tokens rela...
Definition: Initialization.h:560
clang::ActionResult< Expr * >
clang::LCK_ByCopy
@ LCK_ByCopy
< Capturing the *this object by copy
Definition: Lambda.h:36
clang::FunctionProtoType::ExceptionSpecInfo::Type
ExceptionSpecificationType Type
The kind of exception specification this is.
Definition: Type.h:3939
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:31
clang::LambdaCaptureInitKind::NoInit
@ NoInit
[a]
clang::FunctionProtoType::ExtProtoInfo::ExceptionSpec
ExceptionSpecInfo ExceptionSpec
Definition: Type.h:3969
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:628
clang::VarDecl::InitializationStyle
InitializationStyle
Initialization styles.
Definition: Decl.h:847
clang::sema::LambdaScopeInfo
Definition: ScopeInfo.h:818
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:7103
clang::sema::LambdaScopeInfo::ContainsUnexpandedParameterPack
bool ContainsUnexpandedParameterPack
Whether the lambda contains an unexpanded parameter pack.
Definition: ScopeInfo.h:848
clang::LambdaIntroducer::DefaultLoc
SourceLocation DefaultLoc
Definition: DeclSpec.h:2688
clang::sema::CapturingScopeInfo::ImpCap_LambdaByref
@ ImpCap_LambdaByref
Definition: ScopeInfo.h:659
clang::interp::This
bool This(InterpState &S, CodePtr OpPC)
Definition: Interp.h:827
clang::VarDecl::CInit
@ CInit
C-style initialization with assignment.
Definition: Decl.h:849
clang::FunctionProtoType::ExtProtoInfo
Extra information about a function prototype.
Definition: Type.h:3963
clang::CXXMethodDecl::isConst
bool isConst() const
Definition: DeclCXX.h:1979
clang::Expr::IgnoreParens
Expr * IgnoreParens() LLVM_READONLY
Skip past any parentheses which might surround this expression until reaching a fixed point.
Definition: Expr.cpp:2779
clang
Dataflow Directional Tag Classes.
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:1627
clang::FunctionProtoType::ExtProtoInfo::HasTrailingReturn
bool HasTrailingReturn
Definition: Type.h:3966
clang::Type::isIntegralOrUnscopedEnumerationType
bool isIntegralOrUnscopedEnumerationType() const
Determine whether this type is an integral or unscoped enumeration type.
Definition: Type.cpp:1928
clang::FunctionDecl::setDescribedFunctionTemplate
void setDescribedFunctionTemplate(FunctionTemplateDecl *Template)
Definition: Decl.cpp:3656
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:854
clang::sema::LambdaScopeInfo::ExplicitCaptureRanges
llvm::DenseMap< unsigned, SourceRange > ExplicitCaptureRanges
A map of explicit capture indices to their introducer source ranges.
Definition: ScopeInfo.h:888
clang::DeclaratorContext::Block
@ Block
clang::Stmt
Stmt - This represents one statement.
Definition: Stmt.h:68
clang::EST_BasicNoexcept
@ EST_BasicNoexcept
noexcept
Definition: ExceptionSpecificationType.h:26
clang::VK_RValue
@ VK_RValue
An r-value expression (a pr-value in the C++11 taxonomy) produces a temporary value.
Definition: Specifiers.h:110
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:481
clang::Declarator
Information about one declarator, including the parsed type information and the identifier.
Definition: DeclSpec.h:1803
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:430
clang::LambdaCaptureInitKind::CopyInit
@ CopyInit
[a = b], [a = {b}]
clang::ReturnStmt::getBeginLoc
SourceLocation getBeginLoc() const
Definition: Stmt.h:2786
clang::Sema::CaptureHasSideEffects
bool CaptureHasSideEffects(const sema::Capture &From)
Does copying/destroying the captured variable have side effects?
Definition: SemaLambda.cpp:1649
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:647
clang::Attr
Attr - This represents one attribute.
Definition: Attr.h:46
clang::Qualifiers::addAddressSpace
void addAddressSpace(LangAS space)
Definition: Type.h:387
clang::TypeSourceInfo
A container of type source information.
Definition: Type.h:6391
clang::FunctionType::getReturnType
QualType getReturnType() const
Definition: Type.h:3804
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:287
clang::FixItHint::CreateRemoval
static FixItHint CreateRemoval(CharSourceRange RemoveRange)
Create a code modification hint that removes the given source range.
Definition: Diagnostic.h:122
clang::sema::CapturingScopeInfo::HasImplicitReturnType
bool HasImplicitReturnType
Definition: ScopeInfo.h:680
clang::DeclContext::isDependentContext
bool isDependentContext() const
Determines whether this context is dependent on a template parameter.
Definition: DeclBase.cpp:1138
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:1513
clang::SC_Auto
@ SC_Auto
Definition: Specifiers.h:231
clang::FunctionProtoType::ExtProtoInfo::TypeQuals
Qualifiers TypeQuals
Definition: Type.h:3967
clang::LCK_This
@ LCK_This
Capturing the *this object by reference.
Definition: Lambda.h:34
clang::sema::CapturingScopeInfo
Definition: ScopeInfo.h:653
clang::InitializedEntity
Describes an entity that is being initialized.
Definition: Initialization.h:48
clang::FunctionDecl::isVariadic
bool isVariadic() const
Whether this function is variadic.
Definition: Decl.cpp:2868
clang::ParenListExpr::getExprs
Expr ** getExprs()
Definition: Expr.h:5493
clang::LookupResult::getAsSingle
DeclClass * getAsSingle() const
Definition: Lookup.h:507
clang::FunctionTypeLoc::getReturnLoc
TypeLoc getReturnLoc() const
Definition: TypeLoc.h:1435
mapImplicitCaptureStyle
static LambdaCaptureDefault mapImplicitCaptureStyle(CapturingScopeInfo::ImplicitCaptureStyle ICS)
Definition: SemaLambda.cpp:1634
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:3542
clang::sema::Capture::isBlockCapture
bool isBlockCapture() const
Definition: ScopeInfo.h:611
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:2880
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:3179
clang::DeclSpec::TQ_const
@ TQ_const
Definition: DeclSpec.h:305
clang::sema::CapturingScopeInfo::getCXXThisCapture
Capture & getCXXThisCapture()
Retrieve the capture of C++ 'this', if it has been captured.
Definition: ScopeInfo.h:707
clang::FunctionProtoTypeLoc
Definition: TypeLoc.h:1466
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:2391
clang::InventedTemplateParameterInfo::NumExplicitTemplateParams
unsigned NumExplicitTemplateParams
The number of parameters in the template parameter list that were explicitly specified by the user,...
Definition: DeclSpec.h:2713
clang::ValueDecl::getType
QualType getType() const
Definition: Decl.h:655
clang::SC_None
@ SC_None
Definition: Specifiers.h:225
clang::DeducedType
Common base class for placeholders for types that get replaced by placeholder type deduction: C++11 a...
Definition: Type.h:4941
clang::VarDecl::Create
static VarDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, StorageClass S)
Definition: Decl.cpp:1994
clang::ParsedAttributesView
Definition: ParsedAttr.h:848
clang::Expr
This represents one expression.
Definition: Expr.h:109
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:276
clang::FunctionDecl::getDescribedFunctionTemplate
FunctionTemplateDecl * getDescribedFunctionTemplate() const
Retrieves the function template that is described by this function declaration.
Definition: Decl.cpp:3652
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:2702
clang::Sema::buildLambdaInitCaptureInitialization
QualType buildLambdaInitCaptureInitialization(SourceLocation Loc, bool ByRef, SourceLocation EllipsisLoc, Optional< unsigned > NumExpansions, IdentifierInfo *Id, bool DirectInit, Expr *&Init)
Definition: SemaLambda.cpp:788
clang::VarDecl::hasLocalStorage
bool hasLocalStorage() const
Returns true if a variable with function scope is a non-static local variable.
Definition: Decl.h:1069
clang::sema::Capture::isVariableCapture
bool isVariableCapture() const
Definition: ScopeInfo.h:605
clang::CleanupInfo
Definition: CleanupInfo.h:19
clang::BlockDecl::Capture
A class which contains all the information about a particular captured value.
Definition: Decl.h:4116
clang::EnumType
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of enums.
Definition: Type.h:4634
clang::DeclContext::isFunctionOrMethod
bool isFunctionOrMethod() const
Definition: DeclBase.h:1912
clang::FunctionProtoType::getExtProtoInfo
ExtProtoInfo getExtProtoInfo() const
Definition: Type.h:4101
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:1626
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:1350
clang::Sema::TryCaptureKind
TryCaptureKind
Definition: Sema.h:4975
clang::DeclarationNameInfo
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspnd...
Definition: DeclarationName.h:758
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:2207
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:1012
clang::InitializationKind::CreateCopy
static InitializationKind CreateCopy(SourceLocation InitLoc, SourceLocation EqualLoc, bool AllowExplicitConvs=false)
Create a copy initialization.
Definition: Initialization.h:667
clang::FunctionDecl::parameters
ArrayRef< ParmVarDecl * > parameters() const
Definition: Decl.h:2448
clang::Sema::BuildBlockForLambdaConversion
ExprResult BuildBlockForLambdaConversion(SourceLocation CurrentLocation, SourceLocation ConvLocation, CXXConversionDecl *Conv, Expr *Src)
Definition: SemaLambda.cpp:1960
clang::Decl::getLocation
SourceLocation getLocation() const
Definition: DeclBase.h:430
clang::sema::CapturingScopeInfo::ReturnType
QualType ReturnType
ReturnType - The target type of return statements in this context, or null if unknown.
Definition: ScopeInfo.h:684
clang::Decl::addAttr
void addAttr(Attr *A)
Definition: DeclBase.cpp:881
clang::Decl::setReferenced
void setReferenced(bool R=true)
Definition: DeclBase.h:593
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:645
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:1161
clang::DeclRefExpr
A reference to a declared variable, function, enum, etc.
Definition: Expr.h:1213
clang::FunctionDecl
Represents a function declaration or definition.
Definition: Decl.h:1821
clang::RecordDecl
Represents a struct/union/class.
Definition: Decl.h:3816
clang::DeclContext::Equals
bool Equals(const DeclContext *DC) const
Determine whether this declaration context is equivalent to the declaration context DC.
Definition: DeclBase.h:1984
clang::ASTContext::NeedExtraManglingDecl
@ NeedExtraManglingDecl
Definition: ASTContext.h:2908
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:668
clang::DeclaratorDecl::getTypeSourceInfo
TypeSourceInfo * getTypeSourceInfo() const
Definition: Decl.h:725
clang::ICIS_NoInit
@ ICIS_NoInit
No in-class initializer.
Definition: Specifiers.h:247
ContextKind
tok::TokenKind ContextKind
Definition: TokenAnnotator.cpp:1400
clang::ReturnStmt
ReturnStmt - This represents a return, optionally of an expression: return; return 4;.
Definition: Stmt.h:2727
clang::VarDecl::CallInit
@ CallInit
Call-style initialization (C++98)
Definition: Decl.h:852
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:2053
clang::CXXMethodDecl
Represents a static or instance method of a struct/union/class.
Definition: DeclCXX.h:1937
clang::LambdaIntroducer::Range
SourceRange Range
Definition: DeclSpec.h:2687
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:7069
clang::LookupResult::isAmbiguous
bool isAmbiguous() const
Definition: Lookup.h:301
clang::ConstexprSpecKind::Unspecified
@ Unspecified
clang::Decl::getDeclContext
DeclContext * getDeclContext()
Definition: DeclBase.h:439
clang::sema::LambdaScopeInfo::CaptureDefaultLoc
SourceLocation CaptureDefaultLoc
Source location of the '&' or '=' specifying the default capture type, if any.
Definition: ScopeInfo.h:832
clang::sema::CapturingScopeInfo::isCXXThisCaptured
bool isCXXThisCaptured() const
Determine whether the C++ 'this' is captured.
Definition: ScopeInfo.h:704