Author: Vlad Serebrennikov
Date: 2025-04-28T08:22:57+03:00
New Revision: f3a61f61eef53ecc0b59d14c52396df4f47ee5e8

URL: 
https://github.com/llvm/llvm-project/commit/f3a61f61eef53ecc0b59d14c52396df4f47ee5e8
DIFF: 
https://github.com/llvm/llvm-project/commit/f3a61f61eef53ecc0b59d14c52396df4f47ee5e8.diff

LOG: [clang][NFC] Convert `LookupResult::AmbiguityKind` to scoped enum

Added: 
    

Modified: 
    clang/include/clang/Sema/Lookup.h
    clang/lib/Sema/SemaDecl.cpp
    clang/lib/Sema/SemaLookup.cpp

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/Sema/Lookup.h 
b/clang/include/clang/Sema/Lookup.h
index b0a08a05ac6a0..41a206b7f52b3 100644
--- a/clang/include/clang/Sema/Lookup.h
+++ b/clang/include/clang/Sema/Lookup.h
@@ -36,6 +36,79 @@ namespace clang {
 
 class CXXBasePaths;
 
+enum class LookupAmbiguityKind {
+  /// Name lookup results in an ambiguity because multiple
+  /// entities that meet the lookup criteria were found in
+  /// subobjects of 
diff erent types. For example:
+  /// @code
+  /// struct A { void f(int); }
+  /// struct B { void f(double); }
+  /// struct C : A, B { };
+  /// void test(C c) {
+  ///   c.f(0); // error: A::f and B::f come from subobjects of 
diff erent
+  ///           // types. overload resolution is not performed.
+  /// }
+  /// @endcode
+  AmbiguousBaseSubobjectTypes,
+
+  /// Name lookup results in an ambiguity because multiple
+  /// nonstatic entities that meet the lookup criteria were found
+  /// in 
diff erent subobjects of the same type. For example:
+  /// @code
+  /// struct A { int x; };
+  /// struct B : A { };
+  /// struct C : A { };
+  /// struct D : B, C { };
+  /// int test(D d) {
+  ///   return d.x; // error: 'x' is found in two A subobjects (of B and C)
+  /// }
+  /// @endcode
+  AmbiguousBaseSubobjects,
+
+  /// Name lookup results in an ambiguity because multiple definitions
+  /// of entity that meet the lookup criteria were found in 
diff erent
+  /// declaration contexts.
+  /// @code
+  /// namespace A {
+  ///   int i;
+  ///   namespace B { int i; }
+  ///   int test() {
+  ///     using namespace B;
+  ///     return i; // error 'i' is found in namespace A and A::B
+  ///    }
+  /// }
+  /// @endcode
+  AmbiguousReference,
+
+  /// Name lookup results in an ambiguity because multiple placeholder
+  /// variables were found in the same scope.
+  /// @code
+  /// void f() {
+  ///    int _ = 0;
+  ///    int _ = 0;
+  ///    return _; // ambiguous use of placeholder variable
+  /// }
+  /// @endcode
+  AmbiguousReferenceToPlaceholderVariable,
+
+  /// Name lookup results in an ambiguity because an entity with a
+  /// tag name was hidden by an entity with an ordinary name from
+  /// a 
diff erent context.
+  /// @code
+  /// namespace A { struct Foo {}; }
+  /// namespace B { void Foo(); }
+  /// namespace C {
+  ///   using namespace A;
+  ///   using namespace B;
+  /// }
+  /// void test() {
+  ///   C::Foo(); // error: tag 'A::Foo' is hidden by an object in a
+  ///             // 
diff erent namespace
+  /// }
+  /// @endcode
+  AmbiguousTagHiding
+};
+
 /// Represents the results of name lookup.
 ///
 /// An instance of the LookupResult class captures the results of a
@@ -73,79 +146,6 @@ class LookupResult {
     Ambiguous
   };
 
-  enum AmbiguityKind {
-    /// Name lookup results in an ambiguity because multiple
-    /// entities that meet the lookup criteria were found in
-    /// subobjects of 
diff erent types. For example:
-    /// @code
-    /// struct A { void f(int); }
-    /// struct B { void f(double); }
-    /// struct C : A, B { };
-    /// void test(C c) {
-    ///   c.f(0); // error: A::f and B::f come from subobjects of 
diff erent
-    ///           // types. overload resolution is not performed.
-    /// }
-    /// @endcode
-    AmbiguousBaseSubobjectTypes,
-
-    /// Name lookup results in an ambiguity because multiple
-    /// nonstatic entities that meet the lookup criteria were found
-    /// in 
diff erent subobjects of the same type. For example:
-    /// @code
-    /// struct A { int x; };
-    /// struct B : A { };
-    /// struct C : A { };
-    /// struct D : B, C { };
-    /// int test(D d) {
-    ///   return d.x; // error: 'x' is found in two A subobjects (of B and C)
-    /// }
-    /// @endcode
-    AmbiguousBaseSubobjects,
-
-    /// Name lookup results in an ambiguity because multiple definitions
-    /// of entity that meet the lookup criteria were found in 
diff erent
-    /// declaration contexts.
-    /// @code
-    /// namespace A {
-    ///   int i;
-    ///   namespace B { int i; }
-    ///   int test() {
-    ///     using namespace B;
-    ///     return i; // error 'i' is found in namespace A and A::B
-    ///    }
-    /// }
-    /// @endcode
-    AmbiguousReference,
-
-    /// Name lookup results in an ambiguity because multiple placeholder
-    /// variables were found in the same scope.
-    /// @code
-    /// void f() {
-    ///    int _ = 0;
-    ///    int _ = 0;
-    ///    return _; // ambiguous use of placeholder variable
-    /// }
-    /// @endcode
-    AmbiguousReferenceToPlaceholderVariable,
-
-    /// Name lookup results in an ambiguity because an entity with a
-    /// tag name was hidden by an entity with an ordinary name from
-    /// a 
diff erent context.
-    /// @code
-    /// namespace A { struct Foo {}; }
-    /// namespace B { void Foo(); }
-    /// namespace C {
-    ///   using namespace A;
-    ///   using namespace B;
-    /// }
-    /// void test() {
-    ///   C::Foo(); // error: tag 'A::Foo' is hidden by an object in a
-    ///             // 
diff erent namespace
-    /// }
-    /// @endcode
-    AmbiguousTagHiding
-  };
-
   /// A little identifier for flagging temporary lookup results.
   enum TemporaryToken {
     Temporary
@@ -346,7 +346,7 @@ class LookupResult {
     return ResultKind;
   }
 
-  AmbiguityKind getAmbiguityKind() const {
+  LookupAmbiguityKind getAmbiguityKind() const {
     assert(isAmbiguous());
     return Ambiguity;
   }
@@ -532,7 +532,7 @@ class LookupResult {
         Paths = nullptr;
       }
     } else {
-      std::optional<AmbiguityKind> SavedAK;
+      std::optional<LookupAmbiguityKind> SavedAK;
       bool WasAmbiguous = false;
       if (ResultKind == Ambiguous) {
         SavedAK = Ambiguity;
@@ -598,7 +598,7 @@ class LookupResult {
   /// 
diff erent contexts and a tag decl was hidden by an ordinary
   /// decl in a 
diff erent context.
   void setAmbiguousQualifiedTagHiding() {
-    setAmbiguous(AmbiguousTagHiding);
+    setAmbiguous(LookupAmbiguityKind::AmbiguousTagHiding);
   }
 
   /// Clears out any current state.
@@ -769,7 +769,7 @@ class LookupResult {
       getSema().DiagnoseAmbiguousLookup(*this);
   }
 
-  void setAmbiguous(AmbiguityKind AK) {
+  void setAmbiguous(LookupAmbiguityKind AK) {
     ResultKind = Ambiguous;
     Ambiguity = AK;
   }
@@ -792,7 +792,7 @@ class LookupResult {
   LookupResultKind ResultKind = NotFound;
   // ill-defined unless ambiguous. Still need to be initialized it will be
   // copied/moved.
-  AmbiguityKind Ambiguity = {};
+  LookupAmbiguityKind Ambiguity = {};
   UnresolvedSet<8> Decls;
   CXXBasePaths *Paths = nullptr;
   CXXRecordDecl *NamingClass = nullptr;

diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index fe61b92e087d7..b0ebf3e5f47c3 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -483,7 +483,7 @@ ParsedType Sema::getTypeName(const IdentifierInfo &II, 
SourceLocation NameLoc,
     // diagnose the error then.  If we don't do this, then the error
     // about hiding the type will be immediately followed by an error
     // that only makes sense if the identifier was treated like a type.
-    if (Result.getAmbiguityKind() == LookupResult::AmbiguousTagHiding) {
+    if (Result.getAmbiguityKind() == LookupAmbiguityKind::AmbiguousTagHiding) {
       Result.suppressDiagnostics();
       return nullptr;
     }

diff  --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp
index 53f64e91588bf..2e072320e45cc 100644
--- a/clang/lib/Sema/SemaLookup.cpp
+++ b/clang/lib/Sema/SemaLookup.cpp
@@ -337,11 +337,13 @@ bool LookupResult::checkDebugAssumptions() const {
           isa<FunctionTemplateDecl>((*begin())->getUnderlyingDecl())));
   assert(ResultKind != FoundUnresolvedValue || checkUnresolved());
   assert(ResultKind != Ambiguous || Decls.size() > 1 ||
-         (Decls.size() == 1 && (Ambiguity == AmbiguousBaseSubobjects ||
-                                Ambiguity == AmbiguousBaseSubobjectTypes)));
-  assert((Paths != nullptr) == (ResultKind == Ambiguous &&
-                                (Ambiguity == AmbiguousBaseSubobjectTypes ||
-                                 Ambiguity == AmbiguousBaseSubobjects)));
+         (Decls.size() == 1 &&
+          (Ambiguity == LookupAmbiguityKind::AmbiguousBaseSubobjects ||
+           Ambiguity == LookupAmbiguityKind::AmbiguousBaseSubobjectTypes)));
+  assert((Paths != nullptr) ==
+         (ResultKind == Ambiguous &&
+          (Ambiguity == LookupAmbiguityKind::AmbiguousBaseSubobjectTypes ||
+           Ambiguity == LookupAmbiguityKind::AmbiguousBaseSubobjects)));
   return true;
 }
 
@@ -641,9 +643,9 @@ void LookupResult::resolveKind() {
     Ambiguous = true;
 
   if (Ambiguous && ReferenceToPlaceHolderVariable)
-    setAmbiguous(LookupResult::AmbiguousReferenceToPlaceholderVariable);
+    setAmbiguous(LookupAmbiguityKind::AmbiguousReferenceToPlaceholderVariable);
   else if (Ambiguous)
-    setAmbiguous(LookupResult::AmbiguousReference);
+    setAmbiguous(LookupAmbiguityKind::AmbiguousReference);
   else if (HasUnresolved)
     ResultKind = LookupResult::FoundUnresolvedValue;
   else if (N > 1 || HasFunctionTemplate)
@@ -665,7 +667,7 @@ void LookupResult::setAmbiguousBaseSubobjects(CXXBasePaths 
&P) {
   Paths->swap(P);
   addDeclsFromBasePaths(*Paths);
   resolveKind();
-  setAmbiguous(AmbiguousBaseSubobjects);
+  setAmbiguous(LookupAmbiguityKind::AmbiguousBaseSubobjects);
 }
 
 void LookupResult::setAmbiguousBaseSubobjectTypes(CXXBasePaths &P) {
@@ -673,7 +675,7 @@ void 
LookupResult::setAmbiguousBaseSubobjectTypes(CXXBasePaths &P) {
   Paths->swap(P);
   addDeclsFromBasePaths(*Paths);
   resolveKind();
-  setAmbiguous(AmbiguousBaseSubobjectTypes);
+  setAmbiguous(LookupAmbiguityKind::AmbiguousBaseSubobjectTypes);
 }
 
 void LookupResult::print(raw_ostream &Out) {
@@ -2769,7 +2771,7 @@ void Sema::DiagnoseAmbiguousLookup(LookupResult &Result) {
   SourceRange LookupRange = Result.getContextRange();
 
   switch (Result.getAmbiguityKind()) {
-  case LookupResult::AmbiguousBaseSubobjects: {
+  case LookupAmbiguityKind::AmbiguousBaseSubobjects: {
     CXXBasePaths *Paths = Result.getBasePaths();
     QualType SubobjectType = Paths->front().back().Base->getType();
     Diag(NameLoc, diag::err_ambiguous_member_multiple_subobjects)
@@ -2785,7 +2787,7 @@ void Sema::DiagnoseAmbiguousLookup(LookupResult &Result) {
     break;
   }
 
-  case LookupResult::AmbiguousBaseSubobjectTypes: {
+  case LookupAmbiguityKind::AmbiguousBaseSubobjectTypes: {
     Diag(NameLoc, diag::err_ambiguous_member_multiple_subobject_types)
       << Name << LookupRange;
 
@@ -2811,7 +2813,7 @@ void Sema::DiagnoseAmbiguousLookup(LookupResult &Result) {
     break;
   }
 
-  case LookupResult::AmbiguousTagHiding: {
+  case LookupAmbiguityKind::AmbiguousTagHiding: {
     Diag(NameLoc, diag::err_ambiguous_tag_hiding) << Name << LookupRange;
 
     llvm::SmallPtrSet<NamedDecl*, 8> TagDecls;
@@ -2836,7 +2838,7 @@ void Sema::DiagnoseAmbiguousLookup(LookupResult &Result) {
     break;
   }
 
-  case LookupResult::AmbiguousReferenceToPlaceholderVariable: {
+  case LookupAmbiguityKind::AmbiguousReferenceToPlaceholderVariable: {
     Diag(NameLoc, diag::err_using_placeholder_variable) << Name << LookupRange;
     DeclContext *DC = nullptr;
     for (auto *D : Result) {
@@ -2848,7 +2850,7 @@ void Sema::DiagnoseAmbiguousLookup(LookupResult &Result) {
     break;
   }
 
-  case LookupResult::AmbiguousReference: {
+  case LookupAmbiguityKind::AmbiguousReference: {
     Diag(NameLoc, diag::err_ambiguous_reference) << Name << LookupRange;
 
     for (auto *D : Result)


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to