Author: Vlad Serebrennikov Date: 2025-05-02T13:44:32+03:00 New Revision: 6e63b68389983194b5007d8d489e74d1ffcea500
URL: https://github.com/llvm/llvm-project/commit/6e63b68389983194b5007d8d489e74d1ffcea500 DIFF: https://github.com/llvm/llvm-project/commit/6e63b68389983194b5007d8d489e74d1ffcea500.diff LOG: [clang][NFC] Convert `Sema::OverloadKind` to scoped enum Added: Modified: clang/include/clang/Sema/Sema.h clang/lib/Sema/SemaDecl.cpp clang/lib/Sema/SemaDeclCXX.cpp clang/lib/Sema/SemaOverload.cpp Removed: ################################################################################ diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index 9896caaf41a5f..41582096f7dc1 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -804,6 +804,20 @@ enum class CorrectTypoKind { ErrorRecovery // CorrectTypo used in normal error recovery. }; +enum class OverloadKind { + /// This is a legitimate overload: the existing declarations are + /// functions or function templates with diff erent signatures. + Overload, + + /// This is not an overload because the signature exactly matches + /// an existing declaration. + Match, + + /// This is not an overload because the lookup results contain a + /// non-function. + NonFunction +}; + /// Sema - This implements semantic analysis and AST building for C. /// \nosubgrouping class Sema final : public SemaBase { @@ -9987,28 +10001,14 @@ class Sema final : public SemaBase { /// if Sema is already doing so, which would cause infinite recursions. bool IsBuildingRecoveryCallExpr; - enum OverloadKind { - /// This is a legitimate overload: the existing declarations are - /// functions or function templates with diff erent signatures. - Ovl_Overload, - - /// This is not an overload because the signature exactly matches - /// an existing declaration. - Ovl_Match, - - /// This is not an overload because the lookup results contain a - /// non-function. - Ovl_NonFunction - }; - /// Determine whether the given New declaration is an overload of the - /// declarations in Old. This routine returns Ovl_Match or Ovl_NonFunction if - /// New and Old cannot be overloaded, e.g., if New has the same signature as - /// some function in Old (C++ 1.3.10) or if the Old declarations aren't - /// functions (or function templates) at all. When it does return Ovl_Match or - /// Ovl_NonFunction, MatchedDecl will point to the decl that New cannot be - /// overloaded with. This decl may be a UsingShadowDecl on top of the - /// underlying declaration. + /// declarations in Old. This routine returns OverloadKind::Match or + /// OverloadKind::NonFunction if New and Old cannot be overloaded, e.g., if + /// New has the same signature as some function in Old (C++ 1.3.10) or if the + /// Old declarations aren't functions (or function templates) at all. When it + /// does return OverloadKind::Match or OverloadKind::NonFunction, MatchedDecl + /// will point to the decl that New cannot be overloaded with. This decl may + /// be a UsingShadowDecl on top of the underlying declaration. /// /// Example: Given the following input: /// @@ -10021,14 +10021,15 @@ class Sema final : public SemaBase { /// /// When we process #2, Old contains only the FunctionDecl for #1. By /// comparing the parameter types, we see that #1 and #2 are overloaded (since - /// they have diff erent signatures), so this routine returns Ovl_Overload; - /// MatchedDecl is unchanged. + /// they have diff erent signatures), so this routine returns + /// OverloadKind::Overload; MatchedDecl is unchanged. /// /// When we process #3, Old is an overload set containing #1 and #2. We /// compare the signatures of #3 to #1 (they're overloaded, so we do nothing) /// and then #3 to #2. Since the signatures of #3 and #2 are identical (return /// types of functions are not part of the signature), IsOverload returns - /// Ovl_Match and MatchedDecl will be set to point to the FunctionDecl for #2. + /// OverloadKind::Match and MatchedDecl will be set to point to the + /// FunctionDecl for #2. /// /// 'NewIsUsingShadowDecl' indicates that 'New' is being introduced into a /// class by a using declaration. The rules for whether to hide shadow diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 329013471c934..829207b4cf910 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -12032,15 +12032,15 @@ bool Sema::CheckFunctionDeclaration(Scope *S, FunctionDecl *NewFD, MayNeedOverloadableChecks = true; switch (CheckOverload(S, NewFD, Previous, OldDecl, /*NewIsUsingDecl*/ false)) { - case Ovl_Match: + case OverloadKind::Match: Redeclaration = true; break; - case Ovl_NonFunction: + case OverloadKind::NonFunction: Redeclaration = true; break; - case Ovl_Overload: + case OverloadKind::Overload: Redeclaration = false; break; } diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index 55e2129bf46a2..6e6e39acc1cb3 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -12797,15 +12797,15 @@ bool Sema::CheckUsingShadowDecl(BaseUsingDecl *BUD, NamedDecl *Orig, NamedDecl *OldDecl = nullptr; switch (CheckOverload(nullptr, FD, Previous, OldDecl, /*IsForUsingDecl*/ true)) { - case Ovl_Overload: + case OverloadKind::Overload: return false; - case Ovl_NonFunction: + case OverloadKind::NonFunction: Diag(BUD->getLocation(), diag::err_using_decl_conflict); break; // We found a decl with the exact signature. - case Ovl_Match: + case OverloadKind::Match: // If we're in a record, we want to hide the target, so we // return true (without a diagnostic) to tell the caller not to // build a shadow decl. diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp index de2382ffdf1e8..ead87ab8236e9 100644 --- a/clang/lib/Sema/SemaOverload.cpp +++ b/clang/lib/Sema/SemaOverload.cpp @@ -1200,9 +1200,9 @@ static bool checkArgPlaceholdersForOverload(Sema &S, MultiExprArg Args, return false; } -Sema::OverloadKind -Sema::CheckOverload(Scope *S, FunctionDecl *New, const LookupResult &Old, - NamedDecl *&Match, bool NewIsUsingDecl) { +OverloadKind Sema::CheckOverload(Scope *S, FunctionDecl *New, + const LookupResult &Old, NamedDecl *&Match, + bool NewIsUsingDecl) { for (LookupResult::iterator I = Old.begin(), E = Old.end(); I != E; ++I) { NamedDecl *OldD = *I; @@ -1244,14 +1244,14 @@ Sema::CheckOverload(Scope *S, FunctionDecl *New, const LookupResult &Old, continue; Match = *I; - return Ovl_Match; + return OverloadKind::Match; } // Builtins that have custom typechecking or have a reference should // not be overloadable or redeclarable. if (!getASTContext().canBuiltinBeRedeclared(OldF)) { Match = *I; - return Ovl_NonFunction; + return OverloadKind::NonFunction; } } else if (isa<UsingDecl>(OldD) || isa<UsingPackDecl>(OldD)) { // We can overload with these, which can show up when doing @@ -1268,14 +1268,14 @@ Sema::CheckOverload(Scope *S, FunctionDecl *New, const LookupResult &Old, // member, the using declaration can only introduce an enumerator. if (UUD->getQualifier()->isDependent() && !UUD->isCXXClassMember()) { Match = *I; - return Ovl_NonFunction; + return OverloadKind::NonFunction; } } else { // (C++ 13p1): // Only function declarations can be overloaded; object and type // declarations cannot be overloaded. Match = *I; - return Ovl_NonFunction; + return OverloadKind::NonFunction; } } @@ -1303,14 +1303,14 @@ Sema::CheckOverload(Scope *S, FunctionDecl *New, const LookupResult &Old, if (CheckFunctionTemplateSpecialization(New, nullptr, TemplateSpecResult, /*QualifiedFriend*/true)) { New->setInvalidDecl(); - return Ovl_Overload; + return OverloadKind::Overload; } Match = TemplateSpecResult.getAsSingle<FunctionDecl>(); - return Ovl_Match; + return OverloadKind::Match; } - return Ovl_Overload; + return OverloadKind::Overload; } template <typename AttrT> static bool hasExplicitAttr(const FunctionDecl *D) { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits