Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recognize friend operator != to fix ambiguity with operator== #70213

Closed
wants to merge 4 commits into from

Conversation

usx95
Copy link
Contributor

@usx95 usx95 commented Oct 25, 2023

The namespace lookup should give a matching friend operator!= as friend functions belong to the namespace scope (as opposed to the lexical class scope).

Thus to resolve ambiguity of operator== with itself, defining a corresponding friend operator!= should suffice.

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Oct 25, 2023
@usx95 usx95 closed this Oct 25, 2023
@github-actions
Copy link

⚠️ C/C++ code formatter, clang-format found issues in your code. ⚠️

You can test this locally with the following command:
git-clang-format --diff 84d8ace51a5afb07b528f65cde091cf3dbd7c326 183209f71b08a1fdba335d89c906cd26483115c1 -- clang/lib/Sema/SemaOverload.cpp clang/test/CXX/over/over.match/over.match.funcs/over.match.oper/p3-2a.cpp
View the diff from clang-format here.
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 30bde49636b2..807a07a35d69 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -12119,8 +12119,7 @@ struct CompareOverloadCandidatesForDisplay {
         int leftBetter = 0;
         unsigned I = (L->IgnoreObjectArgument || R->IgnoreObjectArgument);
         for (unsigned E = L->Conversions.size(); I != E; ++I) {
-          switch (CompareImplicitConversionSequences(S, Loc,
-                                                     L->Conversions[I],
+          switch (CompareImplicitConversionSequences(S, Loc, L->Conversions[I],
                                                      R->Conversions[I])) {
           case ImplicitConversionSequence::Better:
             leftBetter++;
@@ -12134,8 +12133,10 @@ struct CompareOverloadCandidatesForDisplay {
             break;
           }
         }
-        if (leftBetter > 0) return true;
-        if (leftBetter < 0) return false;
+        if (leftBetter > 0)
+          return true;
+        if (leftBetter < 0)
+          return false;
 
       } else if (RFailureKind == ovl_fail_bad_conversion)
         return false;
@@ -12158,13 +12159,15 @@ struct CompareOverloadCandidatesForDisplay {
     SourceLocation RLoc = GetLocationForCandidate(R);
 
     // Put candidates without locations (e.g. builtins) at the end.
-    if (LLoc.isInvalid()) return false;
-    if (RLoc.isInvalid()) return true;
+    if (LLoc.isInvalid())
+      return false;
+    if (RLoc.isInvalid())
+      return true;
 
     return S.SourceMgr.isBeforeInTranslationUnit(LLoc, RLoc);
   }
 };
-}
+} // namespace
 
 /// CompleteNonViableCandidate - Normally, overload resolution only
 /// computes up to the first bad conversion. Produces the FixIt set if

@usx95 usx95 deleted the equals-operator-68901 branch October 25, 2023 15:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants