clang: lib/Sema/SemaLambda.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

30#include "llvm/ADT/STLExtras.h"

31#include

32using namespace clang;

33using namespace sema;

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

73

74 const UnsignedOrNone NoLambdaIsCaptureReady = std::nullopt;

75

76

77 unsigned CurScopeIndex = FunctionScopes.size() - 1;

79 FunctionScopes[CurScopeIndex]))

80 --CurScopeIndex;

81 assert(

83 "The function on the top of sema's function-info stack must be a lambda");

84

85

86 const bool IsCapturingThis = !VarToCapture;

87 const bool IsCapturingVariable = !IsCapturingThis;

88

89

92

93 do {

96

97

98

99

100

101

102

103 if (IsCapturingVariable &&

105 return NoLambdaIsCaptureReady;

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

124 if (IsCapturingVariable && !LSI->isCaptured(VarToCapture))

125 return NoLambdaIsCaptureReady;

127 return NoLambdaIsCaptureReady;

128 }

130

131 assert(CurScopeIndex);

132 --CurScopeIndex;

136

137 assert(CurScopeIndex < (FunctionScopes.size() - 1));

138

139

141 return CurScopeIndex + 1;

142 return NoLambdaIsCaptureReady;

143}

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

183

184 const UnsignedOrNone NoLambdaIsCaptureCapable = std::nullopt;

185

188 VarToCapture);

189 if (!OptionalStackIndex)

190 return NoLambdaIsCaptureCapable;

191

192 const unsigned IndexOfCaptureReadyLambda = *OptionalStackIndex;

193 assert(((IndexOfCaptureReadyLambda != (FunctionScopes.size() - 1)) ||

195 "The capture ready lambda for a potential capture can only be the "

196 "current lambda if it is a generic lambda");

197

200

201

202 const bool IsCapturingThis = !VarToCapture;

203 const bool IsCapturingVariable = !IsCapturingThis;

204

205 if (IsCapturingVariable) {

206

207

208

209 QualType CaptureType, DeclRefType;

211 VarToCapture,

214 false, CaptureType, DeclRefType,

215 &IndexOfCaptureReadyLambda);

216 if (!CanCaptureVariable)

217 return NoLambdaIsCaptureCapable;

218 } else {

219

220

221

222 const bool CanCaptureThis =

225 false, false,

226 &IndexOfCaptureReadyLambda);

227 if (!CanCaptureThis)

228 return NoLambdaIsCaptureCapable;

229 }

230 return IndexOfCaptureReadyLambda;

231}

232

246

249 unsigned LambdaDependencyKind,

252

253 bool IsGenericLambda =

255

257 Context, DC, Info, IntroducerRange.getBegin(), LambdaDependencyKind,

258 IsGenericLambda, CaptureDefault);

260

262}

263

264

265

268 if (const FunctionDecl *FD = dyn_cast(DC))

269 if (FD->isInlined())

270 return true;

271

273 }

274

275 return false;

276}

277

278std::tuple<MangleNumberingContext *, Decl *>

280

281

283

284 enum ContextKind {

287 DataMember,

288 InlineVariable,

289 TemplatedVariable,

291 NonInlineInModulePurview

293

294 bool IsInNonspecializedTemplate =

296

297

298

299

300 Kind = [&]() {

301 if (!ManglingContextDecl)

303

304 if (auto *ND = dyn_cast(ManglingContextDecl)) {

305

306

307

308

309

310

313 ND->isExternallyVisible())

314 return NonInlineInModulePurview;

315 }

316

317 if (ParmVarDecl *Param = dyn_cast(ManglingContextDecl)) {

320 if (LexicalDC->isRecord())

322 } else if (VarDecl *Var = dyn_cast(ManglingContextDecl)) {

323 if (Var->getMostRecentDecl()->isInline())

324 return InlineVariable;

325

326 if (Var->getDeclContext()->isRecord() && IsInNonspecializedTemplate)

327 return TemplatedVariable;

328

329 if (Var->getDescribedVarTemplate())

330 return TemplatedVariable;

331

332 if (auto *VTS = dyn_cast(Var)) {

333 if (!VTS->isExplicitSpecialization())

334 return TemplatedVariable;

335 }

337 return DataMember;

340 }

341

343 }();

344

345

346

347

348 switch (Kind) {

350

351 if ((IsInNonspecializedTemplate &&

352 !(ManglingContextDecl && isa(ManglingContextDecl))) ||

354 while (auto *CD = dyn_cast(DC))

356 return std::make_tuple(&Context.getManglingNumberContext(DC), nullptr);

357 }

358

359 return std::make_tuple(nullptr, nullptr);

360 }

361

362 case NonInlineInModulePurview:

364

365

366

367

368 case DataMember:

369

371

372 case InlineVariable:

373 case TemplatedVariable:

374

375 return std::make_tuple(

377 ManglingContextDecl),

378 ManglingContextDecl);

379 }

380

381 llvm_unreachable("unexpected context");

382}

383

388 assert(MethodTypeInfo && "expected a non null type");

389

391

392

393

394 if (Class->isDependentContext() || TemplateParams) {

397 if (Result->isUndeducedType()) {

401 }

402 }

403 return MethodType;

404}

405

406

407

408

409

410

411

412

416 return false;

418 if (Method->getType()->isDependentType())

419 return false;

421 return false;

422

424 QualType ExplicitObjectParameterType = Param->getType()

425 .getNonReferenceType()

426 .getUnqualifiedType()

429 if (LambdaType == ExplicitObjectParameterType)

430 return false;

431

432

433

434

435

436

437

438

439

440

441

442

443

444

445

446 auto [It, Inserted] = Context.LambdaCastPaths.try_emplace(Method);

447 if (!Inserted)

448 return It->second.empty();

449

451 CXXBasePaths Paths(true, true,

452 false);

454 Paths)) {

455 Diag(Param->getLocation(), diag::err_invalid_explicit_object_type_in_lambda)

456 << ExplicitObjectParameterType;

457 return true;

458 }

459

462 Diag(CallLoc, diag::err_explicit_object_lambda_ambiguous_base)

463 << LambdaType << PathsDisplay;

464 return true;

465 }

466

469 diag::err_explicit_object_lambda_inaccessible_base))

470 return true;

471

473 return false;

474}

475

478 std::optionalCXXRecordDecl::LambdaNumbering NumberingOverride) {

479 if (NumberingOverride) {

480 Class->setLambdaNumbering(*NumberingOverride);

481 return;

482 }

483

485

486 auto getMangleNumberingContext =

489

490 if (ManglingContextDecl)

491 return &Context.getManglingNumberContext(

493

494 auto DC = Class->getDeclContext();

495 while (auto *CD = dyn_cast(DC))

496 DC = CD->getParent();

497 return &Context.getManglingNumberContext(DC);

498 };

499

506

507

508

509

510

511

512

513 MCtx = getMangleNumberingContext(Class, Numbering.ContextDecl);

514 assert(MCtx && "Retrieving mangle numbering context failed!");

516 }

517 if (MCtx) {

521 Class->setLambdaNumbering(Numbering);

522

523 if (auto *Source =

524 dyn_cast_or_null(Context.getExternalSource()))

525 Source->AssignedLambdaNumbering(Class);

526 }

527}

528

531 bool ExplicitResultType) {

532 if (ExplicitResultType) {

537 diag::err_lambda_incomplete_result);

538 } else {

540 }

541}

542

547 bool ExplicitParams, bool Mutable) {

550 LSI->Lambda = LambdaClass;

552 LSI->ImpCaptureStyle = LambdaScopeInfo::ImpCap_LambdaByval;

553 else if (CaptureDefault == LCD_ByRef)

554 LSI->ImpCaptureStyle = LambdaScopeInfo::ImpCap_LambdaByref;

559}

560

564

570 assert(LSI && "Expected a lambda scope");

572 "Already acted on explicit template parameters");

574 "Explicit template parameters should come "

575 "before invented (auto) ones");

576 assert(!TParams.empty() &&

577 "No template parameters to act on");

578 LSI->TemplateParams.append(TParams.begin(), TParams.end());

582}

583

584

585

586

587

588

589

590

592

593

595

596

597 if (DeclRefExpr *DRE = dyn_cast(E)) {

599 = dyn_cast(DRE->getDecl())) {

601 }

602 return nullptr;

603 }

604

605

606

607 if (BinaryOperator *BO = dyn_cast(E)) {

608 if (BO->getOpcode() == BO_Comma)

610 return nullptr;

611 }

612

613

614

615 if (StmtExpr *SE = dyn_cast(E)) {

616 if (Expr *last = dyn_cast_or_null(SE->getSubStmt()->body_back()))

618 return nullptr;

619 }

620

621

622

623

627 return ED;

628 return nullptr;

629 }

630

631

632

633

635

636

637 if (ICE->getCastKind() == CK_IntegralCast)

639

640

641 }

642

643

645 return ED;

646

647

648 return nullptr;

649}

650

651

652

658

659

660

661

664

665

667 if (!ED) return nullptr;

668

669

670 for (++i; i != e; ++i) {

672 return nullptr;

673 }

674

675

677

678 return ED;

679}

680

681

682

686 i = returns.begin(), e = returns.end(); i != e; ++i) {

690 continue;

691

692

695

696 ExprWithCleanups *cleanups = dyn_cast(retValue);

697

698 Expr *E = (cleanups ? cleanups->getSubExpr() : retValue);

702 if (cleanups) {

704 } else {

706 }

707 }

708}

709

712

715 "lambda expressions use auto deduction in C++14 onwards");

716

717

718

719

720

721

722

723

724

725

726

727

728

729

730

731

732

733

734

735

736

737

738

739

740

742 if (CSI.Returns.empty()) {

743

744

747 return;

748 }

749

750

751

752 assert(!CSI.ReturnType.isNull() && "We should have a tentative return type.");

754 return;

755

756

760 if (ED) {

763 return;

764 }

765 }

766

767

768 if (CSI.Returns.size() == 1)

769 return;

770

771

772

773

774

775

776

779

782 if (Context.getCanonicalFunctionResultType(ReturnType) ==

784

785 auto RetTyNullability = ReturnType->getNullability();

787 if (BlockNullability &&

788 (!RetTyNullability ||

791 continue;

792 }

793

794

795

797 diag::err_typecheck_missing_return_type_incompatible)

799

800 }

801}

802

807

808

813 if (ByRef) {

815 assert(!DeductType.isNull() && "can't build reference to auto");

817 }

818 if (EllipsisLoc.isValid()) {

819 if (Init->containsUnexpandedParameterPack()) {

821 ? diag::warn_cxx17_compat_init_capture_pack

822 : diag::ext_init_capture_pack);

823 DeductType = Context.getPackExpansionType(DeductType, NumExpansions,

824 false);

826 } else {

827

828

829 }

830 }

832

833

835 nullptr, DeclarationName(Id), DeductType, TSI,

837 if (DeducedType.isNull())

839

840

842

843

844

848 IsDirectInit

850 Loc, Init->getBeginLoc(), Init->getEndLoc())

853

855 if (CXXDirectInit)

856 Args =

861

862 if (Result.isInvalid())

864

866 return DeducedType;

867}

868

872

873

876 PETL.setEllipsisLoc(EllipsisLoc);

877

878

879

880

881

883 InitCaptureType, TSI, SC_Auto);

886

892 return NewVD;

893}

894

901

902

903

908

911

912

913

915 false, true));

921

922

923

924

925

926

927

934}

935

939 bool &ExplicitResultType) {

940

941 ExplicitResultType = false;

942

943 assert(

947 "Unexpected storage specifier");

948 bool IsLambdaStatic =

950

952

955 } else {

956

958

960

961 bool HasExplicitObjectParameter =

963

966 !HasExplicitObjectParameter)

968

969 if (ExplicitResultType && S.getLangOpts().HLSL) {

971 if (!RetTy.isNull()) {

972

973

977 diag::err_return_value_with_address_space);

978 }

979 }

980

982 assert(MethodTyInfo && "no type from lambda-declarator");

983

984

988 }

989 return MethodTyInfo;

990}

991

994

995

996

997

998

999

1000

1002 Context.DeclarationNames.getCXXOperatorName(OO_Call);

1008 MethodNameLoc),

1012 {});

1015}

1016

1020 assert(TemplateParams && "no template parameters");

1023 TemplateParams, CallOperator);

1026}

1027

1034 bool HasExplicitResultType) {

1035

1037

1038 if (TrailingRequiresClause)

1039 Method->setTrailingRequiresClause(TrailingRequiresClause);

1040

1043

1045

1046

1048 if (TemplateParams) {

1050 Method->getDescribedFunctionTemplate();

1051 assert(TemplateMethod &&

1052 "AddTemplateParametersToLambdaCallOperator should have been called");

1053

1056 } else {

1058 }

1061

1062 Method->setLexicalDeclContext(DC);

1063 Method->setLocation(LambdaLoc);

1064 Method->setInnerLocStart(CallOperatorLoc);

1065 Method->setTypeSourceInfo(MethodTyInfo);

1067 TemplateParams, MethodTyInfo));

1068 Method->setConstexprKind(ConstexprKind);

1069 Method->setStorageClass(SC);

1070 if (!Params.empty()) {

1072 Method->setParams(Params);

1073 for (auto P : Method->parameters()) {

1074 assert(P && "null in a parameter list");

1075 P->setOwningFunction(Method);

1076 }

1077 }

1078

1080}

1081

1083 Scope *CurrentScope) {

1084

1086 assert(LSI && "LambdaScopeInfo should be on stack!");

1087

1089 LSI->ImpCaptureStyle = LambdaScopeInfo::ImpCap_LambdaByval;

1091 LSI->ImpCaptureStyle = LambdaScopeInfo::ImpCap_LambdaByref;

1095

1097

1098

1099

1102 if (CurScope->getTemplateParamParent() != nullptr) {

1105

1106

1107

1108

1109

1110

1111

1112

1113

1114

1115 while (P->getEntity() && P->getEntity()->isRequiresExprBody())

1116 P = P->getParent();

1117 if (P->isFunctionDeclarationScope() &&

1118 llvm::any_of(P->decls(), [](Decl *D) {

1119 return isa(D) &&

1120 cast(D)->getType()->isTemplateTypeParmType();

1121 }))

1123 }

1124

1126 Intro.Range, nullptr, LambdaDependencyKind, Intro.Default);

1128

1131

1132

1134

1136

1137 bool ContainsUnexpandedParameterPack = false;

1138

1139

1140 llvm::DenseMap<IdentifierInfo *, ValueDecl *> CaptureNames;

1141

1142

1145 for (auto C = Intro.Captures.begin(), E = Intro.Captures.end(); C != E;

1146 PrevCaptureLoc = C->Loc, ++C) {

1150 ? diag::ext_star_this_lambda_capture_cxx17

1151 : diag::warn_cxx14_compat_star_this_lambda_capture);

1152

1153

1154

1155

1157 Diag(C->Loc, diag::err_capture_more_than_once)

1161 continue;

1162 }

1163

1164

1165

1166

1167

1168

1171 ? diag::ext_equals_this_lambda_capture_cxx20

1172 : diag::warn_cxx17_compat_equals_this_lambda_capture);

1173

1174

1175

1176

1178 if (ThisCaptureType.isNull()) {

1179 Diag(C->Loc, diag::err_this_capture) << true;

1180 continue;

1181 }

1182

1184 nullptr,

1188 continue;

1189 }

1190

1191 assert(C->Id && "missing identifier for capture");

1192

1193 if (C->Init.isInvalid())

1194 continue;

1195

1197 if (C->Init.isUsable()) {

1199 ? diag::warn_cxx11_compat_init_capture

1200 : diag::ext_init_capture);

1201

1202

1203

1204

1205

1206

1207 if (C->InitCaptureType.get().isNull())

1208 continue;

1209

1210 if (C->Init.get()->containsUnexpandedParameterPack() &&

1211 C->InitCaptureType.get()->getAs())

1213

1214 unsigned InitStyle;

1215 switch (C->InitKind) {

1217 llvm_unreachable("not an init-capture?");

1220 break;

1223 break;

1226 break;

1227 }

1229 C->EllipsisLoc, C->Id, InitStyle,

1231 assert(Var && "createLambdaInitCaptureVarDecl returned a null VarDecl?");

1232 if (auto *V = dyn_cast(Var))

1235 } else {

1237 "init capture has valid but null init?");

1238

1239

1240

1241

1242

1243

1245 Diag(C->Loc, diag::err_reference_capture_with_reference_default)

1248 continue;

1250 Diag(C->Loc, diag::err_copy_capture_with_copy_default)

1253 continue;

1254 }

1255

1256

1257

1258

1263 continue;

1264 if (R.empty()) {

1265

1269 continue;

1270 }

1271

1273 Var = BD;

1275 Diag(C->Loc, diag::err_capture_class_member_does_not_name_variable)

1276 << C->Id;

1277 continue;

1278 } else

1281 continue;

1282 }

1283

1284

1285

1286

1287

1288 if (!Var) {

1289 Diag(C->Loc, diag::err_capture_does_not_name_variable) << C->Id;

1290 continue;

1291 }

1292

1293

1294

1295

1296 if (auto [It, Inserted] = CaptureNames.insert(std::pair{C->Id, Var});

1297 !Inserted) {

1300 Diag(C->Loc, diag::err_capture_more_than_once)

1301 << C->Id << It->second->getBeginLoc()

1307 } else {

1308

1309

1310 Diag(C->Loc, diag::err_capture_more_than_once) << C->Id;

1311 continue;

1312 }

1313 }

1314

1315

1317 continue;

1318

1320

1322 Diag(C->Loc, diag::err_capture_non_automatic_variable) << C->Id;

1323 Diag(Var->getLocation(), diag::note_previous_decl) << C->Id;

1324 continue;

1325 }

1326

1327

1328

1330 if (C->EllipsisLoc.isValid()) {

1332 EllipsisLoc = C->EllipsisLoc;

1333 } else {

1334 Diag(C->EllipsisLoc, diag::err_pack_expansion_without_parameter_packs)

1335 << (C->Init.isUsable() ? C->Init.get()->getSourceRange()

1337

1338

1339 }

1341 ContainsUnexpandedParameterPack = true;

1342 }

1343

1344 if (C->Init.isUsable()) {

1346 } else {

1351 }

1354 }

1358}

1359

1362

1366

1367

1368

1369

1370

1371

1372

1373

1374

1375

1376

1377

1382 false)))

1383 Diag(Intro.DefaultLoc, diag::err_capture_default_non_local);

1384}

1385

1390

1393 Param->setOwningFunction(LSI->CallOperator);

1394 if (Param->getIdentifier())

1396 }

1397

1398

1399

1400

1401

1404 if (TemplateParams) {

1406 TemplateParams);

1410 }

1412}

1413

1417

1420

1422 bool ExplicitResultType;

1423

1427 } else {

1428 unsigned Index;

1430 const auto &Object = ParamInfo.getTypeObject(Index);

1434 }

1435

1438

1440 *this, Intro, ParamInfo, getCurScope(), TypeLoc, ExplicitResultType);

1441

1446 Params.reserve(Params.size());

1447 for (unsigned I = 0; I < FTI.NumParams; ++I) {

1449 Param->setScopeInfo(0, Params.size());

1450 Params.push_back(Param);

1451 }

1452 }

1453 }

1454

1455 bool IsLambdaStatic =

1457

1462 IsLambdaStatic ? SC_Static : SC_None, Params, ExplicitResultType);

1463

1465

1466

1467

1469

1470

1472 Method, true))

1474

1475

1477

1478 if (Context.getTargetInfo().getTriple().isAArch64())

1480

1481

1484

1485

1488

1490

1491 for (auto &&C : LSI->Captures) {

1492 if (C.isVariableCapture())

1493 continue;

1497 }

1498 }

1499

1500 auto CheckRedefinition = [&](ParmVarDecl *Param) {

1502 if (Capture.Id == Param->getIdentifier()) {

1503 Diag(Param->getLocation(), diag::err_parameter_shadow_capture);

1504 Diag(Capture.Loc, diag::note_var_explicitly_captured_here)

1506 return false;

1507 }

1508 }

1509 return true;

1510 };

1511

1513 if (!P->getIdentifier())

1514 continue;

1515 if (CheckRedefinition(P))

1518 }

1519

1520

1521

1522

1523

1524

1527 if (TemplateParams) {

1528 for (const auto *TP : TemplateParams->asArray()) {

1529 if (!TP->getIdentifier())

1530 continue;

1532 if (Capture.Id == TP->getIdentifier()) {

1535 }

1536 }

1537 }

1538 }

1539

1540

1541

1542

1543

1545

1546

1547

1548

1549

1550

1551

1552

1553

1554

1555

1556

1557

1558

1559

1560

1561

1562

1563

1564

1565

1566 if (Method->getDescribedFunctionTemplate() && Method->isTemplated()) {

1567 Diag(TRC.ConstraintExpr->getBeginLoc(),

1568 diag::err_constrained_non_templated_function);

1569 }

1570 }

1571

1572

1573

1576}

1577

1579 bool IsInstantiation) {

1581

1582

1585

1586

1587 if (!IsInstantiation)

1589

1590

1592 Class->setInvalidDecl();

1597

1599}

1600

1601template

1605 CallOpProto.isVariadic(), false);

1607 CallOpProto.isVariadic(), true);

1609

1610

1611

1612

1613

1614

1615

1616

1617

1618

1619

1620

1621

1625 DefaultFree, DefaultMember, CallOpCC};

1626 llvm::sort(Convs);

1627 llvm::iterator_range<CallingConv *> Range(std::begin(Convs),

1628 llvm::unique(Convs));

1630

1633 F(C);

1634 }

1635 return;

1636 }

1637

1638 if (CallOpCC == DefaultMember && DefaultMember != DefaultFree) {

1639 F(DefaultFree);

1640 F(DefaultMember);

1641 } else {

1642 F(CallOpCC);

1643 }

1644}

1645

1646

1647

1648

1653 CallOpProto->isVariadic(), false);

1655 CallOpProto->isVariadic(), true);

1657

1658

1659

1660 if (CallOpCC == DefaultMember && DefaultMember != DefaultFree)

1661 return DefaultFree;

1662 return CallOpCC;

1663}

1664

1673 "Lambda's call operator should not have a reference qualifier");

1676}

1677

1678

1679

1683 QualType InvokerFunctionTy) {

1684

1685

1686 auto HasPassObjectSizeAttr = [](const ParmVarDecl *P) {

1687 return P->hasAttr();

1688 };

1689 if (llvm::any_of(CallOperator->parameters(), HasPassObjectSizeAttr))

1690 return;

1691

1692

1694

1695

1698 false, true));

1699

1704

1709

1710

1711

1712

1713

1714

1715

1716

1717

1718

1719

1720

1721

1722

1723

1724

1729

1730

1734

1737

1738

1741

1742

1743

1748

1749

1750

1751

1752

1753

1754

1755

1756

1758 for (unsigned I = 0, N = CallOperator->getNumParams(); I != N; ++I) {

1760

1763

1767 nullptr));

1768 CallOpConvTL.setParam(I, From);

1769 CallOpConvNameTL.setParam(I, From);

1770 }

1771

1782

1783

1784

1788

1789 if (Class->isGenericLambda()) {

1790

1791

1796 Loc, ConversionName,

1798 Conversion);

1802 Class->addDecl(ConversionTemplate);

1803 } else

1804 Class->addDecl(Conversion);

1805

1806

1807

1808

1809

1813

1814

1815

1816

1817

1818

1819

1820

1821

1822

1823

1830 for (unsigned I = 0, N = CallOperator->getNumParams(); I != N; ++I)

1831 InvokerParams[I]->setOwningFunction(Invoke);

1832 Invoke->setParams(InvokerParams);

1835 if (Class->isGenericLambda()) {

1840 S.Context, Class, Loc, InvokerName,

1843 StaticInvokerTemplate->setImplicit(true);

1845 Class->addDecl(StaticInvokerTemplate);

1846 } else

1847 Class->addDecl(Invoke);

1848 }

1849}

1850

1851

1852

1853

1854

1860

1863 QualType InvokerFunctionTy =

1866 InvokerFunctionTy);

1867 });

1868}

1869

1870

1880

1883 false, true));

1887

1902 Class->addDecl(Conversion);

1903}

1904

1907 bool IsOpenMPMapping) {

1908

1911

1912

1915

1916

1917

1918

1920 ImplicitCaptureLoc.isValid() ? ImplicitCaptureLoc : Cap.getLocation();

1921

1922

1923

1924

1925

1926

1927

1928

1929

1930

1931

1932

1933

1941 else

1943 } else {

1949 }

1950

1951

1952

1953

1954 if (IsOpenMPMapping)

1955 return Init;

1956

1957 if (Init.isInvalid())

1959

1960 Expr *InitExpr = Init.get();

1966 return InitSeq.Perform(*this, Entity, InitKind, InitExpr);

1967}

1968

1971

1974

1976 true);

1977

1979}

1980

1983 switch (ICS) {

1992 llvm_unreachable("block capture in lambda");

1993 }

1994 llvm_unreachable("Unknown implicit capture style");

1995}

1996

2001 return true;

2002 }

2003

2005 return false;

2006

2010

2011 if (T.isVolatileQualified())

2012 return true;

2013

2014 const Type *BaseT = T->getBaseElementTypeUnsafe();

2016 return !RD->isCompleteDefinition() || !RD->hasTrivialCopyConstructor() ||

2017 !RD->hasTrivialDestructor();

2018

2019 return false;

2020}

2021

2026 return false;

2027

2029 return false;

2030

2031

2032

2035 return false;

2036

2039 diag << "'this'";

2040 else

2043

2044

2045 if (FixItRange.isValid())

2047 else

2048 diag << CaptureRange;

2049 return true;

2050}

2051

2052

2053

2058

2062 if (Var && Var->isInitCapture())

2063 TSI = Var->getTypeSourceInfo();

2064 }

2065

2066

2067

2068 if (!TSI)

2069 TSI = Context.getTrivialTypeSourceInfo(FieldType, Loc);

2070

2071

2074 nullptr, FieldType, TSI, nullptr,

2076

2077

2080 diag::err_field_incomplete_or_sizeless)) {

2082 Field->setInvalidDecl();

2083 } else {

2088 Field->setInvalidDecl();

2089 }

2090 }

2091 }

2092 Field->setImplicit(true);

2095

2098

2099 return Field;

2100}

2101

2105 bool CurHasPreviousCapture, bool IsLast) {

2106 if (!CaptureRange.isValid())

2108

2109 auto GetTrailingEndLocation = [&](SourceLocation StartPoint) {

2111 StartPoint, false, true);

2112 if (!NextToken.isValid())

2114

2116 };

2117

2118 if (!CurHasPreviousCapture && !IsLast) {

2119

2120

2123 false, tok::comma);

2126 }

2127

2128

2129

2132 return SourceRange(FixItStart, FixItEnd);

2133}

2134

2138

2151 bool IsGenericLambda = Class->isGenericLambda();

2152

2154 Decl *TemplateOrNonTemplateCallOperatorDecl =

2158

2159

2160

2162

2164

2167

2168

2170

2171

2172 bool CurHasPreviousCapture = CaptureDefault != LCD_None;

2174 CurHasPreviousCapture ? CaptureDefaultLoc : IntroducerRange.getBegin();

2175

2176 for (unsigned I = 0, N = LSI->Captures.size(); I != N; ++I) {

2178

2181

2182 assert(!From.isBlockCapture() && "Cannot capture __block variables");

2186

2187

2189

2190

2191 bool IsCaptureUsed = true;

2192 if (CurContext->isDependentContext() && !IsImplicit && !From.isODRUsed()) {

2193

2194

2195 bool NonODRUsedInitCapture =

2197 if (!NonODRUsedInitCapture) {

2200 *this, CaptureRange, PrevCaptureLoc, CurHasPreviousCapture, IsLast);

2201 IsCaptureUsed =

2203 }

2204 }

2205

2206 if (CaptureRange.isValid()) {

2207 CurHasPreviousCapture |= IsCaptureUsed;

2208 PrevCaptureLoc = CaptureRange.getEnd();

2209 }

2210

2211

2214

2215

2216

2219 Diag(From.getLocation(), diag::warn_deprecated_this_capture);

2220 Diag(CaptureDefaultLoc, diag::note_deprecated_this_capture)

2223 }

2228 } else {

2234 }

2235 }();

2236

2237

2239

2240

2241

2242

2243

2244

2246 Captures.push_back(Capture);

2247 CaptureInits.push_back(Init.get());

2248

2251 }

2252

2254

2255

2256

2257

2258

2259

2260 if (Captures.empty() && CaptureDefault == LCD_None)

2262

2263

2264

2265

2266

2267

2268

2271

2272

2277

2278 Cleanup.mergeFrom(LambdaCleanup);

2279

2282 CaptureDefaultLoc, ExplicitParams, ExplicitResultType,

2283 CaptureInits, EndLoc, ContainsUnexpandedParameterPack);

2284

2285

2286

2287

2291 Class->isDependentContext()) {

2297 }

2298

2299

2301

2302 if (CurContext->isDependentContext()) {

2304

2305

2306

2310

2311

2312

2313

2314

2315

2316

2317

2318

2321

2322

2323

2325 break;

2326

2330 break;

2331 }

2333 }

2334

2336}

2337

2341 Expr *Src) {

2342

2347 Context.DeclarationNames.getCXXOperatorName(OO_Call)).front());

2350

2353 CurrentLocation, Src);

2354 if (Init.isInvalid())

2356

2357 if (Init.isInvalid())

2359

2360

2362

2363

2366 Block->setBlockMissingReturnType(false);

2367

2368

2370 for (unsigned I = 0, N = CallOperator->getNumParams(); I != N; ++I) {

2376 nullptr));

2377 }

2378 Block->setParams(BlockParams);

2379

2380 Block->setIsConversionFromLambda(true);

2381

2382

2383

2384

2388 ConvLocation, nullptr,

2389 Src->getType(), CapVarTSI,

2392 false, Init.get());

2394

2395

2396

2398

2399

2400

2401 Expr *BuildBlock =

2403 false);

2405 Cleanup.setExprNeedsCleanups(true);

2406

2407 return BuildBlock;

2408}

2409

2414 return FD;

2415 }

2416

2419

2421 if (!FTD)

2422 return nullptr;

2423

2426

2428}

2429

2430bool Sema::addInstantiatedCapturesToScope(

2435 const auto *LambdaPattern = cast(PatternDecl)->getParent();

2436

2437 unsigned Instantiated = 0;

2438

2439

2440

2441

2442

2443

2444

2445

2446

2447 LambdaScopeInfo *InstantiatingScope = nullptr;

2448 if (LambdaPattern->capture_size() && !LambdaClass->capture_size()) {

2449 for (FunctionScopeInfo *Scope : llvm::reverse(FunctionScopes)) {

2450 auto *LSI = dyn_cast(Scope);

2452 continue;

2453 InstantiatingScope = LSI;

2454 break;

2455 }

2456 assert(InstantiatingScope);

2457 }

2458

2459 auto AddSingleCapture = [&](const ValueDecl *CapturedPattern,

2460 unsigned Index) {

2461 ValueDecl *CapturedVar =

2462 InstantiatingScope ? InstantiatingScope->Captures[Index].getVariable()

2463 : LambdaClass->getCapture(Index)->getCapturedVar();

2466 };

2467

2468 for (const LambdaCapture &CapturePattern : LambdaPattern->captures()) {

2469 if (!CapturePattern.capturesVariable()) {

2470 Instantiated++;

2471 continue;

2472 }

2473 ValueDecl *CapturedPattern = CapturePattern.getCapturedVar();

2474

2476 Instantiated++;

2477 continue;

2478 }

2479

2481 AddSingleCapture(CapturedPattern, Instantiated++);

2482 } else {

2484 SmallVector<UnexpandedParameterPack, 2> Unexpanded;

2485 SemaRef.collectUnexpandedParameterPacks(

2486 dyn_cast(CapturedPattern)->getInit(), Unexpanded);

2487 auto NumArgumentsInExpansion =

2489 if (!NumArgumentsInExpansion)

2490 continue;

2491 for (unsigned Arg = 0; Arg < *NumArgumentsInExpansion; ++Arg)

2492 AddSingleCapture(CapturedPattern, Instantiated++);

2493 }

2494 }

2495 return false;

2496}

2497

2505 return;

2506 }

2507

2509

2511 if (!FDPattern)

2512 return;

2513

2514 if (!ShouldAddDeclsFromParentScope)

2515 return;

2516

2518 InstantiationAndPatterns;

2519 while (FDPattern && FD) {

2520 InstantiationAndPatterns.emplace_back(FDPattern, FD);

2521

2522 FDPattern =

2525 }

2526

2527

2528

2529

2530

2531

2532

2533

2534

2535

2536

2537 for (auto [FDPattern, FD] : llvm::reverse(InstantiationAndPatterns)) {

2538 SemaRef.addInstantiatedParametersToScope(FD, FDPattern, Scope, MLTAL);

2539 SemaRef.addInstantiatedLocalVarsToScope(FD, FDPattern, Scope);

2540

2542 SemaRef.addInstantiatedCapturesToScope(FD, FDPattern, Scope, MLTAL);

2543 }

2544}

This file provides some common utility functions for processing Lambda related AST Constructs.

This file defines the classes used to store parsed information about declaration-specifiers and decla...

Defines the clang::Expr interface and subclasses for C++ expressions.

This file declares semantic analysis functions specific to ARM.

This file declares semantic analysis for CUDA constructs.

static LambdaCaptureDefault mapImplicitCaptureStyle(CapturingScopeInfo::ImplicitCaptureStyle ICS)

Definition SemaLambda.cpp:1982

static CallingConv getLambdaConversionFunctionCallConv(Sema &S, const FunctionProtoType *CallOpProto)

Definition SemaLambda.cpp:1650

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:591

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:662

static TypeSourceInfo * getLambdaType(Sema &S, LambdaIntroducer &Intro, Declarator &ParamInfo, Scope *CurScope, SourceLocation Loc, bool &ExplicitResultType)

Definition SemaLambda.cpp:936

static FunctionDecl * getPatternFunctionDecl(FunctionDecl *FD)

Definition SemaLambda.cpp:2410

static LambdaScopeInfo * getCurrentLambdaScopeUnsafe(Sema &S)

Definition SemaLambda.cpp:904

static UnsignedOrNone getStackIndexOfNearestEnclosingCaptureReadyLambda(ArrayRef< const clang::sema::FunctionScopeInfo * > FunctionScopes, ValueDecl *VarToCapture)

Examines the FunctionScopeInfo stack to determine the nearest enclosing lambda (to the current lambda...

Definition SemaLambda.cpp:70

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:683

static TemplateParameterList * getGenericLambdaTemplateParameterList(LambdaScopeInfo *LSI, Sema &SemaRef)

Definition SemaLambda.cpp:234

static void addBlockPointerConversion(Sema &S, SourceRange IntroducerRange, CXXRecordDecl *Class, CXXMethodDecl *CallOperator)

Add a lambda's conversion to block pointer.

Definition SemaLambda.cpp:1871

static void buildLambdaScopeReturnType(Sema &S, LambdaScopeInfo *LSI, CXXMethodDecl *CallOperator, bool ExplicitResultType)

Definition SemaLambda.cpp:529

static SourceRange ConstructFixItRangeForUnusedCapture(Sema &S, SourceRange CaptureRange, SourceLocation PrevCaptureLoc, bool CurHasPreviousCapture, bool IsLast)

Definition SemaLambda.cpp:2103

static TypeSourceInfo * getDummyLambdaType(Sema &S, SourceLocation Loc=SourceLocation())

Definition SemaLambda.cpp:910

static QualType buildTypeForLambdaCallOperator(Sema &S, clang::CXXRecordDecl *Class, TemplateParameterList *TemplateParams, TypeSourceInfo *MethodTypeInfo)

Definition SemaLambda.cpp:385

static bool isInInlineFunction(const DeclContext *DC)

Determine whether the given context is or is enclosed in an inline function.

Definition SemaLambda.cpp:266

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:1855

static void repeatForLambdaConversionFunctionCallingConvs(Sema &S, const FunctionProtoType &CallOpProto, Func F)

Definition SemaLambda.cpp:1602

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:1680

This file provides some common utility functions for processing Lambdas.

This file declares semantic analysis for OpenMP constructs and clauses.

This file declares semantic analysis for SYCL constructs.

a trap message and trap category.

Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...

TranslationUnitDecl * getTranslationUnitDecl() const

QualType getBlockPointerType(QualType T) const

Return the uniqued reference to the type for a block of the specified type.

static CanQualType getCanonicalType(QualType T)

Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...

DeclarationNameTable DeclarationNames

QualType getPointerType(QualType T) const

Return the uniqued reference to the type for a pointer to the specified type.

CallingConv getDefaultCallingConvention(bool IsVariadic, bool IsCXXMethod) const

Retrieves the default calling convention for the current context.

TypeSourceInfo * getTrivialTypeSourceInfo(QualType T, SourceLocation Loc=SourceLocation()) const

Allocate a TypeSourceInfo where all locations have been initialized to a given location,...

QualType getFunctionType(QualType ResultTy, ArrayRef< QualType > Args, const FunctionProtoType::ExtProtoInfo &EPI) const

Return a normal function type with a typed argument list.

static bool hasSameType(QualType T1, QualType T2)

Determine whether the given types T1 and T2 are equivalent.

const TargetInfo & getTargetInfo() const

QualType getAutoDeductType() const

C++11 deduction pattern for 'auto' type.

CanQualType getCanonicalTagType(const TagDecl *TD) const

Attr - This represents one attribute.

A builtin binary operation expression such as "x + y" or "x <= y".

A binding in a decomposition declaration.

A class which contains all the information about a particular captured value.

Represents a block literal declaration, which is like an unnamed FunctionDecl.

static BlockDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L)

BlockExpr - Adaptor class for mixing a BlockDecl with expressions.

BasePaths - Represents the set of paths from a derived class to one of its (direct or indirect) bases...

bool isAmbiguous(CanQualType BaseType) const

Determine whether the path from the most-derived type to the given base type is ambiguous (i....

Represents a C++ conversion function within a class.

static CXXConversionDecl * Create(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo, bool UsesFPIntrin, bool isInline, ExplicitSpecifier ES, ConstexprSpecKind ConstexprKind, SourceLocation EndLocation, const AssociatedConstraint &TrailingRequiresClause={})

QualType getConversionType() const

Returns the type that this conversion function is converting to.

Represents a static or instance method of a struct/union/class.

bool isImplicitObjectMemberFunction() const

[C++2b][dcl.fct]/p7 An implicit object member function is a non-static member function without an exp...

static CXXMethodDecl * Create(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo, StorageClass SC, bool UsesFPIntrin, bool isInline, ConstexprSpecKind ConstexprKind, SourceLocation EndLocation, const AssociatedConstraint &TrailingRequiresClause={})

const CXXRecordDecl * getParent() const

Return the parent of this method declaration, which is the class in which this method is defined.

Represents a C++ struct/union/class.

void setLambdaTypeInfo(TypeSourceInfo *TS)

void setLambdaIsGeneric(bool IsGeneric)

static CXXRecordDecl * CreateLambda(const ASTContext &C, DeclContext *DC, TypeSourceInfo *Info, SourceLocation Loc, unsigned DependencyKind, bool IsGeneric, LambdaCaptureDefault CaptureDefault)

bool isCapturelessLambda() const

Represents a C++ nested-name-specifier or a global scope specifier.

ConditionalOperator - The ?

DeclContext - This is used only as base class of specific decl types that can act as declaration cont...

DeclContext * getParent()

getParent - Returns the containing DeclContext.

bool Equals(const DeclContext *DC) const

Determine whether this declaration context is equivalent to the declaration context DC.

bool isFileContext() const

bool isDependentContext() const

Determines whether this context is dependent on a template parameter.

DeclContext * getLexicalParent()

getLexicalParent - Returns the containing lexical DeclContext.

lookup_result lookup(DeclarationName Name) const

lookup - Find the declarations (if any) with the given Name in this context.

bool isTranslationUnit() const

void addDecl(Decl *D)

Add the declaration D into this context.

bool isFunctionOrMethod() const

Simple template class for restricting typo correction candidates to ones having a single Decl* of the...

A reference to a declared variable, function, enum, etc.

Captures information about "declaration specifiers".

SCS getStorageClassSpec() const

bool SetTypeQual(TQ T, SourceLocation Loc)

ConstexprSpecKind getConstexprSpecifier() const

Decl - This represents one declaration (or definition), e.g.

void setInvalidDecl(bool Invalid=true)

setInvalidDecl - Indicates the Decl had a semantic error.

void markUsed(ASTContext &C)

Mark the declaration used, in the sense of odr-use.

Module * getOwningModule() const

Get the module that owns this declaration (for visibility purposes).

bool isInvalidDecl() const

void setAccess(AccessSpecifier AS)

SourceLocation getLocation() const

void setImplicit(bool I=true)

void setReferenced(bool R=true)

DeclContext * getDeclContext()

void setLexicalDeclContext(DeclContext *DC)

DeclarationNameLoc - Additional source/type location info for a declaration name.

static DeclarationNameLoc makeNamedTypeLoc(TypeSourceInfo *TInfo)

Construct location information for a constructor, destructor or conversion operator.

static DeclarationNameLoc makeCXXOperatorNameLoc(SourceLocation BeginLoc, SourceLocation EndLoc)

Construct location information for a non-literal C++ operator.

The name of a declaration.

SourceLocation getBeginLoc() const LLVM_READONLY

const AssociatedConstraint & getTrailingRequiresClause() const

Get the constraint-expression introduced by the trailing requires-clause in the function/member decla...

void setTrailingRequiresClause(const AssociatedConstraint &AC)

TypeSourceInfo * getTypeSourceInfo() const

Information about one declarator, including the parsed type information and the identifier.

bool isFunctionDeclarator(unsigned &idx) const

isFunctionDeclarator - This method returns true if the declarator is a function declarator (looking t...

const DeclaratorChunk & getTypeObject(unsigned i) const

Return the specified TypeInfo from this declarator.

const DeclSpec & getDeclSpec() const

getDeclSpec - Return the declaration-specifier that this declarator was declared with.

Expr * getTrailingRequiresClause()

Sets a trailing requires clause for this declarator.

unsigned getNumTypeObjects() const

Return the number of types applied to this declarator.

bool isExplicitObjectMemberFunction()

SourceRange getSourceRange() const LLVM_READONLY

Get the source range that spans this declarator.

DeclaratorChunk::FunctionTypeInfo & getFunctionTypeInfo()

getFunctionTypeInfo - Retrieves the function type info object (looking through parentheses).

An instance of this object exists for each enum constant that is defined.

Store information needed for an explicit specifier.

Represents an expression – generally a full-expression – that introduces cleanups to be run at the en...

This represents one expression.

Expr * IgnoreParens() LLVM_READONLY

Skip past any parentheses which might surround this expression until reaching a fixed point.

Represents difference between two FPOptions values.

bool isFPConstrained() const

Represents a member of a struct/union/class.

static FieldDecl * Create(const ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, const IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, Expr *BW, bool Mutable, InClassInitStyle InitStyle)

static FixItHint CreateRemoval(CharSourceRange RemoveRange)

Create a code modification hint that removes the given source range.

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.

void setSubExpr(Expr *E)

As with any mutator of the AST, be very careful when modifying an existing AST to preserve its invari...

const Expr * getSubExpr() const

Represents a function declaration or definition.

const ParmVarDecl * getParamDecl(unsigned i) const

Stmt * getBody(const FunctionDecl *&Definition) const

Retrieve the body (definition) of the function.

ConstexprSpecKind getConstexprKind() const

void setDescribedFunctionTemplate(FunctionTemplateDecl *Template)

FunctionTemplateDecl * getDescribedFunctionTemplate() const

Retrieves the function template that is described by this function declaration.

QualType getReturnType() const

ArrayRef< ParmVarDecl * > parameters() const

FunctionTemplateDecl * getPrimaryTemplate() const

Retrieve the primary template that this function template specialization either specializes or was in...

bool isVariadic() const

Whether this function is variadic.

@ TK_MemberSpecialization

@ TK_DependentNonTemplate

TemplatedKind getTemplatedKind() const

What kind of templated function this is.

bool isConstexpr() const

Whether this is a (C++11) constexpr function or constexpr constructor.

FunctionDecl * getInstantiatedFromDecl() const

void setConstexprKind(ConstexprSpecKind CSK)

FunctionDecl * getInstantiatedFromMemberFunction() const

If this function is an instantiation of a member function of a class template specialization,...

unsigned getNumParams() const

Return the number of parameters this function must have based on its FunctionType.

void setParams(ArrayRef< ParmVarDecl * > NewParamInfo)

Represents a prototype with parameter type info, e.g.

bool isVariadic() const

Whether this function prototype is variadic.

ExtProtoInfo getExtProtoInfo() const

ArrayRef< QualType > getParamTypes() const

Declaration of a template function.

FunctionDecl * getTemplatedDecl() const

Get the underlying function declaration of the template.

FunctionTemplateDecl * getInstantiatedFromMemberTemplate() const

static FunctionTemplateDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name, TemplateParameterList *Params, NamedDecl *Decl)

Create a function template node.

TypeLoc getReturnLoc() const

ExtInfo withCallingConv(CallingConv cc) const

CallingConv getCallConv() const

QualType getReturnType() const

One of these records is kept for each identifier that is lexed.

IdentifierInfo & get(StringRef Name)

Return the identifier token info for the specified named identifier.

ImplicitCastExpr - Allows us to explicitly represent implicit type conversions, which have no direct ...

static ImplicitCastExpr * Create(const ASTContext &Context, QualType T, CastKind Kind, Expr *Operand, const CXXCastPath *BasePath, ExprValueKind Cat, FPOptionsOverride FPO)

Describes the kind of initialization being performed, along with location information for tokens rela...

static InitializationKind CreateDirect(SourceLocation InitLoc, SourceLocation LParenLoc, SourceLocation RParenLoc)

Create a direct initialization.

static InitializationKind CreateCopy(SourceLocation InitLoc, SourceLocation EqualLoc, bool AllowExplicitConvs=false)

Create a copy initialization.

static InitializationKind CreateDirectList(SourceLocation InitLoc)

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.

Describes an entity that is being initialized.

static InitializedEntity InitializeLambdaToBlock(SourceLocation BlockVarLoc, QualType Type)

static InitializedEntity InitializeLambdaCapture(IdentifierInfo *VarID, QualType FieldType, SourceLocation Loc)

Create the initialization entity for a lambda capture.

Describes the capture of a variable or of this, or of a C++1y init-capture.

A C++ lambda expression, which produces a function object (of unspecified type) that can be invoked l...

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.

A stack-allocated class that identifies which local variable declaration instantiations are present i...

void InstantiatedLocal(const Decl *D, Decl *Inst)

void MakeInstantiatedLocalArgPack(const Decl *D)

Represents the results of name lookup.

DeclClass * getAsSingle() const

bool empty() const

Return true if no decls were found.

Keeps track of the mangled names of lambda expressions and block literals within a particular context...

virtual unsigned getManglingNumber(const CXXMethodDecl *CallOperator)=0

Retrieve the mangling number of a new lambda expression with the given call operator within this cont...

unsigned getNextLambdaIndex()

virtual unsigned getDeviceManglingNumber(const CXXMethodDecl *)

Retrieve the mangling number of a new lambda expression with the given call operator within the devic...

Describes a module or submodule.

bool isNamedModuleUnit() const

Is this a C++20 named module unit.

Module * getTopLevelModule()

Retrieve the top-level module for this (sub)module, which may be this module.

Data structure that captures multiple levels of template argument lists for use in template instantia...

This represents a decl that may have a name.

IdentifierInfo * getIdentifier() const

Get the identifier that names this declaration, if there is one.

bool isPlaceholderVar(const LangOptions &LangOpts) const

DeclarationName getDeclName() const

Get the actual, stored name of the declaration, which may be a special name.

unsigned getNumExprs() const

Return the number of expressions in this paren list.

Represents a parameter to a function.

static ParmVarDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, const IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, StorageClass S, Expr *DefArg)

Wrapper for source info for pointers.

A (possibly-)qualified type.

bool isNull() const

Return true if this QualType doesn't point to a type yet.

LangAS getAddressSpace() const

Return the address space of this type.

QualType getUnqualifiedType() const

Retrieve the unqualified variant of the given type, removing as little sugar as possible.

The collection of all-type qualifiers we support.

void addAddressSpace(LangAS space)

Represents a struct/union/class.

ReturnStmt - This represents a return, optionally of an expression: return; return 4;.

void setRetValue(Expr *E)

SourceLocation getBeginLoc() const

Scope - A scope is a transient data structure that is used while parsing the program.

const Scope * getParent() const

getParent - Return the scope that this is nested in.

void CheckSMEFunctionDefAttributes(const FunctionDecl *FD)

SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)

Emit a diagnostic.

void CheckLambdaCapture(CXXMethodDecl *D, const sema::Capture &Capture)

void SetLambdaAttrs(CXXMethodDecl *Method)

Set device or host device attributes on the given lambda operator() method.

void ActOnFinishedFunctionDefinitionInOpenMPAssumeScope(Decl *D)

Act on D, a function definition inside of an omp [begin/end] assumes.

void CheckSYCLEntryPointFunctionDecl(FunctionDecl *FD)

LambdaScopeForCallOperatorInstantiationRAII(Sema &SemasRef, FunctionDecl *FD, MultiLevelTemplateArgumentList MLTAL, LocalInstantiationScope &Scope, bool ShouldAddDeclsFromParentScope=true)

Definition SemaLambda.cpp:2499

Sema - This implements semantic analysis and AST building for C.

Attr * getImplicitCodeSegOrSectionAttrForFunction(const FunctionDecl *FD, bool IsDefinition)

Returns an implicit CodeSegAttr if a __declspec(code_seg) is found on a containing class.

QualType getCurrentThisType()

Try to retrieve the type of the 'this' pointer.

ExprResult BuildBlockForLambdaConversion(SourceLocation CurrentLocation, SourceLocation ConvLocation, CXXConversionDecl *Conv, Expr *Src)

Definition SemaLambda.cpp:2338

Scope * getCurScope() const

Retrieve the parser's current scope.

ExprResult CreateBuiltinUnaryOp(SourceLocation OpLoc, UnaryOperatorKind Opc, Expr *InputExpr, bool IsAfterAmp=false)

void BuildBasePathArray(const CXXBasePaths &Paths, CXXCastPath &BasePath)

bool RequireCompleteSizedType(SourceLocation Loc, QualType T, unsigned DiagID, const Ts &...Args)

@ LookupOrdinaryName

Ordinary name lookup, which finds ordinary names (functions, variables, typedefs, etc....

QualType deduceVarTypeFromInitializer(VarDecl *VDecl, DeclarationName Name, QualType Type, TypeSourceInfo *TSI, SourceRange Range, bool DirectInit, Expr *Init)

VarDecl * createLambdaInitCaptureVarDecl(SourceLocation Loc, QualType InitCaptureType, SourceLocation EllipsisLoc, IdentifierInfo *Id, unsigned InitStyle, Expr *Init, DeclContext *DeclCtx)

Create a dummy variable within the declcontext of the lambda's call operator, for name lookup purpose...

Definition SemaLambda.cpp:869

ExprResult ActOnLambdaExpr(SourceLocation StartLoc, Stmt *Body)

ActOnLambdaExpr - This is called when the body of a lambda expression was successfully completed.

Definition SemaLambda.cpp:1969

CXXRecordDecl * createLambdaClosureType(SourceRange IntroducerRange, TypeSourceInfo *Info, unsigned LambdaDependencyKind, LambdaCaptureDefault CaptureDefault)

Create a new lambda closure type.

Definition SemaLambda.cpp:248

SmallVector< sema::FunctionScopeInfo *, 4 > FunctionScopes

Stack containing information about each of the nested function, block, and method scopes that are cur...

PoppedFunctionScopePtr PopFunctionScopeInfo(const sema::AnalysisBasedWarnings::Policy *WP=nullptr, const Decl *D=nullptr, QualType BlockType=QualType())

Pop a function (or block or lambda or captured region) scope from the stack.

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...

void ActOnLambdaExpressionAfterIntroducer(LambdaIntroducer &Intro, Scope *CurContext)

Once the Lambdas capture are known, we can start to create the closure, call operator method,...

Definition SemaLambda.cpp:1082

void AddTemplateParametersToLambdaCallOperator(CXXMethodDecl *CallOperator, CXXRecordDecl *Class, TemplateParameterList *TemplateParams)

Definition SemaLambda.cpp:1017

ExprResult MaybeBindToTemporary(Expr *E)

MaybeBindToTemporary - If the passed in expression has a record type with a non-trivial destructor,...

void AddRangeBasedOptnone(FunctionDecl *FD)

Only called on function definitions; if there is a pragma in scope with the effect of a range-based o...

Decl * ActOnFinishFunctionBody(Decl *Decl, Stmt *Body, bool IsInstantiation=false, bool RetainFunctionScopeInfo=false)

Performs semantic analysis at the end of a function body.

void addInitCapture(sema::LambdaScopeInfo *LSI, VarDecl *Var, bool ByRef)

Add an init-capture to a lambda scope.

Definition SemaLambda.cpp:895

FieldDecl * BuildCaptureField(RecordDecl *RD, const sema::Capture &Capture)

Build a FieldDecl suitable to hold the given capture.

Definition SemaLambda.cpp:2054

void PushOnScopeChains(NamedDecl *D, Scope *S, bool AddToContext=true)

Add this decl to the scope shadowed decl chains.

ASTContext & getASTContext() const

std::unique_ptr< sema::FunctionScopeInfo, PoppedFunctionScopeDeleter > PoppedFunctionScopePtr

bool tryCaptureVariable(ValueDecl *Var, SourceLocation Loc, TryCaptureKind Kind, SourceLocation EllipsisLoc, bool BuildAndDiagnose, QualType &CaptureType, QualType &DeclRefType, const unsigned *const FunctionScopeIndexToStopAt)

Try to capture the given variable.

void PopExpressionEvaluationContext()

std::string getAmbiguousPathsDisplayString(CXXBasePaths &Paths)

Builds a string representing ambiguous paths from a specific derived class to different subobjects of...

sema::LambdaScopeInfo * getCurGenericLambda()

Retrieve the current generic lambda info, if any.

void handleLambdaNumbering(CXXRecordDecl *Class, CXXMethodDecl *Method, std::optional< CXXRecordDecl::LambdaNumbering > NumberingOverride=std::nullopt)

Number lambda for linkage purposes if necessary.

Definition SemaLambda.cpp:476

LangAS getDefaultCXXMethodAddrSpace() const

Returns default addr space for method qualifiers.

ExprResult BuildCaptureInit(const sema::Capture &Capture, SourceLocation ImplicitCaptureLoc, bool IsOpenMPMapping=false)

Initialize the given capture with a suitable expression.

Definition SemaLambda.cpp:1905

FPOptions & getCurFPFeatures()

Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer, TranslationUnitKind TUKind=TU_Complete, CodeCompleteConsumer *CompletionConsumer=nullptr)

SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset=0)

Calls Lexer::getLocForEndOfToken()

@ UPPC_Initializer

An initializer.

@ UPPC_DeclarationType

The type of an arbitrary declaration.

void buildLambdaScope(sema::LambdaScopeInfo *LSI, CXXMethodDecl *CallOperator, SourceRange IntroducerRange, LambdaCaptureDefault CaptureDefault, SourceLocation CaptureDefaultLoc, bool ExplicitParams, bool Mutable)

Endow the lambda scope info with the relevant properties.

Definition SemaLambda.cpp:543

const LangOptions & getLangOpts() const

bool CaptureHasSideEffects(const sema::Capture &From)

Does copying/destroying the captured variable have side effects?

Definition SemaLambda.cpp:1997

void ActOnStartOfLambdaDefinition(LambdaIntroducer &Intro, Declarator &ParamInfo, const DeclSpec &DS)

ActOnStartOfLambdaDefinition - This is called just before we start parsing the body of a lambda; it a...

Definition SemaLambda.cpp:1414

void ActOnLambdaClosureParameters(Scope *LambdaScope, MutableArrayRef< DeclaratorChunk::ParamInfo > ParamInfo)

Definition SemaLambda.cpp:1386

bool DiagnoseEmptyLookup(Scope *S, CXXScopeSpec &SS, LookupResult &R, CorrectionCandidateCallback &CCC, TemplateArgumentListInfo *ExplicitTemplateArgs=nullptr, ArrayRef< Expr * > Args={}, DeclContext *LookupCtx=nullptr)

Diagnose an empty lookup.

bool CheckConstexprFunctionDefinition(const FunctionDecl *FD, CheckConstexprKind Kind)

AccessResult CheckBaseClassAccess(SourceLocation AccessLoc, QualType Base, QualType Derived, const CXXBasePath &Path, unsigned DiagID, bool ForceCheck=false, bool ForceUnprivileged=false)

Checks access for a hierarchy conversion.

bool DiagnoseUnexpandedParameterPack(SourceLocation Loc, TypeSourceInfo *T, UnexpandedParameterPackContext UPPC)

If the given type contains an unexpanded parameter pack, diagnose the error.

const LangOptions & LangOpts

void PushExpressionEvaluationContextForFunction(ExpressionEvaluationContext NewContext, FunctionDecl *FD)

sema::LambdaScopeInfo * getCurLambda(bool IgnoreNonLambdaCapturingScope=false)

Retrieve the current lambda scope info, if any.

void CompleteLambdaCallOperator(CXXMethodDecl *Method, SourceLocation LambdaLoc, SourceLocation CallOperatorLoc, const AssociatedConstraint &TrailingRequiresClause, TypeSourceInfo *MethodTyInfo, ConstexprSpecKind ConstexprKind, StorageClass SC, ArrayRef< ParmVarDecl * > Params, bool HasExplicitResultType)

Definition SemaLambda.cpp:1028

void maybeAddDeclWithEffects(FuncOrBlockDecl *D)

Inline checks from the start of maybeAddDeclWithEffects, to minimize performance impact on code not u...

void CheckCXXDefaultArguments(FunctionDecl *FD)

Helpers for dealing with blocks and functions.

CleanupInfo Cleanup

Used to control the generation of ExprWithCleanups.

void DiagnoseShadowingLambdaDecls(const sema::LambdaScopeInfo *LSI)

Diagnose shadowing for variables shadowed in the lambda record LambdaRD when these variables are capt...

Expr * BuildCXXThisExpr(SourceLocation Loc, QualType Type, bool IsImplicit)

Build a CXXThisExpr and mark it referenced in the current context.

QualType BuildReferenceType(QualType T, bool LValueRef, SourceLocation Loc, DeclarationName Entity)

Build a reference type.

ExprResult BuildDeclarationNameExpr(const CXXScopeSpec &SS, LookupResult &R, bool NeedsADL, bool AcceptInvalidDecl=false)

void DiagPlaceholderVariableDefinition(SourceLocation Loc)

DeclContext * CurContext

CurContext - This is the current declaration context of parsing.

bool IsDerivedFrom(SourceLocation Loc, CXXRecordDecl *Derived, CXXRecordDecl *Base, CXXBasePaths &Paths)

Determine whether the type Derived is a C++ class that is derived from the type Base.

bool inTemplateInstantiation() const

Determine whether we are currently performing template instantiation.

void ActOnLambdaExplicitTemplateParameterList(LambdaIntroducer &Intro, 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:565

void ActOnLambdaClosureQualifiers(LambdaIntroducer &Intro, SourceLocation MutableLoc)

Definition SemaLambda.cpp:1360

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:1578

bool DiagnoseUseOfDecl(NamedDecl *D, ArrayRef< SourceLocation > Locs, const ObjCInterfaceDecl *UnknownObjCClass=nullptr, bool ObjCPropertyAccess=false, bool AvoidPartialAvailabilityChecks=false, ObjCInterfaceDecl *ClassReciever=nullptr, bool SkipTrailingRequiresClause=false)

Determine whether the use of this declaration is valid, and emit any corresponding diagnostics.

bool CheckParmsForFunctionDef(ArrayRef< ParmVarDecl * > Parameters, bool CheckParameterNames)

CheckParmsForFunctionDef - Check that the parameters of the given function are appropriate for the de...

void CheckShadow(NamedDecl *D, NamedDecl *ShadowedDecl, const LookupResult &R)

Diagnose variable or built-in function shadowing.

bool DiagnoseUnusedLambdaCapture(SourceRange CaptureRange, SourceRange FixItRange, const sema::Capture &From)

Diagnose if an explicit lambda capture is unused.

Definition SemaLambda.cpp:2022

QualType buildLambdaInitCaptureInitialization(SourceLocation Loc, bool ByRef, SourceLocation EllipsisLoc, UnsignedOrNone NumExpansions, IdentifierInfo *Id, bool DirectInit, Expr *&Init)

Definition SemaLambda.cpp:803

SmallVector< ExprWithCleanups::CleanupObject, 8 > ExprCleanupObjects

ExprCleanupObjects - This is the stack of objects requiring cleanup that are created by the current f...

sema::AnalysisBasedWarnings AnalysisWarnings

Worker object for performing CFG-based warnings.

@ UnevaluatedAbstract

The current expression occurs within an unevaluated operand that unconditionally permits abstract ref...

@ UnevaluatedList

The current expression occurs within a braced-init-list within an unevaluated operand.

@ ConstantEvaluated

The current context is "potentially evaluated" in C++11 terms, but the expression is evaluated at com...

@ DiscardedStatement

The current expression occurs within a discarded statement.

@ PotentiallyEvaluated

The current expression is potentially evaluated at run time, which means that code may be generated t...

@ Unevaluated

The current expression and its subexpressions occur within an unevaluated operand (C++11 [expr]p7),...

@ ImmediateFunctionContext

In addition of being constant evaluated, the current expression occurs in an immediate function conte...

@ PotentiallyEvaluatedIfUsed

The current expression is potentially evaluated, but any declarations referenced inside that expressi...

TypeSourceInfo * GetTypeForDeclarator(Declarator &D)

GetTypeForDeclarator - Convert the type for the specified declarator to Type instances.

bool RequireCompleteType(SourceLocation Loc, QualType T, CompleteTypeKind Kind, TypeDiagnoser &Diagnoser)

Ensure that the type T is a complete type.

void ActOnFields(Scope *S, SourceLocation RecLoc, Decl *TagDecl, ArrayRef< Decl * > Fields, SourceLocation LBrac, SourceLocation RBrac, const ParsedAttributesView &AttrList)

void CheckExplicitObjectLambda(Declarator &D)

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:1665

void CheckCompletedCXXClass(Scope *S, CXXRecordDecl *Record)

Perform semantic checks on a class definition that has been completing, introducing implicitly-declar...

void DiscardCleanupsInEvaluationContext()

SmallVector< ExpressionEvaluationContextRecord, 8 > ExprEvalContexts

A stack of expression evaluation contexts.

void PushDeclContext(Scope *S, DeclContext *DC)

Set the current declaration context until it gets popped.

CXXMethodDecl * CreateLambdaCallOperator(SourceRange IntroducerRange, CXXRecordDecl *Class)

Definition SemaLambda.cpp:992

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:710

ExprResult PerformCopyInitialization(const InitializedEntity &Entity, SourceLocation EqualLoc, ExprResult Init, bool TopLevelOfInitList=false, bool AllowExplicit=false)

friend class InitializationSequence

ExprResult BuildLambdaExpr(SourceLocation StartLoc, SourceLocation EndLoc)

Complete a lambda-expression having processed and attached the lambda body.

Definition SemaLambda.cpp:2135

void ProcessDeclAttributes(Scope *S, Decl *D, const Declarator &PD)

ProcessDeclAttributes - Given a declarator (PD) with attributes indicated in it, apply them to D.

QualType SubstAutoTypeDependent(QualType TypeWithAuto)

SourceRange getRangeForNextToken(SourceLocation Loc, bool IncludeMacros, bool IncludeComments, std::optional< tok::TokenKind > ExpectedToken=std::nullopt)

Calls Lexer::findNextToken() to find the next token, and if the locations of both ends of the token c...

std::tuple< MangleNumberingContext *, Decl * > getCurrentMangleNumberContext(const DeclContext *DC)

Compute the mangling number context for a lambda expression or block literal.

Definition SemaLambda.cpp:279

void finishLambdaExplicitCaptures(sema::LambdaScopeInfo *LSI)

Note that we have finished the explicit captures for the given lambda.

Definition SemaLambda.cpp:561

@ CheckValid

Identify whether this function satisfies the formal rules for constexpr functions in the current lanu...

bool DiagnoseInvalidExplicitObjectParameterInLambda(CXXMethodDecl *Method, SourceLocation CallLoc)

Returns true if the explicit object parameter was invalid.

Definition SemaLambda.cpp:413

bool LookupName(LookupResult &R, Scope *S, bool AllowBuiltinCreation=false, bool ForceNoCPlusPlus=false)

Perform unqualified name lookup starting from a given scope.

UnsignedOrNone getNumArgumentsInExpansionFromUnexpanded(llvm::ArrayRef< UnexpandedParameterPack > Unexpanded, const MultiLevelTemplateArgumentList &TemplateArgs)

void NoteTemplateParameterLocation(const NamedDecl &Decl)

ExprResult ActOnFinishFullExpr(Expr *Expr, bool DiscardedValue)

Encodes a location in the source.

bool isValid() const

Return true if this is a valid SourceLocation object.

SourceLocation getLocWithOffset(IntTy Offset) const

Return a source location with the specified offset from this SourceLocation.

A trivial tuple used to represent a source range.

SourceLocation getEnd() const

SourceLocation getBegin() const

StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).

Stmt - This represents one statement.

SourceLocation getEndLoc() const LLVM_READONLY

bool hasNameForLinkage() const

Is this tag type named, either directly or via being defined in a typedef of this type?

Exposes information about the current target.

virtual CallingConvCheckResult checkCallingConvention(CallingConv CC) const

Determines whether a given calling convention is valid for the target.

TemplateParameterList * getTemplateParameters() const

