Skip to content

Commit 50fd480

Browse files
author
git apple-llvm automerger
committed
Merge commit 'ee29afe1e56d' from llvm.org/main into next
2 parents 4cfe8b1 + ee29afe commit 50fd480

File tree

10 files changed

+167
-163
lines changed

10 files changed

+167
-163
lines changed

clang/include/clang/Sema/Lookup.h

Lines changed: 52 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,34 @@ namespace clang {
3636

3737
class CXXBasePaths;
3838

39+
enum class LookupResultKind {
40+
/// No entity found met the criteria.
41+
NotFound = 0,
42+
43+
/// No entity found met the criteria within the current
44+
/// instantiation,, but there were dependent base classes of the
45+
/// current instantiation that could not be searched.
46+
NotFoundInCurrentInstantiation,
47+
48+
/// Name lookup found a single declaration that met the
49+
/// criteria. getFoundDecl() will return this declaration.
50+
Found,
51+
52+
/// Name lookup found a set of overloaded functions that
53+
/// met the criteria.
54+
FoundOverloaded,
55+
56+
/// Name lookup found an unresolvable value declaration
57+
/// and cannot yet complete. This only happens in C++ dependent
58+
/// contexts with dependent using declarations.
59+
FoundUnresolvedValue,
60+
61+
/// Name lookup results in an ambiguity; use
62+
/// getAmbiguityKind to figure out what kind of ambiguity
63+
/// we have.
64+
Ambiguous
65+
};
66+
3967
enum class LookupAmbiguityKind {
4068
/// Name lookup results in an ambiguity because multiple
4169
/// entities that meet the lookup criteria were found in
@@ -118,34 +146,6 @@ enum class LookupAmbiguityKind {
118146
/// results occurred for a given lookup.
119147
class LookupResult {
120148
public:
121-
enum LookupResultKind {
122-
/// No entity found met the criteria.
123-
NotFound = 0,
124-
125-
/// No entity found met the criteria within the current
126-
/// instantiation,, but there were dependent base classes of the
127-
/// current instantiation that could not be searched.
128-
NotFoundInCurrentInstantiation,
129-
130-
/// Name lookup found a single declaration that met the
131-
/// criteria. getFoundDecl() will return this declaration.
132-
Found,
133-
134-
/// Name lookup found a set of overloaded functions that
135-
/// met the criteria.
136-
FoundOverloaded,
137-
138-
/// Name lookup found an unresolvable value declaration
139-
/// and cannot yet complete. This only happens in C++ dependent
140-
/// contexts with dependent using declarations.
141-
FoundUnresolvedValue,
142-
143-
/// Name lookup results in an ambiguity; use
144-
/// getAmbiguityKind to figure out what kind of ambiguity
145-
/// we have.
146-
Ambiguous
147-
};
148-
149149
/// A little identifier for flagging temporary lookup results.
150150
enum TemporaryToken {
151151
Temporary
@@ -322,23 +322,23 @@ class LookupResult {
322322
bool isTemplateNameLookup() const { return TemplateNameLookup; }
323323

324324
bool isAmbiguous() const {
325-
return getResultKind() == Ambiguous;
325+
return getResultKind() == LookupResultKind::Ambiguous;
326326
}
327327

328328
/// Determines if this names a single result which is not an
329329
/// unresolved value using decl. If so, it is safe to call
330330
/// getFoundDecl().
331331
bool isSingleResult() const {
332-
return getResultKind() == Found;
332+
return getResultKind() == LookupResultKind::Found;
333333
}
334334

335335
/// Determines if the results are overloaded.
336336
bool isOverloadedResult() const {
337-
return getResultKind() == FoundOverloaded;
337+
return getResultKind() == LookupResultKind::FoundOverloaded;
338338
}
339339

340340
bool isUnresolvableResult() const {
341-
return getResultKind() == FoundUnresolvedValue;
341+
return getResultKind() == LookupResultKind::FoundUnresolvedValue;
342342
}
343343

344344
LookupResultKind getResultKind() const {
@@ -480,29 +480,29 @@ class LookupResult {
480480
/// Does not test the acceptance criteria.
481481
void addDecl(NamedDecl *D, AccessSpecifier AS) {
482482
Decls.addDecl(D, AS);
483-
ResultKind = Found;
483+
ResultKind = LookupResultKind::Found;
484484
}
485485

486486
/// Add all the declarations from another set of lookup
487487
/// results.
488488
void addAllDecls(const LookupResult &Other) {
489489
Decls.append(Other.Decls.begin(), Other.Decls.end());
490-
ResultKind = Found;
490+
ResultKind = LookupResultKind::Found;
491491
}
492492

493493
/// Determine whether no result was found because we could not
494494
/// search into dependent base classes of the current instantiation.
495495
bool wasNotFoundInCurrentInstantiation() const {
496-
return ResultKind == NotFoundInCurrentInstantiation;
496+
return ResultKind == LookupResultKind::NotFoundInCurrentInstantiation;
497497
}
498498

499499
/// Note that while no result was found in the current instantiation,
500500
/// there were dependent base classes that could not be searched.
501501
void setNotFoundInCurrentInstantiation() {
502-
assert((ResultKind == NotFound ||
503-
ResultKind == NotFoundInCurrentInstantiation) &&
502+
assert((ResultKind == LookupResultKind::NotFound ||
503+
ResultKind == LookupResultKind::NotFoundInCurrentInstantiation) &&
504504
Decls.empty());
505-
ResultKind = NotFoundInCurrentInstantiation;
505+
ResultKind = LookupResultKind::NotFoundInCurrentInstantiation;
506506
}
507507

508508
/// Determine whether the lookup result was shadowed by some other
@@ -524,8 +524,8 @@ class LookupResult {
524524
/// removals has been performed.
525525
void resolveKindAfterFilter() {
526526
if (Decls.empty()) {
527-
if (ResultKind != NotFoundInCurrentInstantiation)
528-
ResultKind = NotFound;
527+
if (ResultKind != LookupResultKind::NotFoundInCurrentInstantiation)
528+
ResultKind = LookupResultKind::NotFound;
529529

530530
if (Paths) {
531531
deletePaths(Paths);
@@ -534,16 +534,16 @@ class LookupResult {
534534
} else {
535535
std::optional<LookupAmbiguityKind> SavedAK;
536536
bool WasAmbiguous = false;
537-
if (ResultKind == Ambiguous) {
537+
if (ResultKind == LookupResultKind::Ambiguous) {
538538
SavedAK = Ambiguity;
539539
WasAmbiguous = true;
540540
}
541-
ResultKind = Found;
541+
ResultKind = LookupResultKind::Found;
542542
resolveKind();
543543

544544
// If we didn't make the lookup unambiguous, restore the old
545545
// ambiguity kind.
546-
if (ResultKind == Ambiguous) {
546+
if (ResultKind == LookupResultKind::Ambiguous) {
547547
(void)WasAmbiguous;
548548
assert(WasAmbiguous);
549549
Ambiguity = *SavedAK;
@@ -556,7 +556,8 @@ class LookupResult {
556556

557557
template <class DeclClass>
558558
DeclClass *getAsSingle() const {
559-
if (getResultKind() != Found) return nullptr;
559+
if (getResultKind() != LookupResultKind::Found)
560+
return nullptr;
560561
return dyn_cast<DeclClass>(getFoundDecl());
561562
}
562563

@@ -566,8 +567,8 @@ class LookupResult {
566567
/// This is intended for users who have examined the result kind
567568
/// and are certain that there is only one result.
568569
NamedDecl *getFoundDecl() const {
569-
assert(getResultKind() == Found
570-
&& "getFoundDecl called on non-unique result");
570+
assert(getResultKind() == LookupResultKind::Found &&
571+
"getFoundDecl called on non-unique result");
571572
return (*begin())->getUnderlyingDecl();
572573
}
573574

@@ -579,7 +580,8 @@ class LookupResult {
579580

580581
/// Asks if the result is a single tag decl.
581582
bool isSingleTagDecl() const {
582-
return getResultKind() == Found && isa<TagDecl>(getFoundDecl());
583+
return getResultKind() == LookupResultKind::Found &&
584+
isa<TagDecl>(getFoundDecl());
583585
}
584586

585587
/// Make these results show that the name was found in
@@ -603,7 +605,7 @@ class LookupResult {
603605

604606
/// Clears out any current state.
605607
LLVM_ATTRIBUTE_REINITIALIZES void clear() {
606-
ResultKind = NotFound;
608+
ResultKind = LookupResultKind::NotFound;
607609
Decls.clear();
608610
if (Paths) deletePaths(Paths);
609611
Paths = nullptr;
@@ -770,7 +772,7 @@ class LookupResult {
770772
}
771773

772774
void setAmbiguous(LookupAmbiguityKind AK) {
773-
ResultKind = Ambiguous;
775+
ResultKind = LookupResultKind::Ambiguous;
774776
Ambiguity = AK;
775777
}
776778

@@ -789,7 +791,7 @@ class LookupResult {
789791
static void deletePaths(CXXBasePaths *);
790792

791793
// Results.
792-
LookupResultKind ResultKind = NotFound;
794+
LookupResultKind ResultKind = LookupResultKind::NotFound;
793795
// ill-defined unless ambiguous. Still need to be initialized it will be
794796
// copied/moved.
795797
LookupAmbiguityKind Ambiguity = {};

clang/lib/Sema/SemaDecl.cpp

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ ParsedType Sema::getTypeName(const IdentifierInfo &II, SourceLocation NameLoc,
420420
NamedDecl *IIDecl = nullptr;
421421
UsingShadowDecl *FoundUsingShadow = nullptr;
422422
switch (Result.getResultKind()) {
423-
case LookupResult::NotFound:
423+
case LookupResultKind::NotFound:
424424
if (CorrectedII) {
425425
TypeNameValidatorCCC CCC(/*AllowInvalid=*/true, isClassName,
426426
AllowDeducedTemplate);
@@ -462,7 +462,7 @@ ParsedType Sema::getTypeName(const IdentifierInfo &II, SourceLocation NameLoc,
462462
}
463463
Result.suppressDiagnostics();
464464
return nullptr;
465-
case LookupResult::NotFoundInCurrentInstantiation:
465+
case LookupResultKind::NotFoundInCurrentInstantiation:
466466
if (AllowImplicitTypename == ImplicitTypenameContext::Yes) {
467467
QualType T = Context.getDependentNameType(ElaboratedTypeKeyword::None,
468468
SS->getScopeRep(), &II);
@@ -474,12 +474,12 @@ ParsedType Sema::getTypeName(const IdentifierInfo &II, SourceLocation NameLoc,
474474
return CreateParsedType(T, TLB.getTypeSourceInfo(Context, T));
475475
}
476476
[[fallthrough]];
477-
case LookupResult::FoundOverloaded:
478-
case LookupResult::FoundUnresolvedValue:
477+
case LookupResultKind::FoundOverloaded:
478+
case LookupResultKind::FoundUnresolvedValue:
479479
Result.suppressDiagnostics();
480480
return nullptr;
481481

482-
case LookupResult::Ambiguous:
482+
case LookupResultKind::Ambiguous:
483483
// Recover from type-hiding ambiguities by hiding the type. We'll
484484
// do the lookup again when looking for an object, and we can
485485
// diagnose the error then. If we don't do this, then the error
@@ -523,7 +523,7 @@ ParsedType Sema::getTypeName(const IdentifierInfo &II, SourceLocation NameLoc,
523523
// perform the name lookup again.
524524
break;
525525

526-
case LookupResult::Found:
526+
case LookupResultKind::Found:
527527
IIDecl = Result.getFoundDecl();
528528
FoundUsingShadow = dyn_cast<UsingShadowDecl>(*Result.begin());
529529
break;
@@ -659,7 +659,7 @@ DeclSpec::TST Sema::isTagName(IdentifierInfo &II, Scope *S) {
659659
LookupResult R(*this, &II, SourceLocation(), LookupTagName);
660660
LookupName(R, S, false);
661661
R.suppressDiagnostics();
662-
if (R.getResultKind() == LookupResult::Found)
662+
if (R.getResultKind() == LookupResultKind::Found)
663663
if (const TagDecl *TD = R.getAsSingle<TagDecl>()) {
664664
switch (TD->getTagKind()) {
665665
case TagTypeKind::Struct:
@@ -928,7 +928,7 @@ Sema::NameClassification Sema::ClassifyName(Scope *S, CXXScopeSpec &SS,
928928

929929
Corrected:
930930
switch (Result.getResultKind()) {
931-
case LookupResult::NotFound:
931+
case LookupResultKind::NotFound:
932932
// If an unqualified-id is followed by a '(', then we have a function
933933
// call.
934934
if (SS.isEmpty() && NextToken.is(tok::l_paren)) {
@@ -1045,7 +1045,7 @@ Sema::NameClassification Sema::ClassifyName(Scope *S, CXXScopeSpec &SS,
10451045
Result.suppressDiagnostics();
10461046
return NameClassification::Unknown();
10471047

1048-
case LookupResult::NotFoundInCurrentInstantiation: {
1048+
case LookupResultKind::NotFoundInCurrentInstantiation: {
10491049
// We performed name lookup into the current instantiation, and there were
10501050
// dependent bases, so we treat this result the same way as any other
10511051
// dependent nested-name-specifier.
@@ -1063,12 +1063,12 @@ Sema::NameClassification Sema::ClassifyName(Scope *S, CXXScopeSpec &SS,
10631063
return NameClassification::DependentNonType();
10641064
}
10651065

1066-
case LookupResult::Found:
1067-
case LookupResult::FoundOverloaded:
1068-
case LookupResult::FoundUnresolvedValue:
1066+
case LookupResultKind::Found:
1067+
case LookupResultKind::FoundOverloaded:
1068+
case LookupResultKind::FoundUnresolvedValue:
10691069
break;
10701070

1071-
case LookupResult::Ambiguous:
1071+
case LookupResultKind::Ambiguous:
10721072
if (getLangOpts().CPlusPlus && NextToken.is(tok::less) &&
10731073
hasAnyAcceptableTemplateNames(Result, /*AllowFunctionTemplates=*/true,
10741074
/*AllowDependent=*/false)) {
@@ -1500,11 +1500,11 @@ static bool AllowOverloadingOfFunction(const LookupResult &Previous,
15001500
// to check at least two; hence the 'any_of' check below. Note that
15011501
// the overloadable attribute is implicitly added to declarations
15021502
// that were required to have it but did not.
1503-
if (Previous.getResultKind() == LookupResult::FoundOverloaded) {
1503+
if (Previous.getResultKind() == LookupResultKind::FoundOverloaded) {
15041504
return llvm::any_of(Previous, [](const NamedDecl *ND) {
15051505
return ND->hasAttr<OverloadableAttr>();
15061506
});
1507-
} else if (Previous.getResultKind() == LookupResult::Found)
1507+
} else if (Previous.getResultKind() == LookupResultKind::Found)
15081508
return Previous.getFoundDecl()->hasAttr<OverloadableAttr>();
15091509

15101510
return false;
@@ -9092,7 +9092,7 @@ static SourceLocation getCaptureLocation(const LambdaScopeInfo *LSI,
90929092
static bool shouldWarnIfShadowedDecl(const DiagnosticsEngine &Diags,
90939093
const LookupResult &R) {
90949094
// Only diagnose if we're shadowing an unambiguous field or variable.
9095-
if (R.getResultKind() != LookupResult::Found)
9095+
if (R.getResultKind() != LookupResultKind::Found)
90969096
return false;
90979097

90989098
// Return false if warning is ignored.
@@ -11475,7 +11475,7 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC,
1147511475
// Recover gracefully from an invalid redeclaration.
1147611476
D.setRedeclaration(true);
1147711477
assert((NewFD->isInvalidDecl() || !D.isRedeclaration() ||
11478-
Previous.getResultKind() != LookupResult::FoundOverloaded) &&
11478+
Previous.getResultKind() != LookupResultKind::FoundOverloaded) &&
1147911479
"previous declaration set still overloaded");
1148011480

1148111481
// Diagnose no-prototype function declarations with calling conventions that
@@ -11642,7 +11642,7 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC,
1164211642

1164311643
assert((NewFD->isInvalidDecl() || NewFD->isMultiVersion() ||
1164411644
!D.isRedeclaration() ||
11645-
Previous.getResultKind() != LookupResult::FoundOverloaded) &&
11645+
Previous.getResultKind() != LookupResultKind::FoundOverloaded) &&
1164611646
"previous declaration set still overloaded");
1164711647

1164811648
NamedDecl *PrincipalDecl = (FunctionTemplate
@@ -19776,19 +19776,19 @@ FieldDecl *Sema::HandleField(Scope *S, RecordDecl *Record,
1977619776
RedeclarationKind::ForVisibleRedeclaration);
1977719777
LookupName(Previous, S);
1977819778
switch (Previous.getResultKind()) {
19779-
case LookupResult::Found:
19780-
case LookupResult::FoundUnresolvedValue:
19781-
PrevDecl = Previous.getAsSingle<NamedDecl>();
19782-
break;
19779+
case LookupResultKind::Found:
19780+
case LookupResultKind::FoundUnresolvedValue:
19781+
PrevDecl = Previous.getAsSingle<NamedDecl>();
19782+
break;
1978319783

19784-
case LookupResult::FoundOverloaded:
19785-
PrevDecl = Previous.getRepresentativeDecl();
19786-
break;
19784+
case LookupResultKind::FoundOverloaded:
19785+
PrevDecl = Previous.getRepresentativeDecl();
19786+
break;
1978719787

19788-
case LookupResult::NotFound:
19789-
case LookupResult::NotFoundInCurrentInstantiation:
19790-
case LookupResult::Ambiguous:
19791-
break;
19788+
case LookupResultKind::NotFound:
19789+
case LookupResultKind::NotFoundInCurrentInstantiation:
19790+
case LookupResultKind::Ambiguous:
19791+
break;
1979219792
}
1979319793
Previous.suppressDiagnostics();
1979419794

0 commit comments

Comments
 (0)