clang: lib/Sema/SemaLookup.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
39#include "llvm/ADT/STLExtras.h"
40#include "llvm/ADT/STLForwardCompat.h"
41#include "llvm/ADT/SmallPtrSet.h"
42#include "llvm/ADT/TinyPtrVector.h"
43#include "llvm/ADT/edit_distance.h"
44#include "llvm/Support/Casting.h"
45#include "llvm/Support/ErrorHandling.h"
46#include
47#include
48#include
49#include
50#include
51#include
52#include
53
54#include "OpenCLBuiltins.inc"
55
56using namespace clang;
57using namespace sema;
58
59namespace {
60 class UnqualUsingEntry {
63
64 public:
65 UnqualUsingEntry(const DeclContext *Nominated,
67 : Nominated(Nominated), CommonAncestor(CommonAncestor) {
68 }
69
70 const DeclContext *getCommonAncestor() const {
71 return CommonAncestor;
72 }
73
74 const DeclContext *getNominatedNamespace() const {
75 return Nominated;
76 }
77
78
79 struct Comparator {
80 bool operator()(const UnqualUsingEntry &L, const UnqualUsingEntry &R) {
81 return L.getCommonAncestor() < R.getCommonAncestor();
82 }
83
84 bool operator()(const UnqualUsingEntry &E, const DeclContext *DC) {
85 return E.getCommonAncestor() < DC;
86 }
87
88 bool operator()(const DeclContext *DC, const UnqualUsingEntry &E) {
89 return DC < E.getCommonAncestor();
90 }
91 };
92 };
93
94
95
96 class UnqualUsingDirectiveSet {
97 Sema &SemaRef;
98
100
101 ListTy list;
103
104 public:
105 UnqualUsingDirectiveSet(Sema &SemaRef) : SemaRef(SemaRef) {}
106
107 void visitScopeChain(Scope *S, Scope *InnermostFileScope) {
108
109
110
111
113 assert(InnermostFileDC && InnermostFileDC->isFileContext());
114
115 for (; S; S = S->getParent()) {
116
117
118
120 if (Ctx && Ctx->isFileContext()) {
121 visit(Ctx, Ctx);
122 } else if (!Ctx || Ctx->isFunctionOrMethod()) {
123 for (auto *I : S->using_directives())
125 visit(I, InnermostFileDC);
126 }
127 }
128 }
129
130
131
132
133
134
135
136
138 if (!visited.insert(DC).second)
139 return;
140
141 addUsingDirectives(DC, EffectiveDC);
142 }
143
144
145
146
149 if (!visited.insert(NS).second)
150 return;
151
152 addUsingDirective(UD, EffectiveDC);
153 addUsingDirectives(NS, EffectiveDC);
154 }
155
156
157
158
161 while (true) {
164 if (SemaRef.isVisible(UD) && visited.insert(NS).second) {
165 addUsingDirective(UD, EffectiveDC);
166 queue.push_back(NS);
167 }
168 }
169
170 if (queue.empty())
171 return;
172
173 DC = queue.pop_back_val();
174 }
175 }
176
177
178
179
180
181
182
183
185
186
188 while (!Common->Encloses(EffectiveDC))
191
193 }
194
195 void done() { llvm::sort(list, UnqualUsingEntry::Comparator()); }
196
197 typedef ListTy::const_iterator const_iterator;
198
199 const_iterator begin() const { return list.begin(); }
200 const_iterator end() const { return list.end(); }
201
202 llvm::iterator_range<const_iterator>
203 getNamespacesFor(const DeclContext *DC) const {
204 return llvm::make_range(std::equal_range(begin(), end(),
206 UnqualUsingEntry::Comparator()));
207 }
208 };
209}
210
211
212
215 bool Redeclaration) {
216 unsigned IDNS = 0;
217 switch (NameKind) {
226 if (Redeclaration)
228 }
229 if (Redeclaration)
231 break;
232
234
235
236 assert(!Redeclaration && "cannot do redeclaration operator lookup");
238 break;
239
243
244
245
246
247
248
249 if (Redeclaration)
251 } else {
253 }
254 break;
255
258 break;
259
264 break;
265
268 break;
269
272 break;
273
275 assert(Redeclaration && "should only be used for redecl lookup");
279 break;
280
283 break;
284
287 break;
288
291 break;
292
297 break;
298 }
299 return IDNS;
300}
301
302void LookupResult::configure() {
305
306
307
308
310 case OO_New:
311 case OO_Delete:
312 case OO_Array_New:
313 case OO_Array_Delete:
315 break;
316
317 default:
318 break;
319 }
320
321
322
324 if (unsigned BuiltinID = Id->getBuiltinID()) {
326 AllowHidden = true;
327 }
328 }
329}
330
331bool LookupResult::checkDebugAssumptions() const {
332
333 assert(ResultKind != NotFound || Decls.size() == 0);
334 assert(ResultKind != Found || Decls.size() == 1);
336 (Decls.size() == 1 &&
337 isa((*begin())->getUnderlyingDecl())));
339 assert(ResultKind != Ambiguous || Decls.size() > 1 ||
342 assert((Paths != nullptr) == (ResultKind == Ambiguous &&
345 return true;
346}
347
348
349void LookupResult::deletePaths(CXXBasePaths *Paths) {
350 delete Paths;
351}
352
353
354
356
357
358
361 return DC;
362
363
364
366}
367
368
369
373
374
376 !isa(Existing))
377 return true;
378
379 const auto *DUnderlying = D->getUnderlyingDecl();
381
382
383
384
385
386
387
388
389
390 if (DUnderlying->getCanonicalDecl() != EUnderlying->getCanonicalDecl()) {
391 assert(isa(DUnderlying) && isa(EUnderlying));
392 bool HaveTag = isa(EUnderlying);
393 bool WantTag =
395 return HaveTag != WantTag;
396 }
397
398
399
400
401
402 if (const auto *DFD = dyn_cast(DUnderlying)) {
403 const auto *EFD = cast(EUnderlying);
404 unsigned DMin = DFD->getMinRequiredArguments();
405 unsigned EMin = EFD->getMinRequiredArguments();
406
407 if (DMin != EMin)
408 return DMin < EMin;
409
410
411 }
412
413
414 if (const auto *DTD = dyn_cast(DUnderlying)) {
415 const auto *ETD = cast(EUnderlying);
416 unsigned DMin = DTD->getTemplateParameters()->getMinRequiredArguments();
417 unsigned EMin = ETD->getTemplateParameters()->getMinRequiredArguments();
418
419
420
421 if (DMin != EMin)
422 return DMin < EMin;
423
424
425
426 for (unsigned I = DMin, N = DTD->getTemplateParameters()->size();
427 I != N; ++I) {
429 ETD->getTemplateParameters()->getParam(I)) &&
431 DTD->getTemplateParameters()->getParam(I)))
432 return true;
433 }
434 }
435
436
437
438 if (const auto *DVD = dyn_cast(DUnderlying)) {
439 const auto *EVD = cast(EUnderlying);
440 if (EVD->getType()->isIncompleteType() &&
441 !DVD->getType()->isIncompleteType()) {
442
444 }
445 return false;
446 }
447
448
449 if (!isa(DUnderlying) && !isa(DUnderlying)) {
450
451
453 }
454
455
458 if (Prev == EUnderlying)
459 return true;
460 return false;
461}
462
463
465
466
467
468
469
470
471
472
473
474
475
476
477 D = D->getUnderlyingDecl();
478 return isa(D) || isa(D) || isa(D) ||
480 isa(D);
481}
482
483
485 unsigned N = Decls.size();
486
487
488 if (N == 0) {
489 assert(ResultKind == NotFound ||
491 return;
492 }
493
494
495
496 if (N == 1) {
497 const NamedDecl *D = (*Decls.begin())->getUnderlyingDecl();
498 if (isa(D))
500 else if (isa(D))
502 return;
503 }
504
505
506 if (ResultKind == Ambiguous) return;
507
508 llvm::SmallDenseMap<const NamedDecl *, unsigned, 16> Unique;
509 llvm::SmallDenseMap<QualType, unsigned, 16> UniqueTypes;
510
512 bool ReferenceToPlaceHolderVariable = false;
513 bool HasTag = false, HasFunction = false;
514 bool HasFunctionTemplate = false, HasUnresolved = false;
515 const NamedDecl *HasNonFunction = nullptr;
516
518 llvm::BitVector RemovedDecls(N);
519
520 for (unsigned I = 0; I < N; I++) {
521 const NamedDecl *D = Decls[I]->getUnderlyingDecl();
523
524
525
527 N - RemovedDecls.count() > 1) {
528 RemovedDecls.set(I);
529 continue;
530 }
531
532
533
534
535
536
537
538
539 if (HideTags && isa(D)) {
540 bool Hidden = false;
541 for (auto *OtherDecl : Decls) {
542 if (canHideTag(OtherDecl) && !OtherDecl->isInvalidDecl() &&
545 RemovedDecls.set(I);
546 Hidden = true;
547 break;
548 }
549 }
550 if (Hidden)
551 continue;
552 }
553
554 std::optional ExistingI;
555
556
557
558
559
560 if (const auto *TD = dyn_cast(D)) {
562 auto UniqueResult = UniqueTypes.insert(
564 if (!UniqueResult.second) {
565
566 ExistingI = UniqueResult.first->second;
567 }
568 }
569
570
571
572 if (!ExistingI) {
573 auto UniqueResult = Unique.insert(std::make_pair(D, I));
574 if (!UniqueResult.second) {
575
576 ExistingI = UniqueResult.first->second;
577 }
578 }
579
580 if (ExistingI) {
581
582
584 Decls[*ExistingI]))
585 Decls[*ExistingI] = Decls[I];
586 RemovedDecls.set(I);
587 continue;
588 }
589
590
591
592 if (isa(D)) {
593 HasUnresolved = true;
594 } else if (isa(D)) {
595 if (HasTag)
597 HasTag = true;
598 } else if (isa(D)) {
599 HasFunction = true;
600 HasFunctionTemplate = true;
601 } else if (isa(D)) {
602 HasFunction = true;
603 } else {
604 if (HasNonFunction) {
605
606
607
608
609 if (getSema().isEquivalentInternalLinkageDeclaration(HasNonFunction,
610 D)) {
611 EquivalentNonFunctions.push_back(D);
612 RemovedDecls.set(I);
613 continue;
614 }
615 if (D->isPlaceholderVar(getSema().getLangOpts()) &&
618 ReferenceToPlaceHolderVariable = true;
619 }
621 }
622 HasNonFunction = D;
623 }
624 }
625
626
627
628 if (!EquivalentNonFunctions.empty() && )
630 getNameLoc(), HasNonFunction, EquivalentNonFunctions);
631
632
633
634
635 for (int I = RemovedDecls.find_last(); I >= 0; I = RemovedDecls.find_prev(I))
636 Decls[I] = Decls[--N];
638
639 if ((HasNonFunction && (HasFunction || HasUnresolved)) ||
640 (HideTags && HasTag && (HasFunction || HasNonFunction || HasUnresolved)))
642
643 if (Ambiguous && ReferenceToPlaceHolderVariable)
647 else if (HasUnresolved)
649 else if (N > 1 || HasFunctionTemplate)
651 else
653}
654
655void LookupResult::addDeclsFromBasePaths(const CXXBasePaths &P) {
657 for (I = P.begin(), E = P.end(); I != E; ++I)
659 ++DI)
661}
662
666 addDeclsFromBasePaths(*Paths);
669}
670
674 addDeclsFromBasePaths(*Paths);
677}
678
680 Out << Decls.size() << " result(s)";
682 if (Paths) Out << ", base paths present";
683
685 Out << "\n";
686 (*I)->print(Out, 2);
687 }
688}
689
692 << ":\n";
695}
696
697
699 llvm::StringRef Name) {
701 << TypeClass << Name;
703}
704
705
716}
717
718
729}
730
731
732
733
734
735
736
737
738
739
740
741
743 Sema &S, const OpenCLBuiltinStruct &OpenCLBuiltin, unsigned &GenTypeMaxCnt,
746
747 unsigned Sig = SignatureTable[OpenCLBuiltin.SigTableIndex];
748 OCL2Qual(S, TypeTable[Sig], RetTypes);
749 GenTypeMaxCnt = RetTypes.size();
750
751
752
753 for (unsigned Index = 1; Index < OpenCLBuiltin.NumTypes; Index++) {
755 OCL2Qual(S, TypeTable[SignatureTable[OpenCLBuiltin.SigTableIndex + Index]],
756 Ty);
757 GenTypeMaxCnt = (Ty.size() > GenTypeMaxCnt) ? Ty.size() : GenTypeMaxCnt;
758 ArgTypes.push_back(std::move(Ty));
759 }
760}
761
762
763
764
765
766
767
768
769
770
772 ASTContext &Context, unsigned GenTypeMaxCnt,
778
779
780
781 if (RetTypes.size() == 0)
782 return;
783
784
785 for (unsigned IGenType = 0; IGenType < GenTypeMaxCnt; IGenType++) {
787
788 for (unsigned A = 0; A < ArgTypes.size(); A++) {
789
790 if (ArgTypes[A].size() == 0)
791 return;
792
793
794
795
796 assert(GenTypeMaxCnt % ArgTypes[A].size() == 0 &&
797 "argument type count not compatible with gentype type count");
798 unsigned Idx = IGenType % ArgTypes[A].size();
799 ArgList.push_back(ArgTypes[A][Idx]);
800 }
801
803 RetTypes[(RetTypes.size() != 1) ? IGenType : 0], ArgList, PI));
804 }
805}
806
807
808
809
810
811
812
813
814
815
818 const unsigned FctIndex,
819 const unsigned Len) {
820
821 bool HasGenType = false;
822
823
824
825 unsigned GenTypeMaxCnt;
826
828
829 for (unsigned SignatureIndex = 0; SignatureIndex < Len; SignatureIndex++) {
830 const OpenCLBuiltinStruct &OpenCLBuiltin =
831 BuiltinTable[FctIndex + SignatureIndex];
832
833
834
835 if (!isOpenCLVersionContainedInMask(Context.getLangOpts(),
836 OpenCLBuiltin.Versions))
837 continue;
838
839
840
841
842 StringRef Extensions = FunctionExtensionTable[OpenCLBuiltin.Extension];
843 if (!Extensions.empty()) {
845 Extensions.split(ExtVec, " ");
846 bool AllExtensionsDefined = true;
847 for (StringRef Ext : ExtVec) {
849 AllExtensionsDefined = false;
850 break;
851 }
852 }
853 if (!AllExtensionsDefined)
854 continue;
855 }
856
859
860
862 ArgTypes);
863 if (GenTypeMaxCnt > 1) {
864 HasGenType = true;
865 }
866
867
868 std::vector FunctionList;
870 ArgTypes);
871
875
876 for (const auto &FTy : FunctionList) {
880 FTy->isFunctionProtoType());
882
883
884
885 const auto *FP = cast(FTy);
887 for (unsigned IParm = 0, e = FP->getNumParams(); IParm != e; ++IParm) {
890 nullptr, FP->getParamType(IParm), nullptr, SC_None, nullptr);
892 ParmList.push_back(Parm);
893 }
894 NewOpenCLBuiltin->setParams(ParmList);
895
896
897 if (OpenCLBuiltin.IsPure)
898 NewOpenCLBuiltin->addAttr(PureAttr::CreateImplicit(Context));
899 if (OpenCLBuiltin.IsConst)
900 NewOpenCLBuiltin->addAttr(ConstAttr::CreateImplicit(Context));
901 if (OpenCLBuiltin.IsConv)
902 NewOpenCLBuiltin->addAttr(ConvergentAttr::CreateImplicit(Context));
903
905 NewOpenCLBuiltin->addAttr(OverloadableAttr::CreateImplicit(Context));
906
907 LR.addDecl(NewOpenCLBuiltin);
908 }
909 }
910
911
912 if (Len > 1 || HasGenType)
914}
915
918
919
920
921
925 if (II) {
927 if (II == getASTContext().getMakeIntegerSeqName()) {
929 return true;
930 }
931 if (II == getASTContext().getTypePackElementName()) {
933 return true;
934 }
935 if (II == getASTContext().getBuiltinCommonTypeName()) {
937 return true;
938 }
939 }
940
941
943 auto Index = isOpenCLBuiltin(II->getName());
944 if (Index.first) {
946 Index.second);
947 return true;
948 }
949 }
950
951 if (RISCV().DeclareRVVBuiltins || RISCV().DeclareSiFiveVectorBuiltins) {
952 if (().IntrinsicManager)
954
956
957 if (RISCV().IntrinsicManager->CreateIntrinsicIfFound(R, II, PP))
958 return true;
959 }
960
961
962 if (unsigned BuiltinID = II->getBuiltinID()) {
963
964
967 return false;
968
973 return true;
974 }
975 }
976 }
977 }
978
979 return false;
980}
981
982
983
984
993}
994
996 if (ID == Builtin::BIobjc_msgSendSuper)
998}
999
1000
1001
1003
1004 if (->getDefinition() || Class->isDependentContext())
1005 return false;
1006
1007
1008 return ->isBeingDefined();
1009}
1010
1013 return;
1014
1015
1016 if (Class->needsImplicitDefaultConstructor())
1018
1019
1020 if (Class->needsImplicitCopyConstructor())
1022
1023
1024 if (Class->needsImplicitCopyAssignment())
1026
1028
1029 if (Class->needsImplicitMoveConstructor())
1031
1032
1033 if (Class->needsImplicitMoveAssignment())
1035 }
1036
1037
1038 if (Class->needsImplicitDestructor())
1040}
1041
1042
1043
1045 switch (Name.getNameKind()) {
1048 return true;
1049
1051 return Name.getCXXOverloadedOperator() == OO_Equal;
1052
1053 default:
1054 break;
1055 }
1056
1057 return false;
1058}
1059
1060
1061
1066 if (!DC)
1067 return;
1068
1069 switch (Name.getNameKind()) {
1074 if (Record->needsImplicitDefaultConstructor())
1076 if (Record->needsImplicitCopyConstructor())
1079 Record->needsImplicitMoveConstructor())
1081 }
1082 break;
1083
1086 if (Record->getDefinition() && Record->needsImplicitDestructor() &&
1089 break;
1090
1092 if (Name.getCXXOverloadedOperator() != OO_Equal)
1093 break;
1094
1098 if (Record->needsImplicitCopyAssignment())
1101 Record->needsImplicitMoveAssignment())
1103 }
1104 }
1105 break;
1106
1109 break;
1110
1111 default:
1112 break;
1113 }
1114}
1115
1116
1117
1119 bool Found = false;
1120
1121
1124 DC);
1125
1126
1132 }
1133 }
1134
1136 return true;
1137
1141 !isa(DC))
1143
1144
1145
1146
1147
1149 if (->isCompleteDefinition())
1151
1152
1153
1154
1155 auto *ContainedDeducedType =
1159 ContainedDeducedType && ContainedDeducedType->isUndeducedType())
1161
1163 UEnd = Record->conversion_end(); U != UEnd; ++U) {
1165 if (!ConvTemplate)
1166 continue;
1167
1168
1169
1170
1171
1173 R.addDecl(ConvTemplate);
1175 continue;
1176 }
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1190
1193 assert(ConvProto && "Nonsensical conversion function template type");
1194
1195
1196
1197
1203
1204
1205
1211 }
1212 }
1213
1215}
1216
1217
1220 UnqualUsingDirectiveSet &UDirs) {
1221
1222 assert(NS && NS->isFileContext() && "CppNamespaceLookup() requires namespace!");
1223
1224
1226
1227
1228
1229 for (const UnqualUsingEntry &UUE : UDirs.getNamespacesFor(NS))
1230 if (LookupDirect(S, R, UUE.getNominatedNamespace()))
1232
1234
1236}
1237
1240 return Ctx->isFileContext();
1241 return false;
1242}
1243
1244
1245
1246
1248 for (Scope *OuterS = S->getParent(); OuterS; OuterS = OuterS->getParent())
1249 if (DeclContext *DC = OuterS->getLookupEntity())
1250 return DC;
1251 return nullptr;
1252}
1253
1254namespace {
1255
1256
1257struct FindLocalExternScope {
1259 : R(R), OldFindLocalExtern(R.getIdentifierNamespace() &
1260 Decl::IDNS_LocalExtern) {
1263 }
1264 void restore() {
1266 }
1267 ~FindLocalExternScope() {
1268 restore();
1269 }
1271 bool OldFindLocalExtern;
1272};
1273}
1274
1277
1280
1281
1282
1284 for (Scope *PreS = S; PreS; PreS = PreS->getParent())
1285 if (DeclContext *DC = PreS->getEntity())
1287 }
1288
1289
1290
1291
1292
1293
1294
1296 Name.getCXXNameType()->isDependentType()) {
1298 return false;
1299 }
1300
1301
1302
1303
1304 Scope *Initial = S;
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327 UnqualUsingDirectiveSet UDirs(*this);
1328 bool VisitedUsingDirectives = false;
1329 bool LeftStartingScope = false;
1330
1331
1332 FindLocalExternScope FindLocals(R);
1333
1335 bool SearchNamespaceScope = true;
1336
1337 for (; I != IEnd && S->isDeclScope(*I); ++I) {
1340 !(*I)->isTemplateParameter()) {
1341
1342
1343
1344
1345
1346 if (!LeftStartingScope && !Initial->isDeclScope(*I))
1347 LeftStartingScope = true;
1348
1349
1350
1351 if (LeftStartingScope && !((*I)->hasLinkage())) {
1353 continue;
1354 }
1355 } else {
1356
1357
1358 SearchNamespaceScope = false;
1359 }
1361 }
1362 }
1363 if (!SearchNamespaceScope) {
1365 if (S->isClassScope())
1366 if (auto *Record = dyn_cast_if_present(S->getEntity()))
1368 return true;
1369 }
1370
1372
1373
1374
1375
1376
1377 return false;
1378 }
1379
1380 if (DeclContext *Ctx = S->getLookupEntity()) {
1382 for (; Ctx && !Ctx->Equals(OuterCtx); Ctx = Ctx->getLookupParent()) {
1383
1384
1385
1386 if (Ctx->isTransparentContext())
1387 continue;
1388
1389
1390
1391
1392 if (Ctx->isFunctionOrMethod()) {
1393
1394
1395 if (ObjCMethodDecl *Method = dyn_cast(Ctx)) {
1396 if (Method->isInstanceMethod() && Name.getAsIdentifierInfo())
1400 Name.getAsIdentifierInfo(),
1401 ClassDeclared)) {
1405 return true;
1406 }
1407 }
1408 }
1409 }
1410
1411 continue;
1412 }
1413
1414
1415
1416 if (Ctx->isFileContext()) {
1417
1418 if (!VisitedUsingDirectives) {
1419
1421 if (UCtx->isTransparentContext())
1422 continue;
1423
1424 UDirs.visit(UCtx, UCtx);
1425 }
1426
1427
1428
1429 Scope *InnermostFileScope = S;
1430 while (InnermostFileScope &&
1432 InnermostFileScope = InnermostFileScope->getParent();
1433 UDirs.visitScopeChain(Initial, InnermostFileScope);
1434
1435 UDirs.done();
1436
1437 VisitedUsingDirectives = true;
1438 }
1439
1442 return true;
1443 }
1444
1445 continue;
1446 }
1447
1448
1449
1450
1451
1452
1453
1455 return true;
1456 }
1457 }
1458 }
1459
1460
1461
1462 if (!S) return false;
1463
1464
1466 return false;
1467
1468
1469
1470
1471
1472
1473 if (!VisitedUsingDirectives) {
1474 UDirs.visitScopeChain(Initial, S);
1475 UDirs.done();
1476 }
1477
1478
1479
1481 FindLocals.restore();
1482
1483
1484
1485
1486
1487 for (; S; S = S->getParent()) {
1488
1489 bool Found = false;
1490 for (; I != IEnd && S->isDeclScope(*I); ++I) {
1492
1493
1494
1495
1498 }
1499 }
1500
1501 if (Found && S->isTemplateParamScope()) {
1503 return true;
1504 }
1505
1506 DeclContext *Ctx = S->getLookupEntity();
1507 if (Ctx) {
1509 for (; Ctx && !Ctx->Equals(OuterCtx); Ctx = Ctx->getLookupParent()) {
1510
1511
1512
1513 if (Ctx->isTransparentContext())
1514 continue;
1515
1516
1517
1518
1519 if (!(Found && S->isTemplateParamScope())) {
1520 assert(Ctx->isFileContext() &&
1521 "We should have been looking only at file context here already.");
1522
1523
1526 }
1527
1530 return true;
1531 }
1532
1534 return false;
1535 }
1536 }
1537
1539 return false;
1540 }
1541
1542 return !R.empty();
1543}
1544
1548 else
1549
1551
1552
1553
1554 if (auto *TD = dyn_cast(ND))
1555 for (auto *Param : *TD->getTemplateParameters())
1557}
1558
1559
1561 if (FunctionDecl *FD = dyn_cast(Entity)) {
1562
1563
1565 Entity = Pattern;
1566 } else if (CXXRecordDecl *RD = dyn_cast(Entity)) {
1568 Entity = Pattern;
1569 } else if (EnumDecl *ED = dyn_cast(Entity)) {
1570 if (auto *Pattern = ED->getTemplateInstantiationPattern())
1571 Entity = Pattern;
1572 } else if (VarDecl *VD = dyn_cast(Entity)) {
1574 Entity = Pattern;
1575 }
1576
1577
1578
1580 if (Context->isFileContext())
1583}
1584
1588 I != N; ++I) {
1591 nullptr;
1593 M = nullptr;
1595 }
1597}
1598
1599bool Sema::isUsableModule(const Module *M) {
1600 assert(M && "We shouldn't check nullness for module here");
1601
1602 if (UsableModuleUnitsCache.count(M))
1603 return true;
1604
1605
1606
1607
1608
1609
1610 if (M == TheGlobalModuleFragment || M == TheImplicitGlobalModuleFragment) {
1611 UsableModuleUnitsCache.insert(M);
1612 return true;
1613 }
1614
1615
1616
1618 return false;
1619
1621
1622
1623
1624 if (!Current)
1625 return false;
1626
1627
1628
1629 if (Current->isImplicitGlobalModule())
1630 Current = Current->getTopLevelModule();
1633
1634
1635
1636
1637
1638
1639
1640 if (llvm::count_if(ModuleScopes,
1641 [&M](const ModuleScope &MS) { return MS.Module == M; }) ||
1643 UsableModuleUnitsCache.insert(M);
1644 return true;
1645 }
1646
1647 return false;
1648}
1649
1653 return true;
1654 return false;
1655}
1656
1659 if (isUsableModule(Merged))
1660 return true;
1661 return false;
1662}
1663
1664template
1665static bool
1669 if (->hasDefaultArgument())
1670 return false;
1671
1673 while (D && Visited.insert(D).second) {
1674 auto &DefaultArg = D->getDefaultArgStorage();
1675 if (!DefaultArg.isInherited() && S.isAcceptable(D, Kind))
1676 return true;
1677
1678 if (!DefaultArg.isInherited() && Modules) {
1679 auto *NonConstD = const_cast<ParmDecl*>(D);
1681 }
1682
1683
1684
1685 D = DefaultArg.getInheritedFrom();
1686 }
1687 return false;
1688}
1689
1693 if (auto *P = dyn_cast(D))
1694 return ::hasAcceptableDefaultArgument(*this, P, Modules, Kind);
1695
1696 if (auto *P = dyn_cast(D))
1697 return ::hasAcceptableDefaultArgument(*this, P, Modules, Kind);
1698
1699 return ::hasAcceptableDefaultArgument(
1700 *this, cast(D), Modules, Kind);
1701}
1702
1707}
1708
1713}
1714
1715template
1716static bool
1720 bool HasFilteredRedecls = false;
1721
1722 for (auto *Redecl : D->redecls()) {
1723 auto *R = cast(Redecl);
1724 if (!F(R))
1725 continue;
1726
1728 return true;
1729
1730 HasFilteredRedecls = true;
1731
1732 if (Modules)
1733 Modules->push_back(R->getOwningModule());
1734 }
1735
1736
1737 if (HasFilteredRedecls)
1738 return false;
1739
1740 return true;
1741}
1742
1743static bool
1748 S, D, Modules,
1750 if (auto *RD = dyn_cast(D))
1751 return RD->getTemplateSpecializationKind() ==
1753 if (auto *FD = dyn_cast(D))
1754 return FD->getTemplateSpecializationKind() ==
1756 if (auto *VD = dyn_cast(D))
1757 return VD->getTemplateSpecializationKind() ==
1759 llvm_unreachable("unknown explicit specialization kind");
1760 },
1761 Kind);
1762}
1763
1766 return ::hasAcceptableExplicitSpecialization(*this, D, Modules,
1768}
1769
1772 return ::hasAcceptableExplicitSpecialization(*this, D, Modules,
1774}
1775
1776static bool
1781 "not a member specialization");
1783 S, D, Modules,
1785
1786
1787
1788
1789
1790
1791
1792
1794 },
1795 Kind);
1796}
1797
1802}
1803
1808}
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819bool LookupResult::isAcceptableSlow(Sema &SemaRef, NamedDecl *D,
1822 "should not call this: not in slow case");
1823
1825 assert(DeclModule && "hidden decl has no owning module");
1826
1827
1830 return true;
1831
1832
1833
1834
1835 auto IsEffectivelyFileContext = [](const DeclContext *DC) {
1836 return DC->isFileContext() || isa(DC) ||
1837 isa(DC);
1838 };
1839
1840
1841
1843 if (DC && !IsEffectivelyFileContext(DC)) {
1844
1845
1846
1847
1848
1849
1850
1851 bool AcceptableWithinParent;
1853 bool SearchDefinitions = true;
1854 if (const auto *DCD = dyn_cast(DC)) {
1855 if (const auto *TD = DCD->getDescribedTemplate()) {
1858 SearchDefinitions = Index >= TPL->size() || TPL->getParam(Index) != D;
1859 }
1860 }
1861 if (SearchDefinitions)
1862 AcceptableWithinParent =
1864 else
1865 AcceptableWithinParent =
1866 isAcceptable(SemaRef, cast(DC), Kind);
1867 } else if (isa(D) ||
1868 (isa(DC) && !SemaRef.getLangOpts().CPlusPlus))
1869 AcceptableWithinParent = isAcceptable(SemaRef, cast(DC), Kind);
1871
1872
1873 AcceptableWithinParent = false;
1874 do {
1876 AcceptableWithinParent = true;
1877 break;
1878 }
1880 } while (!IsEffectivelyFileContext(DC));
1881 } else {
1882 AcceptableWithinParent =
1884 }
1885
1888
1889 !SemaRef.getLangOpts().ModulesLocalVisibility) {
1890
1891
1893 }
1894 return AcceptableWithinParent;
1895 }
1896
1898 return false;
1899
1901 "Additional Sema::AcceptableKind?");
1902 return isReachableSlow(SemaRef, D);
1903}
1904
1906
1907
1908 if (ModulePrivate && isUsableModule(M))
1909 return true;
1910
1911
1912
1913 if (!ModulePrivate && VisibleModules.isVisible(M))
1914 return true;
1915
1916
1917
1918
1919
1921 if (LookupModules.empty())
1922 return false;
1923
1924
1925 if (LookupModules.count(M))
1926 return true;
1927
1928
1929
1930
1932 return true;
1933
1934
1935 if (ModulePrivate)
1936 return false;
1937
1938
1939 return llvm::any_of(LookupModules, [&](const Module *LookupM) {
1941 });
1942}
1943
1944
1945
1946bool LookupResult::isReachableSlow(Sema &SemaRef, NamedDecl *D) {
1947 assert((SemaRef, D) && "Shouldn't call the slow case.\n");
1948
1950 assert(DeclModule && "hidden decl has no owning module");
1951
1952
1954 return false;
1955
1957 return true;
1958
1959
1960
1961
1962
1963
1964
1965
1966
1968 return false;
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1989 return true;
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999 return false;
2000}
2001
2004}
2005
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016 for (auto *D : R) {
2018 return true;
2019 assert(D->isExternallyDeclarable() &&
2020 "should not have hidden, non-externally-declarable result here");
2021 }
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2040}
2041
2042
2043
2044
2045
2046
2047
2048
2049
2051 unsigned IDNS) {
2053
2054 for (auto *RD : D->redecls()) {
2055
2056 if (RD == D)
2057 continue;
2058
2059 auto ND = cast(RD);
2060
2061
2062
2063 if (ND->isInIdentifierNamespace(IDNS) &&
2065 return ND;
2066 }
2067
2068 return nullptr;
2069}
2070
2073 assert((D) && "not in slow case");
2075 *this, D, Modules, [](const NamedDecl *) { return true; },
2077}
2078
2081 assert((D) && "not in slow case");
2083 *this, D, Modules, [](const NamedDecl *) { return true; },
2085}
2086
2088 if (auto *ND = dyn_cast(D)) {
2089
2090
2091
2092
2093
2094
2096 if (auto *Acceptable = getSema().VisibleNamespaceCache.lookup(Key))
2097 return Acceptable;
2099 ? Key
2101 if (Acceptable)
2103 return Acceptable;
2104 }
2105
2107}
2108
2110
2112 return true;
2113
2114
2115
2117}
2118
2121 return true;
2122
2124}
2125
2127
2129 return true;
2130
2131
2132
2133
2134
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150 if (auto *FD = dyn_cast(ND);
2151 FD && FD->isReservedGlobalPlacementOperator())
2152 return true;
2153
2155
2156
2158 return false;
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180 if (auto *TD = dyn_cast(DC))
2182
2183 return false;
2184}
2185
2187 bool ForceNoCPlusPlus) {
2189 if (!Name) return false;
2190
2192
2194
2195
2197
2199 (S->getEntity() && S->getEntity()->isTransparentContext()))
2200 S = S->getParent();
2201 }
2202
2203
2204 FindLocalExternScope FindLocals(R);
2205
2206
2207
2208
2209
2210 bool LeftStartingScope = false;
2211
2214 I != IEnd; ++I)
2217
2218
2219 if (!LeftStartingScope && !S->isDeclScope(*I))
2220 LeftStartingScope = true;
2221
2222
2223
2224 if (LeftStartingScope && !((*I)->hasLinkage())) {
2226 continue;
2227 }
2228 }
2230 !isa(*I))
2231 continue;
2232
2234
2235
2236
2237 if (I != IEnd) {
2238
2239
2240 while (S && !S->isDeclScope(D))
2241 S = S->getParent();
2242
2243
2244
2245
2247 S = nullptr;
2248
2249
2251 if (!S)
2253
2255 for (++LastI; LastI != IEnd; ++LastI) {
2256 if (S) {
2257
2258 if (!S->isDeclScope(*LastI))
2259 break;
2260 } else {
2261
2264 if (!LastDC->Equals(DC))
2265 break;
2266 }
2267
2268
2271 }
2272
2274 }
2275
2276 return true;
2277 }
2278 } else {
2279
2280 if (CppLookupName(R, S))
2281 return true;
2282 }
2283
2284
2285
2286
2288 return true;
2289
2290
2291
2292
2293
2295}
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2326 assert(StartDC->isFileContext() && "start context is not a file context");
2327
2328
2329
2331
2332
2334 Visited.insert(StartDC);
2335
2336
2337
2339 NamespaceDecl *ND = I->getNominatedNamespace()->getFirstDecl();
2341 Queue.push_back(ND);
2342 }
2343
2344
2345
2346
2347
2348 bool FoundTag = false;
2349 bool FoundNonTag = false;
2350
2352
2353 bool Found = false;
2354 while (!Queue.empty()) {
2356
2357
2358
2359 bool UseLocal = !R.empty();
2360 LookupResult &DirectR = UseLocal ? LocalR : R;
2361 bool FoundDirect = LookupDirect(S, DirectR, ND);
2362
2363 if (FoundDirect) {
2364
2366
2367
2369 FoundTag = true;
2370 else
2371 FoundNonTag = true;
2372
2373
2374 if (UseLocal) {
2377 }
2378 }
2379
2380
2381 if (FoundDirect) {
2383 continue;
2384 }
2385
2387 NamespaceDecl *Nom = I->getNominatedNamespace();
2389 Queue.push_back(Nom);
2390 }
2391 }
2392
2394 if (FoundTag && FoundNonTag)
2396 else
2398 }
2399
2401}
2402
2404 bool InUnqualifiedLookup) {
2405 assert(LookupCtx && "Sema::LookupQualifiedName requires a lookup context");
2406
2408 return false;
2409
2410
2411 assert((!isa(LookupCtx) ||
2413 cast(LookupCtx)->isCompleteDefinition() ||
2414 cast(LookupCtx)->isBeingDefined()) &&
2415 "Declaration context must already be complete!");
2416
2417 struct QualifiedLookupInScope {
2418 bool oldVal;
2420
2421 QualifiedLookupInScope(DeclContext *ctx)
2424 }
2425 ~QualifiedLookupInScope() {
2426 Context->setUseQualifiedLookup(oldVal);
2427 }
2428 } QL(LookupCtx);
2429
2430 CXXRecordDecl *LookupRec = dyn_cast(LookupCtx);
2431
2432
2433
2435
2436
2437
2438
2439
2440
2441
2442
2445 Name.getCXXNameType()->isDependentType()) {
2447 return false;
2448 }
2449 }
2450
2453 if (LookupRec)
2455 return true;
2456 }
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2468 return false;
2469
2470
2473
2474
2475
2477 return false;
2478
2479
2484 return false;
2485
2486
2487
2488
2489
2490
2494 return false;
2495 }
2496
2497
2498
2501
2502
2506
2507
2509 Path.Decls != Path.Decls.end(); ++Path.Decls) {
2510 if ((*Path.Decls)->isInIdentifierNamespace(IDNS))
2511 return true;
2512 }
2513 return false;
2514 };
2515
2517 Paths.setOrigin(LookupRec);
2518 if (!LookupRec->lookupInBases(BaseCallback, Paths))
2519 return false;
2520
2522
2523
2524
2525
2526
2527
2528
2530 int SubobjectNumber = 0;
2532
2533
2536 if ((*I)->isInIdentifierNamespace(IDNS) && (*I)->isCXXInstanceMember())
2537 return false;
2538 return true;
2539 };
2540
2542
2543
2544
2548 using Result = const void *;
2549
2550 auto Next = [&](Iterator &It, Iterator End) -> Result {
2551 while (It != End) {
2554 continue;
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564 if (TemplateNameLookup)
2566 ND = TD;
2567
2568
2569
2570
2573 return T.getCanonicalType().getAsOpaquePtr();
2574 }
2575
2577 }
2578 return nullptr;
2579 };
2580
2581
2582
2583 Iterator AIt = A, BIt = B, AEnd, BEnd;
2584 while (true) {
2585 Result AResult = Next(AIt, AEnd);
2586 Result BResult = Next(BIt, BEnd);
2587 if (!AResult && !BResult)
2588 return true;
2589 if (!AResult || !BResult)
2590 return false;
2591 if (AResult != BResult) {
2592
2593
2594 llvm::SmallDenseMap<Result, bool, 32> AResults;
2595 for (; AResult; AResult = Next(AIt, AEnd))
2596 AResults.insert({AResult, false});
2597 unsigned Found = 0;
2598 for (; BResult; BResult = Next(BIt, BEnd)) {
2599 auto It = AResults.find(BResult);
2600 if (It == AResults.end())
2601 return false;
2602 if (!It->second) {
2603 It->second = true;
2605 }
2606 }
2607 return AResults.size() == Found;
2608 }
2609 }
2610 };
2611
2615
2616
2617
2618 SubobjectAccess = std::min(SubobjectAccess, Path->Access);
2619
2620
2621 if (SubobjectType.isNull()) {
2622
2625 continue;
2626 }
2627
2628 if (SubobjectType !=
2630
2631
2632
2633
2634
2635
2636 if (HasOnlyStaticMembers(Path->Decls) &&
2637 HasSameDeclarations(Paths.begin()->Decls, Path->Decls))
2638 continue;
2639
2640 R.setAmbiguousBaseSubobjectTypes(Paths);
2641 return true;
2642 }
2643
2644
2645
2646
2648
2649
2650
2651
2652
2653
2654 if (HasOnlyStaticMembers(Path->Decls))
2655 continue;
2656
2657
2658
2659 R.setAmbiguousBaseSubobjects(Paths);
2660 return true;
2661 }
2662 }
2663
2664
2665
2667 I != E; ++I) {
2669 (*I)->getAccess());
2670 if (NamedDecl *ND = R.getAcceptableDecl(*I))
2671 R.addDecl(ND, AS);
2672 }
2673 R.resolveKind();
2674 return true;
2675}
2676
2681 return LookupInSuper(R, NNS->getAsRecordDecl());
2682 else
2683
2685}
2686
2688 QualType ObjectType, bool AllowBuiltinCreation,
2689 bool EnteringContext) {
2690
2692 return false;
2693
2694
2696 bool IsDependent = false;
2697 if (!ObjectType.isNull()) {
2698
2699
2700 assert((!SS || SS->isEmpty()) &&
2701 "ObjectType and scope specifier cannot coexist");
2707 "Caller should have completed object type");
2708 } else if (SS && SS->isNotEmpty()) {
2709
2710
2712
2714 return false;
2716
2717
2718
2721 return LookupInSuper(R, NNS->getAsRecordDecl());
2722 }
2724 } else {
2725
2726 return LookupName(R, S, AllowBuiltinCreation);
2727 }
2728
2729
2730
2731 if (DC)
2733 else if (IsDependent)
2734
2735
2736
2738 return false;
2739}
2740
2742
2743
2744
2745
2746 for (const auto &BaseSpec : Class->bases()) {
2752
2753
2754
2755 for (auto I = Result.begin(), E = Result.end(); I != E; ++I) {
2758 I.getAccess()));
2759 }
2760
2761 Result.suppressDiagnostics();
2762 }
2763
2766
2767 return !R.empty();
2768}
2769
2771 assert(Result.isAmbiguous() && "Lookup result must be ambiguous");
2772
2776
2777 switch (Result.getAmbiguityKind()) {
2780 QualType SubobjectType = Paths->front().back().Base->getType();
2781 Diag(NameLoc, diag::err_ambiguous_member_multiple_subobjects)
2783 << LookupRange;
2784
2786 while (isa(*Found) &&
2787 cast(*Found)->isStatic())
2789
2790 Diag((*Found)->getLocation(), diag::note_ambiguous_member_found);
2791 break;
2792 }
2793
2795 Diag(NameLoc, diag::err_ambiguous_member_multiple_subobject_types)
2796 << Name << LookupRange;
2797
2799 std::set<const NamedDecl *> DeclsPrinted;
2801 PathEnd = Paths->end();
2805 continue;
2806 if (DeclsPrinted.insert(D).second) {
2807 if (const auto *TD = dyn_cast(D->getUnderlyingDecl()))
2808 Diag(D->getLocation(), diag::note_ambiguous_member_type_found)
2809 << TD->getUnderlyingType();
2810 else if (const auto *TD = dyn_cast(D->getUnderlyingDecl()))
2811 Diag(D->getLocation(), diag::note_ambiguous_member_type_found)
2813 else
2815 }
2816 }
2817 break;
2818 }
2819
2821 Diag(NameLoc, diag::err_ambiguous_tag_hiding) << Name << LookupRange;
2822
2824
2826 if (TagDecl *TD = dyn_cast(D)) {
2827 TagDecls.insert(TD);
2828 Diag(TD->getLocation(), diag::note_hidden_tag);
2829 }
2830
2832 if (!isa(D))
2834
2835
2838 if (TagDecls.count(F.next()))
2840 }
2842 break;
2843 }
2844
2846 Diag(NameLoc, diag::err_using_placeholder_variable) << Name << LookupRange;
2851 break;
2853 }
2854 break;
2855 }
2856
2858 Diag(NameLoc, diag::err_ambiguous_reference) << Name << LookupRange;
2859
2862 break;
2863 }
2864 }
2865}
2866
2867namespace {
2868 struct AssociatedLookup {
2872 : S(S), Namespaces(Namespaces), Classes(Classes),
2873 InstantiationLoc(InstantiationLoc) {
2874 }
2875
2877 Classes.insert(RD);
2878 return ClassesTransitive.insert(RD);
2879 }
2880
2885
2886 private:
2888 };
2889}
2890
2891static void
2893
2894
2895
2896
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914 while (!Ctx->isFileContext() || Ctx->isInlineNamespace())
2915 Ctx = Ctx->getParent();
2916
2917 Namespaces.insert(Ctx->getPrimaryContext());
2918}
2919
2920
2921
2922static void
2925
2926
2927 switch (Arg.getKind()) {
2929 break;
2930
2932
2933
2934
2936 break;
2937
2940
2941
2942
2946 DeclContext *Ctx = ClassTemplate->getDeclContext();
2947 if (CXXRecordDecl *EnclosingClass = dyn_cast(Ctx))
2948 Result.Classes.insert(EnclosingClass);
2949
2951 }
2952 break;
2953 }
2954
2960
2961
2962 break;
2963
2967 break;
2968 }
2969}
2970
2971
2972
2973static void
2976
2977
2978 if (Class->getDeclName() == Result.S.VAListTagName)
2979 return;
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2991 if (CXXRecordDecl *EnclosingClass = dyn_cast(Ctx))
2992 Result.Classes.insert(EnclosingClass);
2993
2994
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3007 = dyn_cast(Class)) {
3008 DeclContext *Ctx = Spec->getSpecializedTemplate()->getDeclContext();
3009 if (CXXRecordDecl *EnclosingClass = dyn_cast(Ctx))
3010 Result.Classes.insert(EnclosingClass);
3011
3013
3015 for (unsigned I = 0, N = TemplateArgs.size(); I != N; ++I)
3017 }
3018
3019
3020
3022 return;
3023
3024
3025 if (.S.isCompleteType(Result.InstantiationLoc,
3027 return;
3028
3029
3030
3032 Bases.push_back(Class);
3033 while (!Bases.empty()) {
3034
3035 Class = Bases.pop_back_val();
3036
3037
3038 for (const auto &Base : Class->bases()) {
3040
3041
3042
3043
3044
3045
3046 if (!BaseType)
3047 continue;
3049 if (Result.addClassTransitive(BaseDecl)) {
3050
3053
3054
3056 Bases.push_back(BaseDecl);
3057 }
3058 }
3059 }
3060}
3061
3062
3063
3064
3065static void
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3080
3081 while (true) {
3083
3084#define TYPE(Class, Base)
3085#define DEPENDENT_TYPE(Class, Base) case Type::Class:
3086#define NON_CANONICAL_TYPE(Class, Base) case Type::Class:
3087#define NON_CANONICAL_UNLESS_DEPENDENT_TYPE(Class, Base) case Type::Class:
3088#define ABSTRACT_TYPE(Class, Base)
3089#include "clang/AST/TypeNodes.inc"
3090
3091
3092
3093
3094
3095 break;
3096
3097
3098
3099 case Type::Pointer:
3101 continue;
3102 case Type::ConstantArray:
3103 case Type::IncompleteArray:
3104 case Type::VariableArray:
3105 T = cast(T)->getElementType().getTypePtr();
3106 continue;
3107
3108
3109
3110 case Type::Builtin:
3111 break;
3112
3113
3114
3115
3116
3117
3118 case Type::Record: {
3120 cast(cast(T)->getDecl());
3122 break;
3123 }
3124
3125
3126
3127
3128
3129 case Type::Enum: {
3131
3133 if (CXXRecordDecl *EnclosingClass = dyn_cast(Ctx))
3134 Result.Classes.insert(EnclosingClass);
3135
3136
3138
3139 break;
3140 }
3141
3142
3143
3144
3145 case Type::FunctionProto: {
3147 for (const auto &Arg : Proto->param_types())
3148 Queue.push_back(Arg.getTypePtr());
3149
3150 [[fallthrough]];
3151 }
3152 case Type::FunctionNoProto: {
3153 const FunctionType *FnType = cast(T);
3155 continue;
3156 }
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167 case Type::MemberPointer: {
3169
3170
3171 Queue.push_back(MemberPtr->getClass());
3172
3173
3175 continue;
3176 }
3177
3178
3179 case Type::BlockPointer:
3181 continue;
3182
3183
3184
3185 case Type::LValueReference:
3186 case Type::RValueReference:
3188 continue;
3189
3190
3191 case Type::Vector:
3192 case Type::ExtVector:
3193 case Type::ConstantMatrix:
3194 case Type::Complex:
3195 case Type::BitInt:
3196 break;
3197
3198
3199 case Type::Auto:
3200 case Type::DeducedTemplateSpecialization:
3201 break;
3202
3203
3204
3205
3206 case Type::ObjCObject:
3207 case Type::ObjCInterface:
3208 case Type::ObjCObjectPointer:
3209 Result.Namespaces.insert(Result.S.Context.getTranslationUnitDecl());
3210 break;
3211
3212
3213
3214 case Type::Atomic:
3215 T = cast(T)->getValueType().getTypePtr();
3216 continue;
3217 case Type::Pipe:
3218 T = cast(T)->getElementType().getTypePtr();
3219 continue;
3220
3221
3222 case Type::ArrayParameter:
3223 break;
3224
3225 case Type::HLSLAttributedResource:
3226 T = cast(T)->getWrappedType().getTypePtr();
3227 }
3228
3229 if (Queue.empty())
3230 break;
3231 T = Queue.pop_back_val();
3232 }
3233}
3234
3239 AssociatedNamespaces.clear();
3240 AssociatedClasses.clear();
3241
3242 AssociatedLookup Result(*this, InstantiationLoc,
3243 AssociatedNamespaces, AssociatedClasses);
3244
3245
3246
3247
3248
3249
3250
3251
3252 for (unsigned ArgIdx = 0; ArgIdx != Args.size(); ++ArgIdx) {
3253 Expr *Arg = Args[ArgIdx];
3254
3257 continue;
3258 }
3259
3260
3261
3262
3263
3264
3265
3266
3268
3270
3272
3273
3274
3276 }
3277 }
3278}
3279
3287}
3288
3291
3292
3293
3294
3295
3296
3300
3301 assert(!Operators.isAmbiguous() && "Operator lookup cannot be ambiguous");
3302 Functions.append(Operators.begin(), Operators.end());
3303}
3304
3307 bool ConstArg, bool VolatileArg, bool RValueThis,
3308 bool ConstThis, bool VolatileThis) {
3310 "doing special member lookup into record that isn't fully complete");
3312 if (RValueThis || ConstThis || VolatileThis)
3315 "constructors and destructors always have unqualified lvalue this");
3316 if (ConstArg || VolatileArg)
3319 "parameter-less special members can't have qualified arguments");
3320
3321
3323
3324 llvm::FoldingSetNodeID ID;
3325 ID.AddPointer(RD);
3326 ID.AddInteger(llvm::to_underlying(SM));
3327 ID.AddInteger(ConstArg);
3328 ID.AddInteger(VolatileArg);
3329 ID.AddInteger(RValueThis);
3330 ID.AddInteger(ConstThis);
3331 ID.AddInteger(VolatileThis);
3332
3333 void *InsertPoint;
3336
3337
3340
3344
3348 DeclareImplicitDestructor(RD);
3349 });
3350 }
3352 Result->setMethod(DD);
3357 }
3358
3359
3360
3363 Expr *Arg = nullptr;
3364 unsigned NumArgs;
3365
3368
3371 NumArgs = 0;
3374 DeclareImplicitDefaultConstructor(RD);
3375 });
3376 }
3377 } else {
3383 DeclareImplicitCopyConstructor(RD);
3384 });
3385 }
3388 DeclareImplicitMoveConstructor(RD);
3389 });
3390 }
3391 } else {
3395 DeclareImplicitCopyAssignment(RD);
3396 });
3397 }
3400 DeclareImplicitMoveAssignment(RD);
3401 });
3402 }
3403 }
3404
3405 if (ConstArg)
3407 if (VolatileArg)
3409
3410
3411
3412
3413
3414
3415
3416
3420 else
3422 }
3423
3425
3427 NumArgs = 1;
3428 Arg = &FakeArg;
3429 }
3430
3431
3433 if (ConstThis)
3435 if (VolatileThis)
3440
3441
3442
3443
3446
3447 if (R.empty()) {
3448
3449
3450
3451
3453 "lookup for a constructor or assignment operator was empty");
3454 Result->setMethod(nullptr);
3457 }
3458
3459
3460
3462
3463 for (NamedDecl *CandDecl : Candidates) {
3464 if (CandDecl->isInvalidDecl())
3465 continue;
3466
3474 else if (CtorInfo)
3477 true);
3478 else
3480 true);
3486 Classification,
3488 else if (CtorInfo)
3490 CtorInfo.FoundDecl, nullptr,
3492 else
3495 } else {
3496 assert(isa(Cand.getDecl()) &&
3497 "illegal Kind of operator = Decl");
3498 }
3499 }
3500
3504 Result->setMethod(cast(Best->Function));
3506 break;
3507
3509 Result->setMethod(cast(Best->Function));
3511 break;
3512
3514 Result->setMethod(nullptr);
3516 break;
3517
3519 Result->setMethod(nullptr);
3521 break;
3522 }
3523
3525}
3526
3530 false, false, false, false, false);
3531
3532 return cast_or_null(Result.getMethod());
3533}
3534
3536 unsigned Quals) {
3538 "non-const, non-volatile qualifiers for copy ctor arg");
3542
3543 return cast_or_null(Result.getMethod());
3544}
3545
3547 unsigned Quals) {
3551
3552 return cast_or_null(Result.getMethod());
3553}
3554
3556
3559 if (Class->needsImplicitDefaultConstructor())
3560 DeclareImplicitDefaultConstructor(Class);
3561 if (Class->needsImplicitCopyConstructor())
3562 DeclareImplicitCopyConstructor(Class);
3563 if (getLangOpts().CPlusPlus11 && Class->needsImplicitMoveConstructor())
3564 DeclareImplicitMoveConstructor(Class);
3565 });
3566 }
3567
3570 return Class->lookup(Name);
3571}
3572
3574 unsigned Quals, bool RValueThis,
3575 unsigned ThisQuals) {
3577 "non-const, non-volatile qualifiers for copy assignment arg");
3579 "non-const, non-volatile qualifiers for copy assignment this");
3584
3585 return Result.getMethod();
3586}
3587
3589 unsigned Quals,
3590 bool RValueThis,
3591 unsigned ThisQuals) {
3593 "non-const, non-volatile qualifiers for copy assignment this");
3598
3599 return Result.getMethod();
3600}
3601
3603 return cast_or_null(
3605 false, false, false)
3606 .getMethod());
3607}
3608
3612 bool AllowTemplate, bool AllowStringTemplatePack,
3613 bool DiagnoseMissing, StringLiteral *StringLit) {
3616 "literal operator lookup can't be ambiguous");
3617
3618
3620
3621 bool AllowCooked = true;
3622 bool FoundRaw = false;
3623 bool FoundTemplate = false;
3624 bool FoundStringTemplatePack = false;
3625 bool FoundCooked = false;
3626
3630 D = USD->getTargetDecl();
3631
3632
3635 continue;
3636 }
3637
3638 bool IsRaw = false;
3639 bool IsTemplate = false;
3640 bool IsStringTemplatePack = false;
3641 bool IsCooked = false;
3642
3643 if (FunctionDecl *FD = dyn_cast(D)) {
3644 if (FD->getNumParams() == 1 &&
3645 FD->getParamDecl(0)->getType()->getAs<PointerType>())
3646 IsRaw = true;
3647 else if (FD->getNumParams() == ArgTys.size()) {
3648 IsCooked = true;
3649 for (unsigned ArgIdx = 0; ArgIdx != ArgTys.size(); ++ArgIdx) {
3650 QualType ParamTy = FD->getParamDecl(ArgIdx)->getType();
3652 IsCooked = false;
3653 break;
3654 }
3655 }
3656 }
3657 }
3660 if (Params->size() == 1) {
3661 IsTemplate = true;
3663
3664
3665
3667 continue;
3668 }
3669
3670
3671
3672 if (StringLit) {
3678 0, SugaredChecked, CanonicalChecked, CTAK_Specified) ||
3680 IsTemplate = false;
3681 }
3682 } else {
3683 IsStringTemplatePack = true;
3684 }
3685 }
3686
3687 if (AllowTemplate && StringLit && IsTemplate) {
3688 FoundTemplate = true;
3689 AllowRaw = false;
3690 AllowCooked = false;
3691 AllowStringTemplatePack = false;
3692 if (FoundRaw || FoundCooked || FoundStringTemplatePack) {
3694 FoundRaw = FoundCooked = FoundStringTemplatePack = false;
3695 }
3696 } else if (AllowCooked && IsCooked) {
3697 FoundCooked = true;
3698 AllowRaw = false;
3699 AllowTemplate = StringLit;
3700 AllowStringTemplatePack = false;
3701 if (FoundRaw || FoundTemplate || FoundStringTemplatePack) {
3702
3703
3705 FoundRaw = FoundTemplate = FoundStringTemplatePack = false;
3706 }
3707 } else if (AllowRaw && IsRaw) {
3708 FoundRaw = true;
3709 } else if (AllowTemplate && IsTemplate) {
3710 FoundTemplate = true;
3711 } else if (AllowStringTemplatePack && IsStringTemplatePack) {
3712 FoundStringTemplatePack = true;
3713 } else {
3715 }
3716 }
3717
3719
3720
3721
3722 if (StringLit && FoundTemplate)
3724
3725
3726
3727
3728 if (FoundCooked)
3730
3731
3732
3733 if (FoundRaw && FoundTemplate) {
3738 }
3739
3740 if (FoundRaw)
3742
3743 if (FoundTemplate)
3745
3746 if (FoundStringTemplatePack)
3748
3749
3750 if (DiagnoseMissing) {
3751 Diag(R.getNameLoc(), diag::err_ovl_no_viable_literal_operator)
3753 << (ArgTys.size() == 2 ? ArgTys[1] : QualType()) << AllowRaw
3754 << (AllowTemplate || AllowStringTemplatePack);
3756 }
3757
3759}
3760
3763
3764
3765
3766 if (Old == nullptr || Old == New) {
3767 Old = New;
3768 return;
3769 }
3770
3771
3774
3776 while (true) {
3777 Cursor = Cursor->getPreviousDecl();
3778
3779
3780
3781 if (!Cursor) return;
3782
3783
3784 if (Cursor == OldFD) break;
3785
3786
3787 }
3788
3789 Old = New;
3790}
3791
3794
3795
3799 AssociatedNamespaces,
3800 AssociatedClasses);
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813 for (auto *NS : AssociatedNamespaces) {
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3832 for (auto *D : R) {
3833 auto *Underlying = D;
3834 if (auto *USD = dyn_cast(D))
3835 Underlying = USD->getTargetDecl();
3836
3837 if (!isa(Underlying) &&
3838 !isa(Underlying))
3839 continue;
3840
3841
3842
3843
3850 break;
3851 }
3852
3854 continue;
3855
3858
3859
3860
3861
3862 assert(FM &&
3865
3866
3868 llvm::any_of(AssociatedClasses, [&](auto *E) {
3869
3870
3871
3872 if (E->getOwningModule() != FM)
3873 return false;
3874
3875
3876 DeclContext *Ctx = E->getDeclContext();
3877 while (!Ctx->isFileContext() || Ctx->isInlineNamespace())
3878 Ctx = Ctx->getParent();
3879 return Ctx == NS;
3880 })) {
3882 break;
3883 }
3884 }
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896 if (AssociatedClasses.count(RD) && isReachable(D)) {
3898 break;
3899 }
3900 }
3901 }
3902
3903
3905 Result.insert(Underlying);
3906 }
3907 }
3908}
3909
3910
3911
3912
3914
3916
3917namespace {
3918
3919class ShadowContextRAII;
3920
3921class VisibleDeclsRecord {
3922public:
3923
3924
3925
3926 typedef llvm::TinyPtrVector<NamedDecl*> ShadowMapEntry;
3927
3928private:
3929
3930
3931 typedef llvm::DenseMap<DeclarationName, ShadowMapEntry> ShadowMap;
3932
3933
3934 std::list ShadowMaps;
3935
3936
3938
3939 friend class ShadowContextRAII;
3940
3941public:
3942
3943
3945 return !VisitedContexts.insert(Ctx).second;
3946 }
3947
3948 bool alreadyVisitedContext(DeclContext *Ctx) {
3949 return VisitedContexts.count(Ctx);
3950 }
3951
3952
3953
3954
3955
3956
3958
3959
3961 ShadowMaps.back()[ND->getDeclName()].push_back(ND);
3962 }
3963};
3964
3965
3966class ShadowContextRAII {
3967 VisibleDeclsRecord &Visible;
3968
3969 typedef VisibleDeclsRecord::ShadowMap ShadowMap;
3970
3971public:
3972 ShadowContextRAII(VisibleDeclsRecord &Visible) : Visible(Visible) {
3973 Visible.ShadowMaps.emplace_back();
3974 }
3975
3976 ~ShadowContextRAII() {
3977 Visible.ShadowMaps.pop_back();
3978 }
3979};
3980
3981}
3982
3985 std::list::reverse_iterator SM = ShadowMaps.rbegin();
3986 for (std::list::reverse_iterator SMEnd = ShadowMaps.rend();
3988 ShadowMap::iterator Pos = SM->find(ND->getDeclName());
3989 if (Pos == SM->end())
3990 continue;
3991
3992 for (auto *D : Pos->second) {
3993
3997 continue;
3998
3999
4003 continue;
4004
4005
4006
4007
4010 SM == ShadowMaps.rbegin())
4011 continue;
4012
4013
4014
4015 if (isa(ND) && isa(D) &&
4016 cast(ND)->getIntroducer() == D)
4017 continue;
4018
4019
4020 return D;
4021 }
4022 }
4023
4024 return nullptr;
4025}
4026
4027namespace {
4028class LookupVisibleHelper {
4029public:
4030 LookupVisibleHelper(VisibleDeclConsumer &Consumer, bool IncludeDependentBases,
4031 bool LoadExternal)
4032 : Consumer(Consumer), IncludeDependentBases(IncludeDependentBases),
4033 LoadExternal(LoadExternal) {}
4034
4036 bool IncludeGlobalScope) {
4037
4038
4039 Scope *Initial = S;
4040 UnqualUsingDirectiveSet UDirs(SemaRef);
4042
4044 S = S->getParent();
4045
4046 UDirs.visitScopeChain(Initial, S);
4047 }
4048 UDirs.done();
4049
4050
4052 Result.setAllowHidden(Consumer.includeHiddenDecls());
4053 if (!IncludeGlobalScope)
4055 ShadowContextRAII Shadow(Visited);
4056 lookupInScope(Initial, Result, UDirs);
4057 }
4058
4059 void lookupVisibleDecls(Sema &SemaRef, DeclContext *Ctx,
4062 Result.setAllowHidden(Consumer.includeHiddenDecls());
4063 if (!IncludeGlobalScope)
4065
4066 ShadowContextRAII Shadow(Visited);
4067 lookupInDeclContext(Ctx, Result, true,
4068 false);
4069 }
4070
4071private:
4073 bool QualifiedNameLookup, bool InBaseClass) {
4074 if (!Ctx)
4075 return;
4076
4077
4078 if (Visited.visitedContext(Ctx->getPrimaryContext()))
4079 return;
4080
4081 Consumer.EnteredContext(Ctx);
4082
4083
4084 if (isa(Ctx) &&
4085 !Result.getSema().getLangOpts().CPlusPlus) {
4086 auto &S = Result.getSema();
4088
4089
4090 if (LoadExternal)
4092 Idents.getExternalIdentifierLookup()) {
4093 std::unique_ptr Iter(External->getIdentifiers());
4094 for (StringRef Name = Iter->Next(); !Name.empty();
4095 Name = Iter->Next())
4096 Idents.get(Name);
4097 }
4098
4099
4100 for (const auto &Ident : Idents) {
4103 I != E; ++I) {
4105 if (NamedDecl *ND = Result.getAcceptableDecl(*I)) {
4106 Consumer.FoundDecl(ND, Visited.checkHidden(ND), Ctx, InBaseClass);
4108 }
4109 }
4110 }
4111 }
4112
4113 return;
4114 }
4115
4116 if (CXXRecordDecl *Class = dyn_cast(Ctx))
4117 Result.getSema().ForceDeclarationOfImplicitMembers(Class);
4118
4120
4121 bool Load = LoadExternal ||
4122 !(isa(Ctx) || isa(Ctx));
4123
4125 Load ? Ctx->lookups()
4126 : Ctx->noload_lookups(false))
4127 for (auto *D : R)
4128
4129
4130
4131
4132
4133 DeclsToVisit.push_back(D);
4134
4135 for (auto *D : DeclsToVisit)
4136 if (auto *ND = Result.getAcceptableDecl(D)) {
4137 Consumer.FoundDecl(ND, Visited.checkHidden(ND), Ctx, InBaseClass);
4139 }
4140
4141 DeclsToVisit.clear();
4142
4143
4144 if (QualifiedNameLookup) {
4145 ShadowContextRAII Shadow(Visited);
4146 for (auto *I : Ctx->using_directives()) {
4147 if (!Result.getSema().isVisible(I))
4148 continue;
4149 lookupInDeclContext(I->getNominatedNamespace(), Result,
4150 QualifiedNameLookup, InBaseClass);
4151 }
4152 }
4153
4154
4156 if (->hasDefinition())
4157 return;
4158
4159 for (const auto &B : Record->bases()) {
4160 QualType BaseType = B.getType();
4161
4164 if (!IncludeDependentBases) {
4165
4166
4167 continue;
4168 }
4170 if (!TST)
4171 continue;
4173 const auto *TD =
4175 if (!TD)
4176 continue;
4177 RD = TD->getTemplatedDecl();
4178 } else {
4181 continue;
4182 RD = Record->getDecl();
4183 }
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205 ShadowContextRAII Shadow(Visited);
4206 lookupInDeclContext(RD, Result, QualifiedNameLookup,
4207 true);
4208 }
4209 }
4210
4211
4212 if (ObjCInterfaceDecl *IFace = dyn_cast(Ctx)) {
4213
4214 for (auto *Cat : IFace->visible_categories()) {
4215 ShadowContextRAII Shadow(Visited);
4216 lookupInDeclContext(Cat, Result, QualifiedNameLookup,
4217 false);
4218 }
4219
4220
4221 for (auto *I : IFace->all_referenced_protocols()) {
4222 ShadowContextRAII Shadow(Visited);
4223 lookupInDeclContext(I, Result, QualifiedNameLookup,
4224 false);
4225 }
4226
4227
4228 if (IFace->getSuperClass()) {
4229 ShadowContextRAII Shadow(Visited);
4230 lookupInDeclContext(IFace->getSuperClass(), Result, QualifiedNameLookup,
4231 true);
4232 }
4233
4234
4235
4236 if (IFace->getImplementation()) {
4237 ShadowContextRAII Shadow(Visited);
4238 lookupInDeclContext(IFace->getImplementation(), Result,
4239 QualifiedNameLookup, InBaseClass);
4240 }
4241 } else if (ObjCProtocolDecl *Protocol = dyn_cast(Ctx)) {
4242 for (auto *I : Protocol->protocols()) {
4243 ShadowContextRAII Shadow(Visited);
4244 lookupInDeclContext(I, Result, QualifiedNameLookup,
4245 false);
4246 }
4248 for (auto *I : Category->protocols()) {
4249 ShadowContextRAII Shadow(Visited);
4250 lookupInDeclContext(I, Result, QualifiedNameLookup,
4251 false);
4252 }
4253
4254
4255 if (Category->getImplementation()) {
4256 ShadowContextRAII Shadow(Visited);
4257 lookupInDeclContext(Category->getImplementation(), Result,
4258 QualifiedNameLookup, true);
4259 }
4260 }
4261 }
4262
4264 UnqualUsingDirectiveSet &UDirs) {
4265
4266
4267 assert(!IncludeDependentBases && "Unsupported flag for lookupInScope");
4268
4269 if (!S)
4270 return;
4271
4272 if (!S->getEntity() ||
4273 (!S->getParent() && .alreadyVisitedContext(S->getEntity())) ||
4274 (S->getEntity())->isFunctionOrMethod()) {
4275 FindLocalExternScope FindLocals(Result);
4276
4277
4279 for (Decl *D : ScopeDecls) {
4280 if (NamedDecl *ND = dyn_cast(D))
4281 if ((ND = Result.getAcceptableDecl(ND))) {
4282 Consumer.FoundDecl(ND, Visited.checkHidden(ND), nullptr, false);
4284 }
4285 }
4286 }
4287
4288 DeclContext *Entity = S->getLookupEntity();
4289 if (Entity) {
4290
4291
4292
4294
4295 for (DeclContext *Ctx = Entity; Ctx && !Ctx->Equals(OuterCtx);
4296 Ctx = Ctx->getLookupParent()) {
4297 if (ObjCMethodDecl *Method = dyn_cast(Ctx)) {
4298 if (Method->isInstanceMethod()) {
4299
4300 LookupResult IvarResult(Result.getSema(), Result.getLookupName(),
4301 Result.getNameLoc(),
4304 lookupInDeclContext(IFace, IvarResult,
4305 false,
4306 false);
4307 }
4308 }
4309
4310
4311
4312
4313 break;
4314 }
4315
4316 if (Ctx->isFunctionOrMethod())
4317 continue;
4318
4319 lookupInDeclContext(Ctx, Result, false,
4320 false);
4321 }
4322 } else if (!S->getParent()) {
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4334 lookupInDeclContext(Entity, Result, false,
4335 false);
4336 }
4337
4338 if (Entity) {
4339
4340
4341 for (const UnqualUsingEntry &UUE : UDirs.getNamespacesFor(Entity))
4342 lookupInDeclContext(
4343 const_cast<DeclContext *>(UUE.getNominatedNamespace()), Result,
4344 false,
4345 false);
4346 }
4347
4348
4349 ShadowContextRAII Shadow(Visited);
4350 lookupInScope(S->getParent(), Result, UDirs);
4351 }
4352
4353private:
4354 VisibleDeclsRecord Visited;
4356 bool IncludeDependentBases;
4357 bool LoadExternal;
4358};
4359}
4360
4363 bool IncludeGlobalScope, bool LoadExternal) {
4364 LookupVisibleHelper H(Consumer, false,
4365 LoadExternal);
4366 H.lookupVisibleDecls(*this, S, Kind, IncludeGlobalScope);
4367}
4368
4371 bool IncludeGlobalScope,
4372 bool IncludeDependentBases, bool LoadExternal) {
4373 LookupVisibleHelper H(Consumer, IncludeDependentBases, LoadExternal);
4374 H.lookupVisibleDecls(*this, Ctx, Kind, IncludeGlobalScope);
4375}
4376
4379
4381
4382 if (GnuLabelLoc.isValid()) {
4383
4385 Scope *S = CurScope;
4387 return cast(Res);
4388 }
4389
4390
4392 RedeclarationKind::NotForRedeclaration);
4393
4394
4396 Res = nullptr;
4397 if (!Res) {
4398
4401 assert(S && "Not in a function?");
4403 }
4404 return cast(Res);
4405}
4406
4407
4408
4409
4410
4415}
4416
4422 bool EnteringContext,
4423 bool isObjCIvarLookup,
4424 bool FindHidden);
4425
4426
4427
4428
4431
4432 for (; DI != DE; ++DI)
4434 break;
4435
4436 if (DI == DE) {
4438 return;
4439 }
4440
4442 bool AnyVisibleDecls = !NewDecls.empty();
4443
4444 for (; DI != DE; ++DI) {
4446 if (!AnyVisibleDecls) {
4447
4448 AnyVisibleDecls = true;
4449 NewDecls.clear();
4450 }
4451 NewDecls.push_back(*DI);
4452 } else if (!AnyVisibleDecls && !(*DI)->isModulePrivate())
4453 NewDecls.push_back(*DI);
4454 }
4455
4456 if (NewDecls.empty())
4458 else {
4461 }
4462}
4463
4464
4465
4466
4472 else
4473 Identifiers.clear();
4474
4476
4477 switch (NNS->getKind()) {
4480 break;
4481
4484 return;
4486 break;
4487
4490 break;
4491
4495 break;
4496
4499 return;
4500 }
4501
4502 if (II)
4503 Identifiers.push_back(II);
4504}
4505
4508
4509 if (Hiding)
4510 return;
4511
4512
4513
4514
4516 if (!Name)
4517 return;
4518
4519
4520
4522 return;
4523
4525}
4526
4528
4529
4530 addName(Name, nullptr);
4531}
4532
4534
4535
4536 addName(Keyword, nullptr, nullptr, true);
4537}
4538
4539void TypoCorrectionConsumer::addName(StringRef Name, NamedDecl *ND,
4541
4542
4543 StringRef TypoStr = Typo->getName();
4544 unsigned MinED = abs((int)Name.size() - (int)TypoStr.size());
4545 if (MinED && TypoStr.size() / MinED < 3)
4546 return;
4547
4548
4549
4550 unsigned UpperBound = (TypoStr.size() + 2) / 3;
4551 unsigned ED = TypoStr.edit_distance(Name, true, UpperBound);
4552 if (ED > UpperBound) return;
4553
4555 if (isKeyword) TC.makeKeyword();
4556 TC.setCorrectionRange(nullptr, Result.getLookupNameInfo());
4558}
4559
4561
4563 StringRef TypoStr = Typo->getName();
4565
4566
4567
4568
4569 if (TypoStr.size() < 3 &&
4570 (Name != TypoStr || Correction.getEditDistance(true) > TypoStr.size()))
4571 return;
4572
4573
4576 if (!Correction || (*CorrectionValidator, Correction))
4577 return;
4578 }
4579
4581 CorrectionResults[Correction.getEditDistance(false)][Name];
4582
4583 if (!CList.empty() && !CList.back().isResolved())
4584 CList.pop_back();
4586 auto RI = llvm::find_if(CList, [NewND](const TypoCorrection &TypoCorr) {
4588 });
4589 if (RI != CList.end()) {
4590
4591
4592
4593 auto IsDeprecated = [](Decl *D) {
4594 while (D) {
4596 return true;
4597 D = llvm::dyn_cast_or_null(D->getDeclContext());
4598 }
4599 return false;
4600 };
4601
4602
4603
4604 std::pair<bool, std::string> NewKey = {
4607
4608 std::pair<bool, std::string> PrevKey = {
4609 IsDeprecated(RI->getFoundDecl()),
4610 RI->getAsString(SemaRef.getLangOpts())};
4611
4612 if (NewKey < PrevKey)
4613 *RI = Correction;
4614 return;
4615 }
4616 }
4617 if (CList.empty() || Correction.isResolved())
4618 CList.push_back(Correction);
4619
4621 CorrectionResults.erase(std::prev(CorrectionResults.end()));
4622}
4623
4625 const llvm::MapVector<NamespaceDecl *, bool> &KnownNamespaces) {
4626 SearchNamespaces = true;
4627
4628 for (auto KNPair : KnownNamespaces)
4629 Namespaces.addNameSpecifier(KNPair.first);
4630
4631 bool SSIsTemplate = false;
4633 (SS && SS->isValid()) ? SS->getScopeRep() : nullptr) {
4635 SSIsTemplate = T->getTypeClass() == Type::TemplateSpecialization;
4636 }
4637
4638
4639
4641 for (unsigned I = 0; I != Types.size(); ++I) {
4642 const auto *TI = Types[I];
4643 if (CXXRecordDecl *CD = TI->getAsCXXRecordDecl()) {
4644 CD = CD->getCanonicalDecl();
4645 if (!CD->isDependentType() && !CD->isAnonymousStructOrUnion() &&
4646 !CD->isUnion() && CD->getIdentifier() &&
4647 (SSIsTemplate || !isa(CD)) &&
4648 (CD->isBeingDefined() || CD->isCompleteDefinition()))
4649 Namespaces.addNameSpecifier(CD);
4650 }
4651 }
4652}
4653
4655 if (++CurrentTCIndex < ValidatedCorrections.size())
4656 return ValidatedCorrections[CurrentTCIndex];
4657
4658 CurrentTCIndex = ValidatedCorrections.size();
4659 while (!CorrectionResults.empty()) {
4660 auto DI = CorrectionResults.begin();
4661 if (DI->second.empty()) {
4662 CorrectionResults.erase(DI);
4663 continue;
4664 }
4665
4666 auto RI = DI->second.begin();
4667 if (RI->second.empty()) {
4668 DI->second.erase(RI);
4669 performQualifiedLookups();
4670 continue;
4671 }
4672
4675 ValidatedCorrections.push_back(TC);
4676 return ValidatedCorrections[CurrentTCIndex];
4677 }
4678 }
4679 return ValidatedCorrections[0];
4680}
4681
4682bool TypoCorrectionConsumer::resolveCorrection(TypoCorrection &Candidate) {
4684 DeclContext *TempMemberContext = MemberContext;
4686retry_lookup:
4688 EnteringContext,
4689 CorrectionValidator->IsObjCIvarLookup,
4691 switch (Result.getResultKind()) {
4695 if (TempSS) {
4696
4697 TempSS = nullptr;
4699 goto retry_lookup;
4700 }
4701 if (TempMemberContext) {
4702 if (SS && !TempSS)
4703 TempSS = SS.get();
4704 TempMemberContext = nullptr;
4705 goto retry_lookup;
4706 }
4707 if (SearchNamespaces)
4708 QualifiedResults.push_back(Candidate);
4709 break;
4710
4712
4713 break;
4714
4717
4718 for (auto *TRD : Result)
4722 if (SearchNamespaces)
4723 QualifiedResults.push_back(Candidate);
4724 break;
4725 }
4727 return true;
4728 }
4729 return false;
4730}
4731
4732void TypoCorrectionConsumer::performQualifiedLookups() {
4733 unsigned TypoLen = Typo->getName().size();
4735 for (const auto &NSI : Namespaces) {
4737 const Type *NSType = NSI.NameSpecifier->getAsType();
4738
4739
4740
4741
4742
4744 nullptr) {
4745 if (NSDecl->getIdentifier() == QR.getCorrectionAsIdentifierInfo())
4746 continue;
4747 }
4748
4750 TC.ClearCorrectionDecls();
4751 TC.setCorrectionSpecifier(NSI.NameSpecifier);
4752 TC.setQualifierDistance(NSI.EditDistance);
4753 TC.setCallbackDistance(0);
4754
4755
4756
4757
4758 unsigned TmpED = TC.getEditDistance(true);
4759 if (QR.getCorrectionAsIdentifierInfo() != Typo && TmpED &&
4760 TypoLen / TmpED < 3)
4761 continue;
4762
4763 Result.clear();
4764 Result.setLookupName(QR.getCorrectionAsIdentifierInfo());
4766 continue;
4767
4768
4769
4770 switch (Result.getResultKind()) {
4773 if (SS && SS->isValid()) {
4774 std::string NewQualified = TC.getAsString(SemaRef.getLangOpts());
4775 std::string OldQualified;
4776 llvm::raw_string_ostream OldOStream(OldQualified);
4777 SS->getScopeRep()->print(OldOStream, SemaRef.getPrintingPolicy());
4778 OldOStream << Typo->getName();
4779
4780
4781
4782 if (OldOStream.str() == NewQualified)
4783 break;
4784 }
4786 TRD != TRDEnd; ++TRD) {
4787 if (SemaRef.CheckMemberAccess(TC.getCorrectionRange().getBegin(),
4789 : nullptr,
4791 TC.addCorrectionDecl(*TRD);
4792 }
4793 if (TC.isResolved()) {
4794 TC.setCorrectionRange(SS.get(), Result.getLookupNameInfo());
4796 }
4797 break;
4798 }
4803 break;
4804 }
4805 }
4806 }
4807 QualifiedResults.clear();
4808}
4809
4810TypoCorrectionConsumer::NamespaceSpecifierSet::NamespaceSpecifierSet(
4812 : Context(Context), CurContextChain(buildContextChain(CurContext)) {
4814 CurScopeSpec ? CurScopeSpec->getScopeRep() : nullptr) {
4815 llvm::raw_string_ostream SpecifierOStream(CurNameSpecifier);
4817
4819 }
4820
4821
4822
4823 for (DeclContext *C : llvm::reverse(CurContextChain)) {
4824 if (auto *ND = dyn_cast_or_null(C))
4825 CurContextIdentifiers.push_back(ND->getIdentifier());
4826 }
4827
4828
4831 DistanceMap[1].push_back(SI);
4832}
4833
4834auto TypoCorrectionConsumer::NamespaceSpecifierSet::buildContextChain(
4835 DeclContext *Start) -> DeclContextList {
4836 assert(Start && "Building a context chain from a null context");
4837 DeclContextList Chain;
4840 NamespaceDecl *ND = dyn_cast_or_null(DC);
4844 }
4845 return Chain;
4846}
4847
4848unsigned
4849TypoCorrectionConsumer::NamespaceSpecifierSet::buildNestedNameSpecifier(
4851 unsigned NumSpecifiers = 0;
4852 for (DeclContext *C : llvm::reverse(DeclChain)) {
4853 if (auto *ND = dyn_cast_or_null(C)) {
4855 ++NumSpecifiers;
4856 } else if (auto *RD = dyn_cast_or_null(C)) {
4859 ++NumSpecifiers;
4860 }
4861 }
4862 return NumSpecifiers;
4863}
4864
4865void TypoCorrectionConsumer::NamespaceSpecifierSet::addNameSpecifier(
4868 unsigned NumSpecifiers = 0;
4869 DeclContextList NamespaceDeclChain(buildContextChain(Ctx));
4870 DeclContextList FullNamespaceDeclChain(NamespaceDeclChain);
4871
4872
4873 for (DeclContext *C : llvm::reverse(CurContextChain)) {
4874 if (NamespaceDeclChain.empty() || NamespaceDeclChain.back() != C)
4875 break;
4876 NamespaceDeclChain.pop_back();
4877 }
4878
4879
4880 NumSpecifiers = buildNestedNameSpecifier(NamespaceDeclChain, NNS);
4881
4882
4883 if (NamespaceDeclChain.empty()) {
4884
4886 NumSpecifiers =
4887 buildNestedNameSpecifier(FullNamespaceDeclChain, NNS);
4889 dyn_cast_or_null(NamespaceDeclChain.back())) {
4891 bool SameNameSpecifier = false;
4892 if (llvm::is_contained(CurNameSpecifierIdentifiers, Name)) {
4893 std::string NewNameSpecifier;
4894 llvm::raw_string_ostream SpecifierOStream(NewNameSpecifier);
4898 SameNameSpecifier = NewNameSpecifier == CurNameSpecifier;
4899 }
4900 if (SameNameSpecifier || llvm::is_contained(CurContextIdentifiers, Name)) {
4901
4903 NumSpecifiers =
4904 buildNestedNameSpecifier(FullNamespaceDeclChain, NNS);
4905 }
4906 }
4907
4908
4909
4910
4911
4912 if (NNS && !CurNameSpecifierIdentifiers.empty()) {
4915 NumSpecifiers =
4916 llvm::ComputeEditDistance(llvm::ArrayRef(CurNameSpecifierIdentifiers),
4918 }
4919
4920 SpecifierInfo SI = {Ctx, NNS, NumSpecifiers};
4921 DistanceMap[NumSpecifiers].push_back(SI);
4922}
4923
4924
4930 bool EnteringContext,
4931 bool isObjCIvarLookup,
4932 bool FindHidden) {
4937 if (MemberContext) {
4939 if (isObjCIvarLookup) {
4943 return;
4944 }
4945 }
4946
4951 return;
4952 }
4953 }
4954
4956 return;
4957 }
4958
4961 false, EnteringContext);
4962
4963
4964
4966 if (Method->isInstanceMethod() && Method->getClassInterface() &&
4971 = Method->getClassInterface()->lookupInstanceVariable(Name)) {
4974 }
4975 }
4976 }
4977}
4978
4979
4983 bool AfterNestedNameSpecifier) {
4984 if (AfterNestedNameSpecifier) {
4985
4989 return;
4990 }
4991
4994
4996
4997 static const char *const CTypeSpecs[] = {
4998 "char", "const", "double", "enum", "float", "int", "long", "short",
4999 "signed", "struct", "union", "unsigned", "void", "volatile",
5000 "_Complex",
5001
5002 "extern", "inline", "static", "typedef"
5003 };
5004
5005 for (const auto *CTS : CTypeSpecs)
5007
5010
5017
5022
5023 if (SemaRef.getLangOpts().CPlusPlus11) {
5029 }
5030 }
5031
5035 static const char *const CastableTypeSpecs[] = {
5036 "char", "double", "float", "int", "long", "short",
5037 "signed", "unsigned", "void"
5038 };
5039 for (auto *kw : CastableTypeSpecs)
5041 }
5042
5048 }
5049
5055 }
5056
5058 static const char *const CXXExprs[] = {
5059 "delete", "new", "operator", "throw", "typeid"
5060 };
5061 for (const auto *CE : CXXExprs)
5063
5064 if (isa(SemaRef.CurContext) &&
5065 cast(SemaRef.CurContext)->isInstance())
5067
5068 if (SemaRef.getLangOpts().CPlusPlus11) {
5071 }
5072 }
5073
5075
5076
5078 }
5079 }
5080
5083
5084 static const char *const CStmts[] = {
5085 "do", "else", "for", "goto", "if", "return", "switch", "while" };
5086 for (const auto *CS : CStmts)
5088
5092 }
5093
5094 if (S && S->getBreakParent())
5096
5097 if (S && S->getContinueParent())
5099
5104 }
5105 } else {
5109 }
5110
5111 if (S && S->isClassScope()) {
5119 }
5120 }
5121
5124
5127 }
5128 }
5129}
5130
5131std::unique_ptr Sema::makeTypoCorrectionConsumer(
5134 DeclContext *MemberContext, bool EnteringContext,
5136
5139 return nullptr;
5140
5141
5142
5143
5146 return nullptr;
5147
5148
5150 if (!Typo)
5151 return nullptr;
5152
5153
5154
5156 return nullptr;
5157
5158
5160 return nullptr;
5161
5162
5164 return nullptr;
5165
5166
5169 locs->second.count(TypoName.getLoc()))
5170 return nullptr;
5171
5172
5173
5174
5176 return nullptr;
5177
5178
5179
5180
5183 return nullptr;
5185
5186
5187
5188 if (ErrorRecovery && getLangOpts().Modules &&
5190
5193 }
5194
5195
5196
5197
5198
5199 std::unique_ptr ClonedCCC = CCC.clone();
5200 auto Consumer = std::make_unique(
5201 *this, TypoName, LookupKind, S, SS, std::move(ClonedCCC), MemberContext,
5202 EnteringContext);
5203
5204
5205 bool IsUnqualifiedLookup = false;
5206 DeclContext *QualifiedDC = MemberContext;
5207 if (MemberContext) {
5209
5210
5211 if (OPT) {
5212 for (auto *I : OPT->quals())
5214 }
5215 } else if (SS && SS->isSet()) {
5217 if (!QualifiedDC)
5218 return nullptr;
5219
5221 } else {
5222 IsUnqualifiedLookup = true;
5223 }
5224
5225
5226
5227 bool SearchNamespaces
5229 (IsUnqualifiedLookup || (SS && SS->isSet()));
5230
5231 if (IsUnqualifiedLookup || SearchNamespaces) {
5232
5233
5234
5236 Consumer->FoundName(I.getKey());
5237
5238
5239
5242 std::unique_ptr Iter(External->getIdentifiers());
5243 do {
5244 StringRef Name = Iter->Next();
5245 if (Name.empty())
5246 break;
5247
5249 } while (true);
5250 }
5251 }
5252
5254 *Consumer->getCorrectionValidator(),
5256
5257
5258
5259 if (SearchNamespaces) {
5260
5261 if (ExternalSource && !LoadedExternalKnownNamespaces) {
5263 LoadedExternalKnownNamespaces = true;
5264 ExternalSource->ReadKnownNamespaces(ExternalKnownNamespaces);
5265 for (auto *N : ExternalKnownNamespaces)
5266 KnownNamespaces[N] = true;
5267 }
5268
5269 Consumer->addNamespaces(KnownNamespaces);
5270 }
5271
5273}
5274
5281 bool EnteringContext,
5283 bool RecordFailure) {
5284
5285
5288 ExternalSource->CorrectTypo(TypoName, LookupKind, S, SS, CCC,
5289 MemberContext, EnteringContext, OPT))
5290 return Correction;
5291 }
5292
5293
5294
5295
5296
5298
5300 auto Consumer = makeTypoCorrectionConsumer(TypoName, LookupKind, S, SS, CCC,
5301 MemberContext, EnteringContext,
5303
5306
5307
5309 return FailedCorrection(Typo, TypoName.getLoc(), RecordFailure);
5310
5311
5312
5313 unsigned ED = Consumer->getBestEditDistance(true);
5314 unsigned TypoLen = Typo->getName().size();
5315 if (ED > 0 && TypoLen / ED < 3)
5316 return FailedCorrection(Typo, TypoName.getLoc(), RecordFailure);
5317
5320 if (!BestTC)
5321 return FailedCorrection(Typo, TypoName.getLoc(), RecordFailure);
5322
5324
5325 if (TypoLen >= 3 && ED > 0 && TypoLen / ED < 3) {
5326
5327
5328
5329 return FailedCorrection(Typo, TypoName.getLoc(), RecordFailure);
5330 }
5331
5332
5333 if (!SecondBestTC ||
5336
5337
5338
5339 if (ED == 0 && Result.isKeyword())
5340 return FailedCorrection(Typo, TypoName.getLoc(), RecordFailure);
5341
5345 return TC;
5346 } else if (SecondBestTC && ObjCMessageReceiver) {
5347
5348
5349
5352 BestTC = SecondBestTC;
5353 else if ((*Consumer)["super"].front().isKeyword())
5354 BestTC = (*Consumer)["super"].front();
5355 }
5356
5357
5360 return FailedCorrection(Typo, TypoName.getLoc(), RecordFailure);
5361
5363 return BestTC;
5364 }
5365
5366
5367
5368
5369 return FailedCorrection(Typo, TypoName.getLoc(), RecordFailure && !SecondBestTC);
5370}
5371
5376 DeclContext *MemberContext, bool EnteringContext,
5378 auto Consumer = makeTypoCorrectionConsumer(TypoName, LookupKind, S, SS, CCC,
5379 MemberContext, EnteringContext,
5381
5382
5386 TypoName, LookupKind, S, SS, *Consumer->getCorrectionValidator(),
5387 MemberContext, EnteringContext, OPT);
5388 if (ExternalTypo)
5389 Consumer->addCorrection(ExternalTypo);
5390 }
5391
5393 return nullptr;
5394
5395
5396
5397 unsigned ED = Consumer->getBestEditDistance(true);
5399 if (!ExternalTypo && ED > 0 && Typo->getName().size() / ED < 3)
5400 return nullptr;
5402 return createDelayedTypo(std::move(Consumer), std::move(TDG), std::move(TRC),
5404}
5405
5407 if (!CDecl) return;
5408
5410 CorrectionDecls.clear();
5411
5412 CorrectionDecls.push_back(CDecl);
5413
5414 if (!CorrectionName)
5416}
5417
5419 if (CorrectionNameSpec) {
5420 std::string tmpBuffer;
5421 llvm::raw_string_ostream PrefixOStream(tmpBuffer);
5423 PrefixOStream << CorrectionName;
5424 return PrefixOStream.str();
5425 }
5426
5428}
5429
5433 return true;
5434
5438
5439 bool HasNonType = false;
5440 bool HasStaticMethod = false;
5441 bool HasNonStaticMethod = false;
5442 for (Decl *D : candidate) {
5444 D = FTD->getTemplatedDecl();
5445 if (CXXMethodDecl *Method = dyn_cast(D)) {
5446 if (Method->isStatic())
5447 HasStaticMethod = true;
5448 else
5449 HasNonStaticMethod = true;
5450 }
5451 if (!isa(D))
5452 HasNonType = true;
5453 }
5454
5457 return false;
5458
5460}
5461
5463 bool HasExplicitTemplateArgs,
5465 : NumArgs(NumArgs), HasExplicitTemplateArgs(HasExplicitTemplateArgs),
5466 CurContext(SemaRef.CurContext), MemberFn(ME) {
5469 !HasExplicitTemplateArgs && NumArgs == 1;
5472}
5473
5477
5478 for (auto *C : candidate) {
5480 NamedDecl *ND = C->getUnderlyingDecl();
5482 FD = FTD->getTemplatedDecl();
5483 if (!HasExplicitTemplateArgs && !FD) {
5484 if (!(FD = dyn_cast(ND)) && isa(ND)) {
5485
5486
5487
5488 QualType ValType = cast(ND)->getType();
5489 if (ValType.isNull())
5490 continue;
5494 if (FPT->getNumParams() == NumArgs)
5495 return true;
5496 }
5497 }
5498
5499
5501 : isa(ND)) &&
5503
5504 return NumArgs <= 1 || HasExplicitTemplateArgs || isa(ND);
5505
5506
5507
5508 if (!FD || !(FD->getNumParams() >= NumArgs &&
5510 continue;
5511
5512
5513
5514
5515
5516 if (const auto *MD = dyn_cast(FD)) {
5517 if (MemberFn || !MD->isStatic()) {
5518 const auto *CurMD =
5519 MemberFn
5520 ? dyn_cast_if_present(MemberFn->getMemberDecl())
5521 : dyn_cast_if_present(CurContext);
5523 CurMD ? CurMD->getParent()->getCanonicalDecl() : nullptr;
5525 if (!CurRD || (CurRD != RD && !CurRD->isDerivedFrom(RD)))
5526 continue;
5527 }
5528 }
5529 return true;
5530 }
5531 return false;
5532}
5533
5536 bool ErrorRecovery) {
5537 diagnoseTypo(Correction, TypoDiag, PDiag(diag::note_previous_decl),
5538 ErrorRecovery);
5539}
5540
5541
5542
5544 if (const auto *VD = dyn_cast(D))
5545 return VD->getDefinition();
5546 if (const auto *FD = dyn_cast(D))
5547 return FD->getDefinition();
5548 if (const auto *TD = dyn_cast(D))
5549 return TD->getDefinition();
5550 if (const auto *ID = dyn_cast(D))
5551 return ID->getDefinition();
5552 if (const auto *PD = dyn_cast(D))
5553 return PD->getDefinition();
5554 if (const auto *TD = dyn_cast(D))
5555 if (const NamedDecl *TTD = TD->getTemplatedDecl())
5557 return nullptr;
5558}
5559
5562
5563
5565 if (!Def)
5567
5569 assert(Owner && "definition of hidden declaration is not in a module");
5570
5572 OwningModules.push_back(Owner);
5574 OwningModules.insert(OwningModules.end(), Merged.begin(), Merged.end());
5575
5577 Recover);
5578}
5579
5580
5581
5583 llvm::StringRef IncludingFile) {
5584 bool IsAngled = false;
5586 E, IncludingFile, &IsAngled);
5587 return (IsAngled ? '<' : '"') + Path + (IsAngled ? '>' : '"');
5588}
5589
5594 assert(!Modules.empty());
5595
5596
5597
5598 if (isa(Decl))
5599 return;
5600
5601 auto NotePrevious = [&] {
5602
5603
5604
5605 Diag(DeclLoc, diag::note_unreachable_entity) << (int)MIK;
5606 };
5607
5608
5610 llvm::SmallDenseSet<Module*, 8> UniqueModuleSet;
5611 for (auto *M : Modules) {
5613 continue;
5614 if (UniqueModuleSet.insert(M).second)
5615 UniqueModules.push_back(M);
5616 }
5617
5618
5619 std::string HeaderName;
5624 HeaderName =
5626 }
5627
5628
5629
5630 if (!HeaderName.empty() || UniqueModules.empty()) {
5631
5632
5633 Diag(UseLoc, diag::err_module_unimported_use_header)
5634 << (int)MIK << Decl << !HeaderName.empty() << HeaderName;
5635
5636 NotePrevious();
5637 if (Recover)
5639 return;
5640 }
5641
5642 Modules = UniqueModules;
5643
5644 auto GetModuleNameForDiagnostic = [this](const Module *M) -> std::string {
5647
5650
5651
5652
5653
5656 else
5658 };
5659
5660 if (Modules.size() > 1) {
5661 std::string ModuleList;
5662 unsigned N = 0;
5663 for (const auto *M : Modules) {
5664 ModuleList += "\n ";
5665 if (++N == 5 && N != Modules.size()) {
5666 ModuleList += "[...]";
5667 break;
5668 }
5669 ModuleList += GetModuleNameForDiagnostic(M);
5670 }
5671
5672 Diag(UseLoc, diag::err_module_unimported_use_multiple)
5673 << (int)MIK << Decl << ModuleList;
5674 } else {
5675
5676 Diag(UseLoc, diag::err_module_unimported_use)
5677 << (int)MIK << Decl << GetModuleNameForDiagnostic(Modules[0]);
5678 }
5679
5680 NotePrevious();
5681
5682
5683 if (Recover)
5685}
5686
5690 bool ErrorRecovery) {
5695
5696
5699 assert(Decl && "import required but no declaration to import");
5700
5703 return;
5704 }
5705
5707 << CorrectedQuotedStr << (ErrorRecovery ? FixTypo : FixItHint());
5708
5711
5712
5713
5714 if (const auto *FD = dyn_cast_if_present(ChosenDecl);
5715 FD && FD->getBuiltinID() &&
5716 PrevNote.getDiagID() == diag::note_previous_decl &&
5718 ChosenDecl = nullptr;
5719 }
5720
5721 if (PrevNote.getDiagID() && ChosenDecl)
5722 Diag(ChosenDecl->getLocation(), PrevNote)
5723 << CorrectedQuotedStr << (ErrorRecovery ? FixItHint() : FixTypo);
5724
5725
5728}
5729
5730TypoExpr *Sema::createDelayedTypo(std::unique_ptr TCC,
5731 TypoDiagnosticGenerator TDG,
5732 TypoRecoveryCallback TRC,
5734 assert(TCC && "createDelayedTypo requires a valid TypoCorrectionConsumer");
5736 auto &State = DelayedTypos[TE];
5737 State.Consumer = std::move(TCC);
5738 State.DiagHandler = std::move(TDG);
5739 State.RecoveryHandler = std::move(TRC);
5740 if (TE)
5742 return TE;
5743}
5744
5746 auto Entry = DelayedTypos.find(TE);
5747 assert(Entry != DelayedTypos.end() &&
5748 "Failed to get the state for a TypoExpr!");
5749 return Entry->second;
5750}
5751
5753 DelayedTypos.erase(TE);
5754}
5755
5759 RedeclarationKind::NotForRedeclaration);
5764}
5765
5768}
5769
5771
5772
5773
5774
5775 if (cast(CurContext)->getOwningModuleForLinkage())
5776 return RedeclarationKind::ForVisibleRedeclaration;
5777 return RedeclarationKind::ForExternalRedeclaration;
5778}
Defines the clang::ASTContext interface.
Defines enum values for all the target-independent builtin functions.
enum clang::sema::@1727::IndirectLocalPathEntry::EntryKind Kind
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
Defines the C++ template declaration subclasses.
Defines the clang::Expr interface and subclasses for C++ expressions.
llvm::DenseSet< const void * > Visited
Defines the clang::LangOptions interface.
llvm::MachO::Record Record
Defines the clang::Preprocessor interface.
RedeclarationKind
Specifies whether (or how) name lookup is being performed for a redeclaration (vs.
static Module * getDefiningModule(Sema &S, Decl *Entity)
Find the module in which the given declaration was defined.
static bool isPreferredLookupResult(Sema &S, Sema::LookupNameKind Kind, const NamedDecl *D, const NamedDecl *Existing)
Determine whether D is a better lookup result than Existing, given that they declare the same entity.
static bool CanDeclareSpecialMemberFunction(const CXXRecordDecl *Class)
Determine whether we can declare a special member function within the class at this point.
static bool canHideTag(const NamedDecl *D)
Determine whether D can hide a tag declaration.
static std::string getHeaderNameForHeader(Preprocessor &PP, FileEntryRef E, llvm::StringRef IncludingFile)
Get a "quoted.h" or <angled.h> include path to use in a diagnostic suggesting the addition of a #incl...
static void addAssociatedClassesAndNamespaces(AssociatedLookup &Result, QualType T)
static QualType getOpenCLTypedefType(Sema &S, llvm::StringRef Name)
Lookup an OpenCL typedef type.
static DeclContext * findOuterContext(Scope *S)
Find the outer declaration context from this scope.
static void LookupPotentialTypoResult(Sema &SemaRef, LookupResult &Res, IdentifierInfo *Name, Scope *S, CXXScopeSpec *SS, DeclContext *MemberContext, bool EnteringContext, bool isObjCIvarLookup, bool FindHidden)
Perform name lookup for a possible result for typo correction.
static void checkCorrectionVisibility(Sema &SemaRef, TypoCorrection &TC)
Check whether the declarations found for a typo correction are visible.
static bool isNamespaceOrTranslationUnitScope(Scope *S)
static bool LookupQualifiedNameInUsingDirectives(Sema &S, LookupResult &R, DeclContext *StartDC)
Perform qualified name lookup in the namespaces nominated by using directives by the given context.
static bool LookupDirect(Sema &S, LookupResult &R, const DeclContext *DC)
static QualType getOpenCLEnumType(Sema &S, llvm::StringRef Name)
Lookup an OpenCL enum type.
static void CollectEnclosingNamespace(Sema::AssociatedNamespaceSet &Namespaces, DeclContext *Ctx)
static bool hasAcceptableDefaultArgument(Sema &S, const ParmDecl *D, llvm::SmallVectorImpl< Module * > *Modules, Sema::AcceptableKind Kind)
static bool isImplicitlyDeclaredMemberFunctionName(DeclarationName Name)
Determine whether this is the name of an implicitly-declared special member function.
static void DeclareImplicitMemberFunctionsWithName(Sema &S, DeclarationName Name, SourceLocation Loc, const DeclContext *DC)
If there are any implicit member functions with the given name that need to be declared in the given ...
static void AddKeywordsToConsumer(Sema &SemaRef, TypoCorrectionConsumer &Consumer, Scope *S, CorrectionCandidateCallback &CCC, bool AfterNestedNameSpecifier)
Add keywords to the consumer as possible typo corrections.
static void GetQualTypesForOpenCLBuiltin(Sema &S, const OpenCLBuiltinStruct &OpenCLBuiltin, unsigned &GenTypeMaxCnt, SmallVector< QualType, 1 > &RetTypes, SmallVector< SmallVector< QualType, 1 >, 5 > &ArgTypes)
Get the QualType instances of the return type and arguments for an OpenCL builtin function signature.
static QualType diagOpenCLBuiltinTypeError(Sema &S, llvm::StringRef TypeClass, llvm::StringRef Name)
Diagnose a missing builtin type.
static bool hasAcceptableMemberSpecialization(Sema &S, const NamedDecl *D, llvm::SmallVectorImpl< Module * > *Modules, Sema::AcceptableKind Kind)
static bool hasAcceptableDeclarationImpl(Sema &S, const NamedDecl *D, llvm::SmallVectorImpl< Module * > *Modules, Filter F, Sema::AcceptableKind Kind)
static bool isCandidateViable(CorrectionCandidateCallback &CCC, TypoCorrection &Candidate)
static const DeclContext * getContextForScopeMatching(const Decl *D)
Get a representative context for a declaration such that two declarations will have the same context ...
static NamedDecl * findAcceptableDecl(Sema &SemaRef, NamedDecl *D, unsigned IDNS)
Retrieve the visible declaration corresponding to D, if any.
static void GetOpenCLBuiltinFctOverloads(ASTContext &Context, unsigned GenTypeMaxCnt, std::vector< QualType > &FunctionList, SmallVector< QualType, 1 > &RetTypes, SmallVector< SmallVector< QualType, 1 >, 5 > &ArgTypes)
Create a list of the candidate function overloads for an OpenCL builtin function.
static const unsigned MaxTypoDistanceResultSets
static const NamedDecl * getDefinitionToImport(const NamedDecl *D)
Find which declaration we should import to provide the definition of the given declaration.
static void getNestedNameSpecifierIdentifiers(NestedNameSpecifier *NNS, SmallVectorImpl< const IdentifierInfo * > &Identifiers)
static bool hasAcceptableExplicitSpecialization(Sema &S, const NamedDecl *D, llvm::SmallVectorImpl< Module * > *Modules, Sema::AcceptableKind Kind)
static unsigned getIDNS(Sema::LookupNameKind NameKind, bool CPlusPlus, bool Redeclaration)
static void InsertOCLBuiltinDeclarationsFromTable(Sema &S, LookupResult &LR, IdentifierInfo *II, const unsigned FctIndex, const unsigned Len)
When trying to resolve a function name, if isOpenCLBuiltin() returns a non-null <Index,...
static void LookupPredefedObjCSuperType(Sema &Sema, Scope *S)
Looks up the declaration of "struct objc_super" and saves it for later use in building builtin declar...
static bool CppNamespaceLookup(Sema &S, LookupResult &R, ASTContext &Context, const DeclContext *NS, UnqualUsingDirectiveSet &UDirs)
This file declares semantic analysis functions specific to RISC-V.
const NestedNameSpecifier * Specifier
__DEVICE__ long long abs(long long __n)
A class for storing results from argument-dependent lookup.
void insert(NamedDecl *D)
Adds a new ADL candidate to this map.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
TranslationUnitDecl * getTranslationUnitDecl() const
const SmallVectorImpl< Type * > & getTypes() const
QualType getTagDeclType(const TagDecl *Decl) const
Return the unique reference to the type for the specified TagDecl (struct/union/class/enum) decl.
DeclarationNameTable DeclarationNames
QualType getRecordType(const RecordDecl *Decl) const
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
CallingConv getDefaultCallingConvention(bool IsVariadic, bool IsCXXMethod, bool IsBuiltin=false) const
Retrieves the default calling convention for the current target.
QualType getEnumType(const EnumDecl *Decl) const
QualType getTypeDeclType(const TypeDecl *Decl, const TypeDecl *PrevDecl=nullptr) const
Return the unique reference to the type for the specified type declaration.
Builtin::Context & BuiltinInfo
const LangOptions & getLangOpts() const
void setObjCSuperType(QualType ST)
const clang::PrintingPolicy & getPrintingPolicy() const
ArrayRef< Module * > getModulesWithMergedDefinition(const NamedDecl *Def)
Get the additional modules in which the definition Def has been merged.
bool hasSameUnqualifiedType(QualType T1, QualType T2) const
Determine whether the given types are equivalent after cvr-qualifiers have been removed.
QualType getFunctionType(QualType ResultTy, ArrayRef< QualType > Args, const FunctionProtoType::ExtProtoInfo &EPI) const
Return a normal function type with a typed argument list.
void mergeDefinitionIntoModule(NamedDecl *ND, Module *M, bool NotifyListeners=true)
Note that the definition ND has been merged into module M, and should be visible whenever M is visibl...
QualType getTypedefType(const TypedefNameDecl *Decl, QualType Underlying=QualType()) const
Return the unique reference to the type for the specified typedef-name decl.
bool isInSameModule(const Module *M1, const Module *M2)
If the two module M1 and M2 are in the same module.
bool isPredefinedLibFunction(unsigned ID) const
Determines whether this builtin is a predefined libc/libm function, such as "malloc",...
Represents a path from a specific derived class (which is not represented as part of the path) to a p...
BasePaths - Represents the set of paths from a derived class to one of its (direct or indirect) bases...
std::list< CXXBasePath >::iterator paths_iterator
std::list< CXXBasePath >::const_iterator const_paths_iterator
void swap(CXXBasePaths &Other)
Swap this data structure's contents with another CXXBasePaths object.
Represents a base class of a C++ class.
QualType getType() const
Retrieves the type of the base class.
Represents a C++ constructor within a class.
Represents a C++ destructor within a class.
Represents a static or instance method of a struct/union/class.
Represents a C++ struct/union/class.
base_class_iterator bases_end()
bool hasAnyDependentBases() const
Determine whether this class has any dependent base classes which are not the current instantiation.
bool needsImplicitDefaultConstructor() const
Determine if we need to declare a default constructor for this class.
bool needsImplicitMoveConstructor() const
Determine whether this class should get an implicit move constructor or if any existing special membe...
CXXRecordDecl * getDefinition() const
static AccessSpecifier MergeAccess(AccessSpecifier PathAccess, AccessSpecifier DeclAccess)
Calculates the access of a decl that is reached along a path.
const CXXRecordDecl * getTemplateInstantiationPattern() const
Retrieve the record declaration from which this record could be instantiated.
bool lookupInBases(BaseMatchesCallback BaseMatches, CXXBasePaths &Paths, bool LookupInDependent=false) const
Look for entities within the base classes of this C++ class, transitively searching all base class su...
base_class_iterator bases_begin()
bool needsImplicitCopyConstructor() const
Determine whether this class needs an implicit copy constructor to be lazily declared.
bool needsImplicitDestructor() const
Determine whether this class needs an implicit destructor to be lazily declared.
CXXDestructorDecl * getDestructor() const
Returns the destructor decl for this class.
bool needsImplicitMoveAssignment() const
Determine whether this class should get an implicit move assignment operator or if any existing speci...
bool needsImplicitCopyAssignment() const
Determine whether this class needs an implicit copy assignment operator to be lazily declared.
bool isDerivedFrom(const CXXRecordDecl *Base) const
Determine whether this class is derived from the class Base.
Represents a C++ nested-name-specifier or a global scope specifier.
bool isNotEmpty() const
A scope specifier is present, but may be valid or invalid.
SourceRange getRange() const
bool isSet() const
Deprecated.
NestedNameSpecifier * getScopeRep() const
Retrieve the representation of the nested-name-specifier.
bool isInvalid() const
An error occurred during parsing of the scope specifier.
bool isEmpty() const
No scope specifier.
Declaration of a class template.
Represents a class template specialization, which refers to a class template with a given set of temp...
Base class for callback objects used by Sema::CorrectTypo to check the validity of a potential typo c...
bool WantExpressionKeywords
virtual unsigned RankCandidate(const TypoCorrection &candidate)
Method used by Sema::CorrectTypo to assign an "edit distance" rank to a candidate (where a lower valu...
virtual bool ValidateCandidate(const TypoCorrection &candidate)
Simple predicate used by the default RankCandidate to determine whether to return an edit distance of...
bool WantFunctionLikeCasts
bool WantRemainingKeywords
virtual std::unique_ptr< CorrectionCandidateCallback > clone()=0
Clone this CorrectionCandidateCallback.
A POD class for pairing a NamedDecl* with an access specifier.
static DeclAccessPair make(NamedDecl *D, AccessSpecifier AS)
NamedDecl * getDecl() const
The results of name lookup within a DeclContext.
DeclListNode::iterator iterator
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.
udir_range using_directives() const
Returns iterator range [First, Last) of UsingDirectiveDecls stored within this context.
bool Equals(const DeclContext *DC) const
Determine whether this declaration context is equivalent to the declaration context DC.
bool isFileContext() const
bool isTransparentContext() const
isTransparentContext - Determines whether this context is a "transparent" context,...
ASTContext & getParentASTContext() 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
DeclContext * getRedeclContext()
getRedeclContext - Retrieve the context in which an entity conflicts with other entities of the same ...
bool shouldUseQualifiedLookup() const
void setUseQualifiedLookup(bool use=true) const
DeclContext * getPrimaryContext()
getPrimaryContext - There may be many different declarations of the same entity (including forward de...
bool isInlineNamespace() const
bool isFunctionOrMethod() const
DeclContext * getLookupParent()
Find the parent context of this context that will be used for unqualified name lookup.
bool Encloses(const DeclContext *DC) const
Determine whether this declaration context encloses the declaration context DC.
Decl - This represents one declaration (or definition), e.g.
Decl * getPreviousDecl()
Retrieve the previous declaration that declares the same entity as this declaration,...
Decl * getMostRecentDecl()
Retrieve the most recent declaration that declares the same entity as this declaration (which may be ...
bool isModulePrivate() const
Whether this declaration was marked as being private to the module in which it was defined.
bool isTemplateDecl() const
returns true if this declaration is a template
FriendObjectKind getFriendObjectKind() const
Determines whether this declaration is the object of a friend declaration and, if so,...
bool isFunctionOrFunctionTemplate() const
Whether this declaration is a function or function template.
bool isUnconditionallyVisible() const
Determine whether this declaration is definitely visible to name lookup, independent of whether the o...
bool isInIdentifierNamespace(unsigned NS) const
bool isInvisibleOutsideTheOwningModule() const
bool isInExportDeclContext() const
Whether this declaration was exported in a lexical context.
bool isInAnotherModuleUnit() const
Whether this declaration comes from another module unit.
Module * getOwningModule() const
Get the module that owns this declaration (for visibility purposes).
FunctionDecl * getAsFunction() LLVM_READONLY
Returns the function itself, or the templated function if this is a function template.
bool isTemplateParameter() const
isTemplateParameter - Determines whether this declaration is a template parameter.
bool isInvalidDecl() const
unsigned getIdentifierNamespace() const
SourceLocation getLocation() const
@ IDNS_NonMemberOperator
This declaration is a C++ operator declared in a non-class context.
@ IDNS_TagFriend
This declaration is a friend class.
@ IDNS_Ordinary
Ordinary names.
@ IDNS_Type
Types, declared with 'struct foo', typedefs, etc.
@ IDNS_OMPReduction
This declaration is an OpenMP user defined reduction construction.
@ IDNS_Label
Labels, declared with 'x:' and referenced with 'goto x'.
@ IDNS_Member
Members, declared with object declarations within tag definitions.
@ IDNS_OMPMapper
This declaration is an OpenMP user defined mapper.
@ IDNS_ObjCProtocol
Objective C @protocol.
@ IDNS_Namespace
Namespaces, declared with 'namespace foo {}'.
@ IDNS_OrdinaryFriend
This declaration is a friend function.
@ IDNS_Using
This declaration is a using declaration.
@ IDNS_LocalExtern
This declaration is a function-local extern declaration of a variable or function.
@ IDNS_Tag
Tags, declared with 'struct foo;' and referenced with 'struct foo'.
bool isDeprecated(std::string *Message=nullptr) const
Determine whether this declaration is marked 'deprecated'.
bool isTemplateParameterPack() const
isTemplateParameter - Determines whether this declaration is a template parameter pack.
void setImplicit(bool I=true)
redecl_range redecls() const
Returns an iterator range for all the redeclarations of the same decl.
bool isDefinedOutsideFunctionOrMethod() const
isDefinedOutsideFunctionOrMethod - This predicate returns true if this scoped decl is defined outside...
DeclContext * getDeclContext()
TranslationUnitDecl * getTranslationUnitDecl()
bool hasTagIdentifierNamespace() const
DeclContext * getLexicalDeclContext()
getLexicalDeclContext - The declaration context where this Decl was lexically declared (LexicalDC).
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
const LangOptions & getLangOpts() const LLVM_READONLY
Helper to get the language options from the ASTContext.
void setVisibleDespiteOwningModule()
Set that this declaration is globally visible, even if it came from a module that is not visible.
The name of a declaration.
IdentifierInfo * getAsIdentifierInfo() const
Retrieve the IdentifierInfo * stored in this declaration name, or null if this declaration name isn't...
TemplateDecl * getCXXDeductionGuideTemplate() const
If this name is the name of a C++ deduction guide, return the template associated with that name.
std::string getAsString() const
Retrieve the human-readable string for this name.
OverloadedOperatorKind getCXXOverloadedOperator() const
If this name is the name of an overloadable operator in C++ (e.g., operator+), retrieve the kind of o...
@ CXXConversionFunctionName
QualType getCXXNameType() const
If this name is one of the C++ names (of a constructor, destructor, or conversion function),...
NameKind getNameKind() const
Determine what kind of name this is.
DiagnosticOptions & getDiagnosticOptions() const
Retrieve the diagnostic options.
bool hasFatalErrorOccurred() const
The return type of classify().
This represents one expression.
Classification Classify(ASTContext &Ctx) const
Classify - Classify this expression according to the C++11 expression taxonomy.
bool isFPConstrained() const
A reference to a FileEntry that includes the name of the file as it was accessed by the FileManager's...
Cached information about one file (either on disk or in the virtual file system).
Annotates a diagnostic with some code that should be inserted, removed, or replaced to fix the proble...
static FixItHint CreateReplacement(CharSourceRange RemoveRange, StringRef Code)
Create a code modification hint that replaces the given source range with the given code string.
bool ValidateCandidate(const TypoCorrection &candidate) override
Simple predicate used by the default RankCandidate to determine whether to return an edit distance of...
FunctionCallFilterCCC(Sema &SemaRef, unsigned NumArgs, bool HasExplicitTemplateArgs, MemberExpr *ME=nullptr)
Represents a function declaration or definition.
unsigned getMinRequiredArguments() const
Returns the minimum number of arguments needed to call this function.
FunctionDecl * getTemplateInstantiationPattern(bool ForDefinition=true) const
Retrieve the function declaration from which this function could be instantiated, if it is an instant...
bool isDeleted() const
Whether this function has been deleted.
static FunctionDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation NLoc, DeclarationName N, QualType T, TypeSourceInfo *TInfo, StorageClass SC, bool UsesFPIntrin=false, bool isInlineSpecified=false, bool hasWrittenPrototype=true, ConstexprSpecKind ConstexprKind=ConstexprSpecKind::Unspecified, Expr *TrailingRequiresClause=nullptr)
unsigned getNumParams() const
Return the number of parameters this function must have based on its FunctionType.
Represents a prototype with parameter type info, e.g.
ExtProtoInfo getExtProtoInfo() const
ArrayRef< QualType > param_types() const
Declaration of a template function.
FunctionDecl * getTemplatedDecl() const
Get the underlying function declaration of the template.
ExtInfo withCallingConv(CallingConv cc) const
FunctionType - C99 6.7.5.3 - Function Declarators.
QualType getReturnType() const
Provides lookups to, and iteration over, IdentiferInfo objects.
One of these records is kept for each identifier that is lexed.
unsigned getBuiltinID() const
Return a value indicating whether this is a builtin function.
StringRef getName() const
Return the actual identifier string.
iterator - Iterate over the decls of a specified declaration name.
iterator begin(DeclarationName Name)
Returns an iterator over decls with the name 'Name'.
iterator end()
Returns the end iterator.
bool isDeclInScope(Decl *D, DeclContext *Ctx, Scope *S=nullptr, bool AllowInlineNamespace=false) const
isDeclInScope - If 'Ctx' is a function/method, isDeclInScope returns true if 'D' is in Scope 'S',...
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
IdentifierInfoLookup * getExternalIdentifierLookup() const
Retrieve the external identifier lookup object, if any.
Represents the declaration of a label.
static LabelDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation IdentL, IdentifierInfo *II)
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
A class for iterating through a result set and possibly filtering out results.
void restart()
Restart the iteration.
void erase()
Erase the last element returned from this iterator.
Represents the results of name lookup.
void addAllDecls(const LookupResult &Other)
Add all the declarations from another set of lookup results.
@ FoundOverloaded
Name lookup found a set of overloaded functions that met the criteria.
@ FoundUnresolvedValue
Name lookup found an unresolvable value declaration and cannot yet complete.
@ Ambiguous
Name lookup results in an ambiguity; use getAmbiguityKind to figure out what kind of ambiguity we hav...
@ NotFound
No entity found met the criteria.
@ NotFoundInCurrentInstantiation
No entity found met the criteria within the current instantiation,, but there were dependent base cla...
@ Found
Name lookup found a single declaration that met the criteria.
void setShadowed()
Note that we found and ignored a declaration while performing lookup.
static bool isAvailableForLookup(Sema &SemaRef, NamedDecl *ND)
Determine whether this lookup is permitted to see the declaration.
LLVM_ATTRIBUTE_REINITIALIZES void clear()
Clears out any current state.
void setFindLocalExtern(bool FindLocalExtern)
void setAllowHidden(bool AH)
Specify whether hidden declarations are visible, e.g., for recovery reasons.
DeclClass * getAsSingle() const
void setContextRange(SourceRange SR)
Sets a 'context' source range.
static bool isAcceptable(Sema &SemaRef, NamedDecl *D, Sema::AcceptableKind Kind)
void setAmbiguousQualifiedTagHiding()
Make these results show that the name was found in different contexts and a tag decl was hidden by an...
void addDecl(NamedDecl *D)
Add a declaration to these results with its natural access.
bool isTemplateNameLookup() const
void setAmbiguousBaseSubobjects(CXXBasePaths &P)
Make these results show that the name was found in distinct base classes of the same type.
bool isSingleTagDecl() const
Asks if the result is a single tag decl.
void setLookupName(DeclarationName Name)
Sets the name to look up.
bool empty() const
Return true if no decls were found.
void resolveKind()
Resolves the result kind of the lookup, possibly hiding decls.
SourceLocation getNameLoc() const
Gets the location of the identifier.
void setAmbiguousBaseSubobjectTypes(CXXBasePaths &P)
Make these results show that the name was found in base classes of different types.
Filter makeFilter()
Create a filter for this result set.
NamedDecl * getFoundDecl() const
Fetch the unique decl found by this lookup.
void setHideTags(bool Hide)
Sets whether tag declarations should be hidden by non-tag declarations during resolution.
NamedDecl * getAcceptableDecl(NamedDecl *D) const
Retrieve the accepted (re)declaration of the given declaration, if there is one.
bool isSingleResult() const
Determines if this names a single result which is not an unresolved value using decl.
unsigned getIdentifierNamespace() const
Returns the identifier namespace mask for this lookup.
Sema::LookupNameKind getLookupKind() const
Gets the kind of lookup to perform.
Sema & getSema() const
Get the Sema object that this lookup result is searching with.
void setNamingClass(CXXRecordDecl *Record)
Sets the 'naming class' for this lookup.
LookupResultKind getResultKind() const
void print(raw_ostream &)
static bool isReachable(Sema &SemaRef, NamedDecl *D)
void suppressDiagnostics()
Suppress the diagnostics that would normally fire because of this lookup.
bool isForRedeclaration() const
True if this lookup is just looking for an existing declaration.
DeclarationName getLookupName() const
Gets the name to look up.
@ AmbiguousTagHiding
Name lookup results in an ambiguity because an entity with a tag name was hidden by an entity with an...
@ AmbiguousBaseSubobjectTypes
Name lookup results in an ambiguity because multiple entities that meet the lookup criteria were foun...
@ AmbiguousReferenceToPlaceholderVariable
Name lookup results in an ambiguity because multiple placeholder variables were found in the same sco...
@ AmbiguousReference
Name lookup results in an ambiguity because multiple definitions of entity that meet the lookup crite...
@ AmbiguousBaseSubobjects
Name lookup results in an ambiguity because multiple nonstatic entities that meet the lookup criteria...
void setNotFoundInCurrentInstantiation()
Note that while no result was found in the current instantiation, there were dependent base classes t...
static bool isVisible(Sema &SemaRef, NamedDecl *D)
Determine whether the given declaration is visible to the program.
const DeclarationNameInfo & getLookupNameInfo() const
Gets the name info to look up.
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
ValueDecl * getMemberDecl() const
Retrieve the member declaration to which this expression refers.
A pointer to member type per C++ 8.3.3 - Pointers to members.
QualType getPointeeType() const
const Type * getClass() const
virtual bool lookupMissingImports(StringRef Name, SourceLocation TriggerLoc)=0
Check global module index for missing imports.
Describes a module or submodule.
StringRef getTopLevelModuleName() const
Retrieve the name of the top-level module.
bool isPrivateModule() const
bool isModuleVisible(const Module *M) const
Determine whether the specified module would be visible to a lookup at the end of this module.
bool isModuleInterfaceUnit() const
bool isModuleMapModule() const
bool isHeaderLikeModule() const
Is this module have similar semantics as headers.
StringRef getPrimaryModuleInterfaceName() const
Get the primary module interface name from a partition.
bool isExplicitGlobalModule() const
bool isGlobalModule() const
Does this Module scope describe a fragment of the global module within some C++ module.
bool isImplicitGlobalModule() const
std::string getFullModuleName(bool AllowStringLiterals=false) const
Retrieve the full name of this module, including the path from its top-level module.
bool isNamedModule() const
Does this Module is a named module of a standard named module?
Module * getTopLevelModule()
Retrieve the top-level module for this (sub)module, which may be this module.
This represents a decl that may have a name.
NamedDecl * getUnderlyingDecl()
Looks through UsingDecls and ObjCCompatibleAliasDecls for the underlying named decl.
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
bool isExternallyDeclarable() const
Determine whether this declaration can be redeclared in a different translation unit.
Represent a C++ namespace.
bool isAnonymousNamespace() const
Returns true if this is an anonymous namespace declaration.
Represents a C++ nested name specifier, such as "\::std::vector::".
SpecifierKind getKind() const
Determine what kind of nested name specifier is stored.
static NestedNameSpecifier * Create(const ASTContext &Context, NestedNameSpecifier *Prefix, const IdentifierInfo *II)
Builds a specifier combining a prefix and an identifier.
NamespaceAliasDecl * getAsNamespaceAlias() const
Retrieve the namespace alias stored in this nested name specifier.
IdentifierInfo * getAsIdentifier() const
Retrieve the identifier stored in this nested name specifier.
static NestedNameSpecifier * GlobalSpecifier(const ASTContext &Context)
Returns the nested name specifier representing the global scope.
NestedNameSpecifier * getPrefix() const
Return the prefix of this nested name specifier.
@ NamespaceAlias
A namespace alias, stored as a NamespaceAliasDecl*.
@ TypeSpec
A type, stored as a Type*.
@ TypeSpecWithTemplate
A type that was preceded by the 'template' keyword, stored as a Type*.
@ Super
Microsoft's '__super' specifier, stored as a CXXRecordDecl* of the class it appeared in.
@ Identifier
An identifier, stored as an IdentifierInfo*.
@ Global
The global specifier '::'. There is no stored value.
@ Namespace
A namespace, stored as a NamespaceDecl*.
NamespaceDecl * getAsNamespace() const
Retrieve the namespace stored in this nested name specifier.
void print(raw_ostream &OS, const PrintingPolicy &Policy, bool ResolveTemplateArguments=false) const
Print this nested name specifier to the given output stream.
const Type * getAsType() const
Retrieve the type stored in this nested name specifier.
ObjCCategoryDecl - Represents a category declaration.
Represents an ObjC class declaration.
ObjCIvarDecl - Represents an ObjC instance variable.
ObjCMethodDecl - Represents an instance or class method declaration.
Represents a pointer to an Objective C object.
Represents one property declaration in an Objective-C interface.
Represents an Objective-C protocol declaration.
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class.
OverloadCandidateSet - A set of overload candidates, used in C++ overload resolution (C++ 13....
@ CSK_Normal
Normal lookup.
SmallVectorImpl< OverloadCandidate >::iterator iterator
OverloadingResult BestViableFunction(Sema &S, SourceLocation Loc, OverloadCandidateSet::iterator &Best)
Find the best viable function on this overload set, if it exists.
A reference to an overloaded function set, either an UnresolvedLookupExpr or an UnresolvedMemberExpr.
static FindResult find(Expr *E)
Finds the overloaded expression in the given expression E of OverloadTy.
llvm::iterator_range< decls_iterator > decls() const
Represents a parameter to a function.
void setScopeInfo(unsigned scopeDepth, unsigned parameterIndex)
static ParmVarDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, const IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, StorageClass S, Expr *DefArg)
unsigned getDiagID() const
PointerType - C99 6.7.5.1 - Pointer Declarators.
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
bool isMacroDefined(StringRef Id)
HeaderSearch & getHeaderSearchInfo() const
OptionalFileEntryRef getHeaderToIncludeForDiagnostics(SourceLocation IncLoc, SourceLocation MLoc)
We want to produce a diagnostic at location IncLoc concerning an unreachable effect at location MLoc ...
A (possibly-)qualified type.
const IdentifierInfo * getBaseTypeIdentifier() const
Retrieves a pointer to the name of the base type.
void addConst()
Add the const type qualifier to this QualType.
bool isNull() const
Return true if this QualType doesn't point to a type yet.
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
void addVolatile()
Add the volatile type qualifier to this QualType.
Represents a struct/union/class.
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
RecordDecl * getDecl() const
Scope - A scope is a transient data structure that is used while parsing the program.
const Scope * getFnParent() const
getFnParent - Return the closest scope that is a function body.
bool isDeclScope(const Decl *D) const
isDeclScope - Return true if this is the scope that the specified decl is declared in.
DeclContext * getEntity() const
Get the entity corresponding to this scope.
const Scope * getParent() const
getParent - Return the scope that this is nested in.
@ DeclScope
This is a scope that can contain a declaration.
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID, bool DeferHint=false)
Emit a diagnostic.
PartialDiagnostic PDiag(unsigned DiagID=0)
Build a partial diagnostic.
std::unique_ptr< sema::RISCVIntrinsicManager > IntrinsicManager
RAII class used to determine whether SFINAE has trapped any errors that occur during template argumen...
bool hasErrorOccurred() const
Determine whether any SFINAE errors have been trapped.
SpecialMemberOverloadResult - The overloading result for a special member function.
Sema - This implements semantic analysis and AST building for C.
void DeclareGlobalNewDelete()
DeclareGlobalNewDelete - Declare the global forms of operator new and delete.
bool hasReachableDefinition(NamedDecl *D, NamedDecl **Suggested, bool OnlyNeedComplete=false)
Determine if D has a reachable definition.
CXXConstructorDecl * DeclareImplicitDefaultConstructor(CXXRecordDecl *ClassDecl)
Declare the implicit default constructor for the given class.
llvm::DenseSet< Module * > LookupModulesCache
Cache of additional modules that should be used for name lookup within the current template instantia...
SmallVector< CodeSynthesisContext, 16 > CodeSynthesisContexts
List of active code synthesis contexts.
llvm::DenseSet< Module * > & getLookupModules()
Get the set of additional modules that should be checked during name lookup.
LookupNameKind
Describes the kind of name lookup to perform.
@ LookupLabel
Label name lookup.
@ LookupOrdinaryName
Ordinary name lookup, which finds ordinary names (functions, variables, typedefs, etc....
@ LookupUsingDeclName
Look up all declarations in a scope with the given name, including resolved using declarations.
@ LookupNestedNameSpecifierName
Look up of a name that precedes the '::' scope resolution operator in C++.
@ LookupOMPReductionName
Look up the name of an OpenMP user-defined reduction operation.
@ LookupLocalFriendName
Look up a friend of a local class.
@ LookupObjCProtocolName
Look up the name of an Objective-C protocol.
@ LookupRedeclarationWithLinkage
Look up an ordinary name that is going to be redeclared as a name with linkage.
@ LookupOperatorName
Look up of an operator name (e.g., operator+) for use with operator overloading.
@ LookupObjCImplicitSelfParam
Look up implicit 'self' parameter of an objective-c method.
@ LookupNamespaceName
Look up a namespace name within a C++ using directive or namespace alias definition,...
@ LookupMemberName
Member name lookup, which finds the names of class/struct/union members.
@ LookupDestructorName
Look up a name following ~ in a destructor name.
@ LookupTagName
Tag name lookup, which finds the names of enums, classes, structs, and unions.
@ LookupOMPMapperName
Look up the name of an OpenMP user-defined mapper.
@ LookupAnyName
Look up any declaration with any name.
bool hasReachableDeclarationSlow(const NamedDecl *D, llvm::SmallVectorImpl< Module * > *Modules=nullptr)
MissingImportKind
Kinds of missing import.
void ForceDeclarationOfImplicitMembers(CXXRecordDecl *Class)
Force the declaration of any implicitly-declared members of this class.
bool hasVisibleDeclarationSlow(const NamedDecl *D, llvm::SmallVectorImpl< Module * > *Modules)
void LookupNecessaryTypesForBuiltin(Scope *S, unsigned ID)
bool LookupInSuper(LookupResult &R, CXXRecordDecl *Class)
Perform qualified name lookup into all base classes of the given class.
bool RequireCompleteDeclContext(CXXScopeSpec &SS, DeclContext *DC)
Require that the context specified by SS be complete.
Preprocessor & getPreprocessor() const
CXXConstructorDecl * DeclareImplicitMoveConstructor(CXXRecordDecl *ClassDecl)
Declare the implicit move constructor for the given class.
static NamedDecl * getAsTemplateNameDecl(NamedDecl *D, bool AllowFunctionTemplates=true, bool AllowDependent=true)
Try to interpret the lookup result D as a template-name.
LiteralOperatorLookupResult LookupLiteralOperator(Scope *S, LookupResult &R, ArrayRef< QualType > ArgTys, bool AllowRaw, bool AllowTemplate, bool AllowStringTemplate, bool DiagnoseMissing, StringLiteral *StringLit=nullptr)
LookupLiteralOperator - Determine which literal operator should be used for a user-defined literal,...
bool hasVisibleExplicitSpecialization(const NamedDecl *D, llvm::SmallVectorImpl< Module * > *Modules=nullptr)
Determine if there is a visible declaration of D that is an explicit specialization declaration for a...
NamedDecl * LookupSingleName(Scope *S, DeclarationName Name, SourceLocation Loc, LookupNameKind NameKind, RedeclarationKind Redecl=RedeclarationKind::NotForRedeclaration)
Look up a name, looking for a single declaration.
IdentifierInfo * getSuperIdentifier() const
@ CTAK_Specified
The template argument was specified in the code or was instantiated with some deduced template argume...
bool DisableTypoCorrection
Tracks whether we are in a context where typo correction is disabled.
llvm::DenseMap< NamedDecl *, NamedDecl * > VisibleNamespaceCache
Map from the most recent declaration of a namespace to the most recent visible declaration of that na...
bool hasMergedDefinitionInCurrentModule(const NamedDecl *Def)
IdentifierSourceLocations TypoCorrectionFailures
A cache containing identifiers for which typo correction failed and their locations,...
DiagnosticsEngine & getDiagnostics() const
bool LookupBuiltin(LookupResult &R)
Lookup a builtin function, when name lookup would otherwise fail.
void PushOnScopeChains(NamedDecl *D, Scope *S, bool AddToContext=true)
Add this decl to the scope shadowed decl chains.
void LookupOverloadedOperatorName(OverloadedOperatorKind Op, Scope *S, UnresolvedSetImpl &Functions)
bool hasVisibleDefaultArgument(const NamedDecl *D, llvm::SmallVectorImpl< Module * > *Modules=nullptr)
Determine if the template parameter D has a visible default argument.
NamedDecl * LazilyCreateBuiltin(IdentifierInfo *II, unsigned ID, Scope *S, bool ForRedeclaration, SourceLocation Loc)
LazilyCreateBuiltin - The specified Builtin-ID was first used at file scope.
ASTContext & getASTContext() const
CXXDestructorDecl * LookupDestructor(CXXRecordDecl *Class)
Look for the destructor of the given class.
std::string getAmbiguousPathsDisplayString(CXXBasePaths &Paths)
Builds a string representing ambiguous paths from a specific derived class to different subobjects of...
unsigned TyposCorrected
The number of typos corrected by CorrectTypo.
PrintingPolicy getPrintingPolicy() const
Retrieve a suitable printing policy for diagnostics.
Module * getOwningModule(const Decl *Entity)
Get the module owning an entity.
ObjCMethodDecl * getCurMethodDecl()
getCurMethodDecl - If inside of a method body, this returns a pointer to the method decl for the meth...
void FindAssociatedClassesAndNamespaces(SourceLocation InstantiationLoc, ArrayRef< Expr * > Args, AssociatedNamespaceSet &AssociatedNamespaces, AssociatedClassSet &AssociatedClasses)
Find the associated classes and namespaces for argument-dependent lookup for a call with the given se...
void AddMethodTemplateCandidate(FunctionTemplateDecl *MethodTmpl, DeclAccessPair FoundDecl, CXXRecordDecl *ActingContext, TemplateArgumentListInfo *ExplicitTemplateArgs, QualType ObjectType, Expr::Classification ObjectClassification, ArrayRef< Expr * > Args, OverloadCandidateSet &CandidateSet, bool SuppressUserConversions=false, bool PartialOverloading=false, OverloadCandidateParamOrder PO={})
Add a C++ member function template as a candidate to the candidate set, using template argument deduc...
void AddTemplateOverloadCandidate(FunctionTemplateDecl *FunctionTemplate, DeclAccessPair FoundDecl, TemplateArgumentListInfo *ExplicitTemplateArgs, ArrayRef< Expr * > Args, OverloadCandidateSet &CandidateSet, bool SuppressUserConversions=false, bool PartialOverloading=false, bool AllowExplicit=true, ADLCallKind IsADLCandidate=ADLCallKind::NotADL, OverloadCandidateParamOrder PO={}, bool AggregateCandidateDeduction=false)
Add a C++ function template specialization as a candidate in the candidate set, using template argume...
FPOptions & getCurFPFeatures()
CXXConstructorDecl * LookupDefaultConstructor(CXXRecordDecl *Class)
Look up the default constructor for the given class.
const LangOptions & getLangOpts() const
TypoCorrection CorrectTypo(const DeclarationNameInfo &Typo, Sema::LookupNameKind LookupKind, Scope *S, CXXScopeSpec *SS, CorrectionCandidateCallback &CCC, CorrectTypoKind Mode, DeclContext *MemberContext=nullptr, bool EnteringContext=false, const ObjCObjectPointerType *OPT=nullptr, bool RecordFailure=true)
Try to "correct" a typo in the source code by finding visible declarations whose names are similar to...
TypoExpr * CorrectTypoDelayed(const DeclarationNameInfo &Typo, Sema::LookupNameKind LookupKind, Scope *S, CXXScopeSpec *SS, CorrectionCandidateCallback &CCC, TypoDiagnosticGenerator TDG, TypoRecoveryCallback TRC, CorrectTypoKind Mode, DeclContext *MemberContext=nullptr, bool EnteringContext=false, const ObjCObjectPointerType *OPT=nullptr)
Try to "correct" a typo in the source code by finding visible declarations whose names are similar to...
void LookupVisibleDecls(Scope *S, LookupNameKind Kind, VisibleDeclConsumer &Consumer, bool IncludeGlobalScope=true, bool LoadExternal=true)
bool LookupParsedName(LookupResult &R, Scope *S, CXXScopeSpec *SS, QualType ObjectType, bool AllowBuiltinCreation=false, bool EnteringContext=false)
Performs name lookup for a name that was parsed in the source code, and may contain a C++ scope speci...
bool hasVisibleMemberSpecialization(const NamedDecl *D, llvm::SmallVectorImpl< Module * > *Modules=nullptr)
Determine if there is a visible declaration of D that is a member specialization declaration (as oppo...
bool isReachable(const NamedDecl *D)
Determine whether a declaration is reachable.
CXXMethodDecl * DeclareImplicitMoveAssignment(CXXRecordDecl *ClassDecl)
Declare the implicit move assignment operator for the given class.
NamedDecl * getCurFunctionOrMethodDecl() const
getCurFunctionOrMethodDecl - Return the Decl for the current ObjC method or C function we're in,...
sema::FunctionScopeInfo * getCurFunction() const
bool isVisible(const NamedDecl *D)
Determine whether a declaration is visible to name lookup.
Module * getCurrentModule() const
Get the module unit whose scope we are currently within.
void NoteOverloadCandidate(const NamedDecl *Found, const FunctionDecl *Fn, OverloadCandidateRewriteKind RewriteKind=OverloadCandidateRewriteKind(), QualType DestType=QualType(), bool TakingAddress=false)
bool hasReachableDefaultArgument(const NamedDecl *D, llvm::SmallVectorImpl< Module * > *Modules=nullptr)
Determine if the template parameter D has a reachable default argument.
sema::BlockScopeInfo * getCurBlock()
Retrieve the current block, if any.
void ArgumentDependentLookup(DeclarationName Name, SourceLocation Loc, ArrayRef< Expr * > Args, ADLResult &Functions)
DeclContext * CurContext
CurContext - This is the current declaration context of parsing.
std::function< void(const TypoCorrection &)> TypoDiagnosticGenerator
CXXMethodDecl * LookupMovingAssignment(CXXRecordDecl *Class, unsigned Quals, bool RValueThis, unsigned ThisQuals)
Look up the moving assignment operator for the given class.
llvm::SmallVector< TypoExpr *, 2 > TypoExprs
Holds TypoExprs that are created from createDelayedTypo.
CXXMethodDecl * DeclareImplicitCopyAssignment(CXXRecordDecl *ClassDecl)
Declare the implicit copy assignment operator for the given class.
CXXConstructorDecl * LookupMovingConstructor(CXXRecordDecl *Class, unsigned Quals)
Look up the moving constructor for the given class.
bool isAcceptable(const NamedDecl *D, AcceptableKind Kind)
Determine whether a declaration is acceptable (visible/reachable).
CXXMethodDecl * LookupCopyingAssignment(CXXRecordDecl *Class, unsigned Quals, bool RValueThis, unsigned ThisQuals)
Look up the copying assignment operator for the given class.
bool isModuleVisible(const Module *M, bool ModulePrivate=false)
void AddMethodCandidate(DeclAccessPair FoundDecl, QualType ObjectType, Expr::Classification ObjectClassification, ArrayRef< Expr * > Args, OverloadCandidateSet &CandidateSet, bool SuppressUserConversion=false, OverloadCandidateParamOrder PO={})
AddMethodCandidate - Adds a named decl (which is some kind of method) as a method candidate to the gi...
bool hasVisibleMergedDefinition(const NamedDecl *Def)
void DeclareImplicitDeductionGuides(TemplateDecl *Template, SourceLocation Loc)
Declare implicit deduction guides for a class template if we've not already done so.
void diagnoseEquivalentInternalLinkageDeclarations(SourceLocation Loc, const NamedDecl *D, ArrayRef< const NamedDecl * > Equiv)
llvm::FoldingSet< SpecialMemberOverloadResultEntry > SpecialMemberCache
A cache of special member function overload resolution results for C++ records.
DeclContext * computeDeclContext(QualType T)
Compute the DeclContext that is associated with the given type.
LabelDecl * LookupOrCreateLabel(IdentifierInfo *II, SourceLocation IdentLoc, SourceLocation GnuLabelLoc=SourceLocation())
LookupOrCreateLabel - Do a name lookup of a label with the specified name.
void diagnoseMissingImport(SourceLocation Loc, const NamedDecl *Decl, MissingImportKind MIK, bool Recover=true)
Diagnose that the specified declaration needs to be visible but isn't, and suggest a module import th...
bool hasReachableMemberSpecialization(const NamedDecl *D, llvm::SmallVectorImpl< Module * > *Modules=nullptr)
Determine if there is a reachable declaration of D that is a member specialization declaration (as op...
RedeclarationKind forRedeclarationInCurContext() const
CXXConstructorDecl * LookupCopyingConstructor(CXXRecordDecl *Class, unsigned Quals)
Look up the copying constructor for the given class.
ModuleLoader & getModuleLoader() const
Retrieve the module loader associated with the preprocessor.
void diagnoseTypo(const TypoCorrection &Correction, const PartialDiagnostic &TypoDiag, bool ErrorRecovery=true)
bool CheckTemplateArgument(NamedDecl *Param, TemplateArgumentLoc &Arg, NamedDecl *Template, SourceLocation TemplateLoc, SourceLocation RAngleLoc, unsigned ArgumentPackIndex, SmallVectorImpl< TemplateArgument > &SugaredConverted, SmallVectorImpl< TemplateArgument > &CanonicalConverted, CheckTemplateArgumentKind CTAK)
Check that the given template argument corresponds to the given template parameter.
Scope * TUScope
Translation Unit Scope - useful to Objective-C actions that need to lookup file scope declarations in...
void DiagnoseAmbiguousLookup(LookupResult &Result)
Produce a diagnostic describing the ambiguity that resulted from name lookup.
bool LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx, bool InUnqualifiedLookup=false)
Perform qualified name lookup into a given context.
SmallVector< ExpressionEvaluationContextRecord, 8 > ExprEvalContexts
A stack of expression evaluation contexts.
void makeMergedDefinitionVisible(NamedDecl *ND)
Make a merged definition of an existing hidden definition ND visible at the specified location.
bool isDependentScopeSpecifier(const CXXScopeSpec &SS)
SourceManager & SourceMgr
bool hasReachableExplicitSpecialization(const NamedDecl *D, llvm::SmallVectorImpl< Module * > *Modules=nullptr)
Determine if there is a reachable declaration of D that is an explicit specialization declaration for...
std::function< ExprResult(Sema &, TypoExpr *, TypoCorrection)> TypoRecoveryCallback
DiagnosticsEngine & Diags
CXXConstructorDecl * DeclareImplicitCopyConstructor(CXXRecordDecl *ClassDecl)
Declare the implicit copy constructor for the given class.
SpecialMemberOverloadResult LookupSpecialMember(CXXRecordDecl *D, CXXSpecialMemberKind SM, bool ConstArg, bool VolatileArg, bool RValueThis, bool ConstThis, bool VolatileThis)
bool hasAcceptableDefaultArgument(const NamedDecl *D, llvm::SmallVectorImpl< Module * > *Modules, Sema::AcceptableKind Kind)
Determine if the template parameter D has a reachable default argument.
AccessResult CheckMemberAccess(SourceLocation UseLoc, CXXRecordDecl *NamingClass, DeclAccessPair Found)
Checks access to a member.
SmallVector< Module *, 16 > CodeSynthesisContextLookupModules
Extra modules inspected when performing a lookup during a template instantiation.
llvm::BumpPtrAllocator BumpAlloc
TemplateDeductionResult DeduceTemplateArguments(ClassTemplatePartialSpecializationDecl *Partial, ArrayRef< TemplateArgument > TemplateArgs, sema::TemplateDeductionInfo &Info)
void runWithSufficientStackSpace(SourceLocation Loc, llvm::function_ref< void()> Fn)
Run some code with "sufficient" stack space.
bool hasAcceptableDefinition(NamedDecl *D, NamedDecl **Suggested, AcceptableKind Kind, bool OnlyNeedComplete=false)
void clearDelayedTypo(TypoExpr *TE)
Clears the state of the given TypoExpr.
LiteralOperatorLookupResult
The possible outcomes of name lookup for a literal operator.
@ LOLR_ErrorNoDiagnostic
The lookup found no match but no diagnostic was issued.
@ LOLR_Raw
The lookup found a single 'raw' literal operator, which expects a string literal containing the spell...
@ LOLR_Error
The lookup resulted in an error.
@ LOLR_Cooked
The lookup found a single 'cooked' literal operator, which expects a normal literal to be built and p...
@ LOLR_StringTemplatePack
The lookup found an overload set of literal operator templates, which expect the character type and c...
@ LOLR_Template
The lookup found an overload set of literal operator templates, which expect the characters of the sp...
void ActOnPragmaDump(Scope *S, SourceLocation Loc, IdentifierInfo *II)
Called on #pragma clang __debug dump II.
bool LookupName(LookupResult &R, Scope *S, bool AllowBuiltinCreation=false, bool ForceNoCPlusPlus=false)
Perform unqualified name lookup starting from a given scope.
IdentifierResolver IdResolver
const TypoExprState & getTypoExprState(TypoExpr *TE) const
DeclContextLookupResult LookupConstructors(CXXRecordDecl *Class)
Look up the constructors for the given class.
CXXDestructorDecl * DeclareImplicitDestructor(CXXRecordDecl *ClassDecl)
Declare the implicit destructor for the given class.
void createImplicitModuleImportForErrorRecovery(SourceLocation Loc, Module *Mod)
Create an implicit import of the given module at the given source location, for error recovery,...
void AddOverloadCandidate(FunctionDecl *Function, DeclAccessPair FoundDecl, ArrayRef< Expr * > Args, OverloadCandidateSet &CandidateSet, bool SuppressUserConversions=false, bool PartialOverloading=false, bool AllowExplicit=true, bool AllowExplicitConversion=false, ADLCallKind IsADLCandidate=ADLCallKind::NotADL, ConversionSequenceList EarlyConversions={}, OverloadCandidateParamOrder PO={}, bool AggregateCandidateDeduction=false)
AddOverloadCandidate - Adds the given function to the set of candidate functions, using the given fun...
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
FileID getFileID(SourceLocation SpellingLoc) const
Return the FileID for a SourceLocation.
const FileEntry * getFileEntryForID(FileID FID) const
Returns the FileEntry record for the provided FileID.
A trivial tuple used to represent a source range.
SourceLocation getBegin() const
void dump() const
Dumps the specified AST fragment and all subtrees to llvm::errs().
StringLiteral - This represents a string literal expression, e.g.
Represents the declaration of a struct/union/class/enum.
bool isBeingDefined() const
Determines whether this type is in the process of being defined.
A template argument list.
unsigned size() const
Retrieve the number of template arguments in this template argument list.
Location wrapper for a TemplateArgument.
Represents a template argument.
QualType getAsType() const
Retrieve the type for a type template argument.
ArrayRef< TemplateArgument > pack_elements() const
Iterator range referencing all of the elements of a template argument pack.
@ Declaration
The template argument is a declaration that was provided for a pointer, reference,...
@ Template
The template argument is a template name that was provided for a template template parameter.
@ StructuralValue
The template argument is a non-type template argument that can't be represented by the special-case D...
@ Pack
The template argument is actually a parameter pack.
@ TemplateExpansion
The template argument is a pack expansion of a template name that was provided for a template templat...
@ NullPtr
The template argument is a null pointer or null pointer to member that was provided for a non-type te...
@ Type
The template argument is a type.
@ Null
Represents an empty template argument, e.g., one that has not been deduced.
@ Integral
The template argument is an integral value stored in an llvm::APSInt that was provided for an integra...
@ Expression
The template argument is an expression, and we've not resolved it to one of the other forms yet,...
ArgKind getKind() const
Return the kind of stored template argument.
TemplateName getAsTemplateOrTemplatePattern() const
Retrieve the template argument as a template name; if the argument is a pack expansion,...
Represents a C++ template name within the type system.
TemplateDecl * getAsTemplateDecl(bool IgnoreDeduced=false) const
Retrieve the underlying template declaration that this template name refers to, if known.
Stores a list of template parameters for a TemplateDecl and its derived classes.
NamedDecl * getParam(unsigned Idx)
Represents a type template specialization; the template must be a class template, a type alias templa...
Represents a declaration of a type.
const Type * getTypeForDecl() const
The base class of the type hierarchy.
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.
bool isReferenceType() const
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...
DeducedType * getContainedDeducedType() const
Get the DeducedType whose type will be deduced for a variable with an initializer of this type.
QualType getCanonicalTypeInternal() const
bool isIncompleteType(NamedDecl **Def=nullptr) const
Types are partitioned into 3 broad categories (C99 6.2.5p1): object types, function types,...
bool isAnyPointerType() const
TypeClass getTypeClass() const
const T * getAs() const
Member-template getAs'.
Base class for declarations which introduce a typedef-name.
void FoundDecl(NamedDecl *ND, NamedDecl *Hiding, DeclContext *Ctx, bool InBaseClass) override
Invoked each time Sema::LookupVisibleDecls() finds a declaration visible from the current scope or co...
void addKeywordResult(StringRef Keyword)
void addCorrection(TypoCorrection Correction)
const TypoCorrection & getNextCorrection()
Return the next typo correction that passes all internal filters and is deemed valid by the consumer'...
void FoundName(StringRef Name)
void addNamespaces(const llvm::MapVector< NamespaceDecl *, bool > &KnownNamespaces)
Set-up method to add to the consumer the set of namespaces to use in performing corrections to nested...
Simple class containing the result of Sema::CorrectTypo.
IdentifierInfo * getCorrectionAsIdentifierInfo() const
ArrayRef< PartialDiagnostic > getExtraDiagnostics() const
static const unsigned InvalidDistance
void addCorrectionDecl(NamedDecl *CDecl)
Add the given NamedDecl to the list of NamedDecls that are the declarations associated with the Decla...
void setCorrectionDecls(ArrayRef< NamedDecl * > Decls)
Clears the list of NamedDecls and adds the given set.
std::string getAsString(const LangOptions &LO) const
bool requiresImport() const
Returns whether this typo correction is correcting to a declaration that was declared in a module tha...
void setCorrectionRange(CXXScopeSpec *SS, const DeclarationNameInfo &TypoName)
NamedDecl * getCorrectionDecl() const
Gets the pointer to the declaration of the typo correction.
SourceRange getCorrectionRange() const
void WillReplaceSpecifier(bool ForceReplacement)
void setCallbackDistance(unsigned ED)
DeclarationName getCorrection() const
Gets the DeclarationName of the typo correction.
unsigned getEditDistance(bool Normalized=true) const
Gets the "edit distance" of the typo correction from the typo.
NestedNameSpecifier * getCorrectionSpecifier() const
Gets the NestedNameSpecifier needed to use the typo correction.
SmallVectorImpl< NamedDecl * >::iterator decl_iterator
void setRequiresImport(bool Req)
std::string getQuoted(const LangOptions &LO) const
NamedDecl * getFoundDecl() const
Get the correction declaration found by name lookup (before we looked through using shadow declaratio...
TypoExpr - Internal placeholder for expressions where typo correction still needs to be performed and...
A set of unresolved declarations.
void append(iterator I, iterator E)
void truncate(unsigned N)
The iterator over UnresolvedSets.
Represents C++ using-directive.
NamespaceDecl * getNominatedNamespace()
Returns the namespace nominated by this using-directive.
Represents a shadow declaration implicitly introduced into a scope by a (resolved) using-declaration ...
Represents a variable declaration or definition.
VarDecl * getTemplateInstantiationPattern() const
Retrieve the variable declaration from which this variable could be instantiated, if it is an instant...
Consumes visible declarations found when searching for all visible names within a given scope or cont...
virtual bool includeHiddenDecls() const
Determine whether hidden declarations (from unimported modules) should be given to this consumer.
virtual ~VisibleDeclConsumer()
Destroys the visible declaration consumer.
bool isVisible(const Module *M) const
Determine whether a module is visible.
SmallVector< SwitchInfo, 8 > SwitchStack
SwitchStack - This is the current set of active switch statements in the block.
Provides information about an attempted template argument deduction, whose success or failure was des...
bool Load(InterpState &S, CodePtr OpPC)
The JSON file list parser is used to communicate input to InstallAPI.
OverloadedOperatorKind
Enumeration specifying the different kinds of C++ overloaded operators.
if(T->getSizeExpr()) TRY_TO(TraverseStmt(const_cast< Expr * >(T -> getSizeExpr())))
@ OR_Deleted
Succeeded, but refers to a deleted function.
@ OR_Success
Overload resolution succeeded.
@ OR_Ambiguous
Ambiguous candidates found.
@ OR_No_Viable_Function
No viable function found.
@ Specialization
We are substituting template parameters for template arguments in order to form a template specializa...
std::unique_ptr< sema::RISCVIntrinsicManager > CreateRISCVIntrinsicManager(Sema &S)
@ External
External linkage, which indicates that the entity can be referred to from other translation units.
TemplateDecl * getAsTypeTemplateDecl(Decl *D)
@ Result
The result type of a method or function.
std::pair< unsigned, unsigned > getDepthAndIndex(const NamedDecl *ND)
Retrieve the depth and index of a template parameter.
CXXSpecialMemberKind
Kinds of C++ special members.
ExprValueKind
The categorization of expression values, currently following the C++11 scheme.
@ VK_PRValue
A pr-value expression (in the C++11 taxonomy) produces a temporary value.
@ VK_LValue
An l-value expression is a reference to an object with independent storage.
const FunctionProtoType * T
@ Success
Template argument deduction was successful.
@ TSK_ExplicitSpecialization
This template specialization was declared or defined by an explicit specialization (C++ [temp....
ConstructorInfo getConstructorInfo(NamedDecl *ND)
@ Class
The "class" keyword introduces the elaborated-type-specifier.
@ Enum
The "enum" keyword introduces the elaborated-type-specifier.
@ EST_None
no exception specification
AccessSpecifier
A C++ access specifier (public, private, protected), plus the special value "none" which means differ...
Represents an element in a path from a derived class to a base class.
int SubobjectNumber
Identifies which base class subobject (of type Base->getType()) this base path element refers to.
const CXXBaseSpecifier * Base
The base specifier that states the link from a derived class to a base class, which will be followed ...
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspon...
SourceLocation getLoc() const
getLoc - Returns the main location of the declaration name.
DeclarationName getName() const
getName - Returns the embedded declaration name.
SourceLocation getBeginLoc() const
getBeginLoc - Retrieve the location of the first token.
Extra information about a function prototype.
ExceptionSpecInfo ExceptionSpec
FunctionType::ExtInfo ExtInfo
OverloadExpr * Expression
Describes how types, statements, expressions, and declarations should be printed.