Get the list of template parameters.

Stores a list of template parameters for a TemplateDecl and its derived classes.

static TemplateParameterList * Create(const ASTContext &C, SourceLocation TemplateLoc, SourceLocation LAngleLoc, ArrayRef< NamedDecl * > Params, SourceLocation RAngleLoc, Expr *RequiresClause)

bool containsUnexpandedParameterPack() const

Determine whether this template parameter list contains an unexpanded parameter pack.

ArrayRef< NamedDecl * > asArray()

TyLocType push(QualType T)

Pushes space for a new TypeLoc of the given type.

TypeSourceInfo * getTypeSourceInfo(ASTContext &Context, QualType T)

Creates a TypeSourceInfo for the given type.

Base wrapper for a particular "section" of type source info.

T getAs() const

Convert to the specified TypeLoc type, returning a null TypeLoc if this TypeLoc is not of the desired...

A container of type source information.

TypeLoc getTypeLoc() const

Return the TypeLoc wrapper for the type source info.

QualType getType() const

Return the type wrapped by this type source info.

void setNameLoc(SourceLocation Loc)

The base class of the type hierarchy.

bool isIntegralOrUnscopedEnumerationType() const

Determine whether this type is an integral or unscoped enumeration type.

CXXRecordDecl * getAsCXXRecordDecl() const

Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...

const T * castAs() const

Member-template castAs.

QualType getPointeeType() const

If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.

bool isDependentType() const

Whether this type is a dependent type, meaning that its definition somehow depends on a template para...

bool containsUnexpandedParameterPack() const

Whether this type is or contains an unexpanded parameter pack, used to support C++0x variadic templat...

bool isUndeducedType() const

Determine whether this type is an undeduced type, meaning that it somehow involves a C++11 'auto' typ...

EnumDecl * getAsEnumDecl() const

Retrieves the EnumDecl this type refers to.

bool isIncompleteType(NamedDecl **Def=nullptr) const

Types are partitioned into 3 broad categories (C99 6.2.5p1): object types, function types,...

std::optional< NullabilityKind > getNullability() const

Determine the nullability of the given type.

Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...

bool isParameterPack() const

Determine whether this value is actually a function parameter pack, init-capture pack,...

VarDecl * getPotentiallyDecomposedVarDecl()

bool isInitCapture() const

Whether this variable is the implicit variable for a lambda init-capture.

Represents a variable declaration or definition.

static VarDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, const IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, StorageClass S)

void setInitStyle(InitializationStyle Style)

void setInitCapture(bool IC)

bool isInitCapture() const

Whether this variable is the implicit variable for a lambda init-capture.

InitializationStyle

Initialization styles.

@ ListInit

Direct list-initialization (C++11)

@ CInit

C-style initialization with assignment.

@ CallInit

Call-style initialization (C++98)

bool hasLocalStorage() const

Returns true if a variable with function scope is a non-static local variable.

StorageClass getStorageClass() const

Returns the storage class as written in the source.

ValueDecl * getVariable() const

bool isVariableCapture() const

bool isBlockCapture() const

SourceLocation getLocation() const

Retrieve the location at which this variable was captured.

bool isNonODRUsed() const

bool isInitCapture() const

Determine whether this capture is an init-capture.

bool isVLATypeCapture() const

SourceLocation getEllipsisLoc() const

Retrieve the source location of the ellipsis, whose presence indicates that the capture is a pack exp...

bool isThisCapture() const

QualType getCaptureType() const

Retrieve the capture type for this capture, which is effectively the type of the non-static data memb...

bool isCopyCapture() const

const VariableArrayType * getCapturedVLAType() const

QualType ReturnType

ReturnType - The target type of return statements in this context, or null if unknown.

bool isCaptured(ValueDecl *Var) const

Determine whether the given variable has been captured.

bool ContainsUnexpandedParameterPack

Whether this contains an unexpanded parameter pack.

SmallVector< Capture, 4 > Captures

Captures - The captures.

ImplicitCaptureStyle ImpCaptureStyle

bool HasImplicitReturnType

Capture & getCXXThisCapture()

Retrieve the capture of C++ 'this', if it has been captured.

bool isCXXThisCaptured() const

Determine whether the C++ 'this' is captured.

SmallVector< NamedDecl *, 4 > LocalPacks

Packs introduced by this, if any.

void addCapture(ValueDecl *Var, bool isBlock, bool isByref, bool isNested, SourceLocation Loc, SourceLocation EllipsisLoc, QualType CaptureType, bool Invalid)

SmallVector< ReturnStmt *, 4 > Returns

The list of return statements that occur within the function or block, if there is any chance of appl...

SourceLocation PotentialThisCaptureLocation

void finishedExplicitCaptures()

Note when all explicit captures have been added.

CleanupInfo Cleanup

Whether any of the capture expressions requires cleanups.

SourceRange IntroducerRange

Source range covering the lambda introducer [...].

bool ExplicitParams

Whether the (empty) parameter list is explicit.

TemplateParameterList * GLTemplateParameterList

If this is a generic lambda, and the template parameter list has been created (from the TemplateParam...

ExprResult RequiresClause

The requires-clause immediately following the explicit template parameter list, if any.

SourceRange ExplicitTemplateParamsRange

Source range covering the explicit template parameter list (if it exists).

CXXRecordDecl * Lambda

The class that describes the lambda.

unsigned NumExplicitCaptures

The number of captures in the Captures list that are explicit captures.

SourceLocation CaptureDefaultLoc

Source location of the '&' or '=' specifying the default capture type, if any.

llvm::DenseMap< unsigned, SourceRange > ExplicitCaptureRanges

A map of explicit capture indices to their introducer source ranges.

bool AfterParameterList

Indicate that we parsed the parameter list at which point the mutability of the lambda is known.

CXXMethodDecl * CallOperator

The lambda's compiler-generated operator().

bool Mutable

Whether this is a mutable lambda.

Defines the clang::TargetInfo interface.

The JSON file list parser is used to communicate input to InstallAPI.

CanQual< Type > CanQualType

Represents a canonical, potentially-qualified type.

bool isa(CodeGen::Address addr)

DeclContext * getLambdaAwareParentOfDeclContext(DeclContext *DC)

ConstexprSpecKind

Define the kind of constexpr specifier.

@ ICIS_NoInit

No in-class initializer.

@ RQ_None

No ref-qualifier was provided.

UnsignedOrNone getStackIndexOfNearestEnclosingCaptureCapableLambda(ArrayRef< const sema::FunctionScopeInfo * > FunctionScopes, ValueDecl *VarToCapture, Sema &S)

Examines the FunctionScopeInfo stack to determine the nearest enclosing lambda (to the current lambda...

Definition SemaLambda.cpp:180

LambdaCaptureKind

The different capture forms in a lambda introducer.

@ LCK_ByCopy

Capturing by copy (a.k.a., by value)

@ LCK_ByRef

Capturing by reference.

@ LCK_VLAType

Capturing variable-length array type.

@ LCK_StarThis

Capturing the *this object by copy.

@ LCK_This

Capturing the *this object by reference.

bool isLambdaCallWithExplicitObjectParameter(const DeclContext *DC)

StorageClass

Storage classes.

bool FTIHasSingleVoidParameter(const DeclaratorChunk::FunctionTypeInfo &FTI)

MutableArrayRef< Expr * > MultiExprArg

@ CopyInit

[a = b], [a = {b}]

bool isLambdaCallOperator(const CXXMethodDecl *MD)

@ Result

The result type of a method or function.

const FunctionProtoType * T

bool hasWeakerNullability(NullabilityKind L, NullabilityKind R)

Return true if L has a weaker nullability annotation than R.

LangAS

Defines the address space values used by the address space qualifier of QualType.

LambdaCaptureDefault

The default, if any, capture method for a lambda expression.

@ VK_PRValue

A pr-value expression (in the C++11 taxonomy) produces a temporary value.

StringRef getLambdaStaticInvokerName()

SmallVector< CXXBaseSpecifier *, 4 > CXXCastPath

A simple array of base specifiers.

CallingConv

CallingConv - Specifies the calling convention that a function uses.

U cast(CodeGen::Address addr)

@ Class

The "class" keyword introduces the elaborated-type-specifier.

ActionResult< Expr * > ExprResult

@ EST_BasicNoexcept

noexcept

Information about how a lambda is numbered within its context.

unsigned DeviceManglingNumber

bool HasKnownInternalLinkage

DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspon...

SourceLocation getTrailingReturnTypeLoc() const

Get the trailing-return-type location for this function declarator.

bool hasTrailingReturnType() const

Determine whether this function declarator had a trailing-return-type.

ParsedType getTrailingReturnType() const

Get the trailing-return-type for this function declarator.

bool hasMutableQualifier() const

Determine whether this lambda-declarator contains a 'mutable' qualifier.

DeclSpec & getOrCreateMethodQualifiers()

ParamInfo - An array of paraminfo objects is allocated whenever a function declarator is parsed.

ExceptionSpecificationType Type

The kind of exception specification this is.

Extra information about a function prototype.

ExceptionSpecInfo ExceptionSpec

RefQualifierKind RefQualifier

unsigned HasTrailingReturn

FunctionType::ExtInfo ExtInfo

unsigned NumExplicitTemplateParams

The number of parameters in the template parameter list that were explicitly specified by the user,...

SmallVector< NamedDecl *, 4 > TemplateParams

Store the list of the template parameters for a generic lambda or an abbreviated function template.

Represents a complete lambda introducer.

SmallVector< LambdaCapture, 4 > Captures

SourceLocation DefaultLoc

LambdaCaptureDefault Default

FunctionScopeRAII(Sema &S)