Skip to content

Commit f3a61f6

Browse files
committed
[clang][NFC] Convert LookupResult::AmbiguityKind to scoped enum
1 parent 98eeedd commit f3a61f6

File tree

3 files changed

+95
-93
lines changed

3 files changed

+95
-93
lines changed

clang/include/clang/Sema/Lookup.h

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

3737
class CXXBasePaths;
3838

39+
enum class LookupAmbiguityKind {
40+
/// Name lookup results in an ambiguity because multiple
41+
/// entities that meet the lookup criteria were found in
42+
/// subobjects of different types. For example:
43+
/// @code
44+
/// struct A { void f(int); }
45+
/// struct B { void f(double); }
46+
/// struct C : A, B { };
47+
/// void test(C c) {
48+
/// c.f(0); // error: A::f and B::f come from subobjects of different
49+
/// // types. overload resolution is not performed.
50+
/// }
51+
/// @endcode
52+
AmbiguousBaseSubobjectTypes,
53+
54+
/// Name lookup results in an ambiguity because multiple
55+
/// nonstatic entities that meet the lookup criteria were found
56+
/// in different subobjects of the same type. For example:
57+
/// @code
58+
/// struct A { int x; };
59+
/// struct B : A { };
60+
/// struct C : A { };
61+
/// struct D : B, C { };
62+
/// int test(D d) {
63+
/// return d.x; // error: 'x' is found in two A subobjects (of B and C)
64+
/// }
65+
/// @endcode
66+
AmbiguousBaseSubobjects,
67+
68+
/// Name lookup results in an ambiguity because multiple definitions
69+
/// of entity that meet the lookup criteria were found in different
70+
/// declaration contexts.
71+
/// @code
72+
/// namespace A {
73+
/// int i;
74+
/// namespace B { int i; }
75+
/// int test() {
76+
/// using namespace B;
77+
/// return i; // error 'i' is found in namespace A and A::B
78+
/// }
79+
/// }
80+
/// @endcode
81+
AmbiguousReference,
82+
83+
/// Name lookup results in an ambiguity because multiple placeholder
84+
/// variables were found in the same scope.
85+
/// @code
86+
/// void f() {
87+
/// int _ = 0;
88+
/// int _ = 0;
89+
/// return _; // ambiguous use of placeholder variable
90+
/// }
91+
/// @endcode
92+
AmbiguousReferenceToPlaceholderVariable,
93+
94+
/// Name lookup results in an ambiguity because an entity with a
95+
/// tag name was hidden by an entity with an ordinary name from
96+
/// a different context.
97+
/// @code
98+
/// namespace A { struct Foo {}; }
99+
/// namespace B { void Foo(); }
100+
/// namespace C {
101+
/// using namespace A;
102+
/// using namespace B;
103+
/// }
104+
/// void test() {
105+
/// C::Foo(); // error: tag 'A::Foo' is hidden by an object in a
106+
/// // different namespace
107+
/// }
108+
/// @endcode
109+
AmbiguousTagHiding
110+
};
111+
39112
/// Represents the results of name lookup.
40113
///
41114
/// An instance of the LookupResult class captures the results of a
@@ -73,79 +146,6 @@ class LookupResult {
73146
Ambiguous
74147
};
75148

76-
enum AmbiguityKind {
77-
/// Name lookup results in an ambiguity because multiple
78-
/// entities that meet the lookup criteria were found in
79-
/// subobjects of different types. For example:
80-
/// @code
81-
/// struct A { void f(int); }
82-
/// struct B { void f(double); }
83-
/// struct C : A, B { };
84-
/// void test(C c) {
85-
/// c.f(0); // error: A::f and B::f come from subobjects of different
86-
/// // types. overload resolution is not performed.
87-
/// }
88-
/// @endcode
89-
AmbiguousBaseSubobjectTypes,
90-
91-
/// Name lookup results in an ambiguity because multiple
92-
/// nonstatic entities that meet the lookup criteria were found
93-
/// in different subobjects of the same type. For example:
94-
/// @code
95-
/// struct A { int x; };
96-
/// struct B : A { };
97-
/// struct C : A { };
98-
/// struct D : B, C { };
99-
/// int test(D d) {
100-
/// return d.x; // error: 'x' is found in two A subobjects (of B and C)
101-
/// }
102-
/// @endcode
103-
AmbiguousBaseSubobjects,
104-
105-
/// Name lookup results in an ambiguity because multiple definitions
106-
/// of entity that meet the lookup criteria were found in different
107-
/// declaration contexts.
108-
/// @code
109-
/// namespace A {
110-
/// int i;
111-
/// namespace B { int i; }
112-
/// int test() {
113-
/// using namespace B;
114-
/// return i; // error 'i' is found in namespace A and A::B
115-
/// }
116-
/// }
117-
/// @endcode
118-
AmbiguousReference,
119-
120-
/// Name lookup results in an ambiguity because multiple placeholder
121-
/// variables were found in the same scope.
122-
/// @code
123-
/// void f() {
124-
/// int _ = 0;
125-
/// int _ = 0;
126-
/// return _; // ambiguous use of placeholder variable
127-
/// }
128-
/// @endcode
129-
AmbiguousReferenceToPlaceholderVariable,
130-
131-
/// Name lookup results in an ambiguity because an entity with a
132-
/// tag name was hidden by an entity with an ordinary name from
133-
/// a different context.
134-
/// @code
135-
/// namespace A { struct Foo {}; }
136-
/// namespace B { void Foo(); }
137-
/// namespace C {
138-
/// using namespace A;
139-
/// using namespace B;
140-
/// }
141-
/// void test() {
142-
/// C::Foo(); // error: tag 'A::Foo' is hidden by an object in a
143-
/// // different namespace
144-
/// }
145-
/// @endcode
146-
AmbiguousTagHiding
147-
};
148-
149149
/// A little identifier for flagging temporary lookup results.
150150
enum TemporaryToken {
151151
Temporary
@@ -346,7 +346,7 @@ class LookupResult {
346346
return ResultKind;
347347
}
348348

349-
AmbiguityKind getAmbiguityKind() const {
349+
LookupAmbiguityKind getAmbiguityKind() const {
350350
assert(isAmbiguous());
351351
return Ambiguity;
352352
}
@@ -532,7 +532,7 @@ class LookupResult {
532532
Paths = nullptr;
533533
}
534534
} else {
535-
std::optional<AmbiguityKind> SavedAK;
535+
std::optional<LookupAmbiguityKind> SavedAK;
536536
bool WasAmbiguous = false;
537537
if (ResultKind == Ambiguous) {
538538
SavedAK = Ambiguity;
@@ -598,7 +598,7 @@ class LookupResult {
598598
/// different contexts and a tag decl was hidden by an ordinary
599599
/// decl in a different context.
600600
void setAmbiguousQualifiedTagHiding() {
601-
setAmbiguous(AmbiguousTagHiding);
601+
setAmbiguous(LookupAmbiguityKind::AmbiguousTagHiding);
602602
}
603603

604604
/// Clears out any current state.
@@ -769,7 +769,7 @@ class LookupResult {
769769
getSema().DiagnoseAmbiguousLookup(*this);
770770
}
771771

772-
void setAmbiguous(AmbiguityKind AK) {
772+
void setAmbiguous(LookupAmbiguityKind AK) {
773773
ResultKind = Ambiguous;
774774
Ambiguity = AK;
775775
}
@@ -792,7 +792,7 @@ class LookupResult {
792792
LookupResultKind ResultKind = NotFound;
793793
// ill-defined unless ambiguous. Still need to be initialized it will be
794794
// copied/moved.
795-
AmbiguityKind Ambiguity = {};
795+
LookupAmbiguityKind Ambiguity = {};
796796
UnresolvedSet<8> Decls;
797797
CXXBasePaths *Paths = nullptr;
798798
CXXRecordDecl *NamingClass = nullptr;

clang/lib/Sema/SemaDecl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ ParsedType Sema::getTypeName(const IdentifierInfo &II, SourceLocation NameLoc,
483483
// diagnose the error then. If we don't do this, then the error
484484
// about hiding the type will be immediately followed by an error
485485
// that only makes sense if the identifier was treated like a type.
486-
if (Result.getAmbiguityKind() == LookupResult::AmbiguousTagHiding) {
486+
if (Result.getAmbiguityKind() == LookupAmbiguityKind::AmbiguousTagHiding) {
487487
Result.suppressDiagnostics();
488488
return nullptr;
489489
}

clang/lib/Sema/SemaLookup.cpp

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -337,11 +337,13 @@ bool LookupResult::checkDebugAssumptions() const {
337337
isa<FunctionTemplateDecl>((*begin())->getUnderlyingDecl())));
338338
assert(ResultKind != FoundUnresolvedValue || checkUnresolved());
339339
assert(ResultKind != Ambiguous || Decls.size() > 1 ||
340-
(Decls.size() == 1 && (Ambiguity == AmbiguousBaseSubobjects ||
341-
Ambiguity == AmbiguousBaseSubobjectTypes)));
342-
assert((Paths != nullptr) == (ResultKind == Ambiguous &&
343-
(Ambiguity == AmbiguousBaseSubobjectTypes ||
344-
Ambiguity == AmbiguousBaseSubobjects)));
340+
(Decls.size() == 1 &&
341+
(Ambiguity == LookupAmbiguityKind::AmbiguousBaseSubobjects ||
342+
Ambiguity == LookupAmbiguityKind::AmbiguousBaseSubobjectTypes)));
343+
assert((Paths != nullptr) ==
344+
(ResultKind == Ambiguous &&
345+
(Ambiguity == LookupAmbiguityKind::AmbiguousBaseSubobjectTypes ||
346+
Ambiguity == LookupAmbiguityKind::AmbiguousBaseSubobjects)));
345347
return true;
346348
}
347349

@@ -641,9 +643,9 @@ void LookupResult::resolveKind() {
641643
Ambiguous = true;
642644

643645
if (Ambiguous && ReferenceToPlaceHolderVariable)
644-
setAmbiguous(LookupResult::AmbiguousReferenceToPlaceholderVariable);
646+
setAmbiguous(LookupAmbiguityKind::AmbiguousReferenceToPlaceholderVariable);
645647
else if (Ambiguous)
646-
setAmbiguous(LookupResult::AmbiguousReference);
648+
setAmbiguous(LookupAmbiguityKind::AmbiguousReference);
647649
else if (HasUnresolved)
648650
ResultKind = LookupResult::FoundUnresolvedValue;
649651
else if (N > 1 || HasFunctionTemplate)
@@ -665,15 +667,15 @@ void LookupResult::setAmbiguousBaseSubobjects(CXXBasePaths &P) {
665667
Paths->swap(P);
666668
addDeclsFromBasePaths(*Paths);
667669
resolveKind();
668-
setAmbiguous(AmbiguousBaseSubobjects);
670+
setAmbiguous(LookupAmbiguityKind::AmbiguousBaseSubobjects);
669671
}
670672

671673
void LookupResult::setAmbiguousBaseSubobjectTypes(CXXBasePaths &P) {
672674
Paths = new CXXBasePaths;
673675
Paths->swap(P);
674676
addDeclsFromBasePaths(*Paths);
675677
resolveKind();
676-
setAmbiguous(AmbiguousBaseSubobjectTypes);
678+
setAmbiguous(LookupAmbiguityKind::AmbiguousBaseSubobjectTypes);
677679
}
678680

679681
void LookupResult::print(raw_ostream &Out) {
@@ -2769,7 +2771,7 @@ void Sema::DiagnoseAmbiguousLookup(LookupResult &Result) {
27692771
SourceRange LookupRange = Result.getContextRange();
27702772

27712773
switch (Result.getAmbiguityKind()) {
2772-
case LookupResult::AmbiguousBaseSubobjects: {
2774+
case LookupAmbiguityKind::AmbiguousBaseSubobjects: {
27732775
CXXBasePaths *Paths = Result.getBasePaths();
27742776
QualType SubobjectType = Paths->front().back().Base->getType();
27752777
Diag(NameLoc, diag::err_ambiguous_member_multiple_subobjects)
@@ -2785,7 +2787,7 @@ void Sema::DiagnoseAmbiguousLookup(LookupResult &Result) {
27852787
break;
27862788
}
27872789

2788-
case LookupResult::AmbiguousBaseSubobjectTypes: {
2790+
case LookupAmbiguityKind::AmbiguousBaseSubobjectTypes: {
27892791
Diag(NameLoc, diag::err_ambiguous_member_multiple_subobject_types)
27902792
<< Name << LookupRange;
27912793

@@ -2811,7 +2813,7 @@ void Sema::DiagnoseAmbiguousLookup(LookupResult &Result) {
28112813
break;
28122814
}
28132815

2814-
case LookupResult::AmbiguousTagHiding: {
2816+
case LookupAmbiguityKind::AmbiguousTagHiding: {
28152817
Diag(NameLoc, diag::err_ambiguous_tag_hiding) << Name << LookupRange;
28162818

28172819
llvm::SmallPtrSet<NamedDecl*, 8> TagDecls;
@@ -2836,7 +2838,7 @@ void Sema::DiagnoseAmbiguousLookup(LookupResult &Result) {
28362838
break;
28372839
}
28382840

2839-
case LookupResult::AmbiguousReferenceToPlaceholderVariable: {
2841+
case LookupAmbiguityKind::AmbiguousReferenceToPlaceholderVariable: {
28402842
Diag(NameLoc, diag::err_using_placeholder_variable) << Name << LookupRange;
28412843
DeclContext *DC = nullptr;
28422844
for (auto *D : Result) {
@@ -2848,7 +2850,7 @@ void Sema::DiagnoseAmbiguousLookup(LookupResult &Result) {
28482850
break;
28492851
}
28502852

2851-
case LookupResult::AmbiguousReference: {
2853+
case LookupAmbiguityKind::AmbiguousReference: {
28522854
Diag(NameLoc, diag::err_ambiguous_reference) << Name << LookupRange;
28532855

28542856
for (auto *D : Result)

0 commit comments

Comments
 (0)