[clang] [clang] Reapply Handle templated operators with reversed arguments (PR #72213)

Ilya Biryukov via cfe-commits cfe-commits at lists.llvm.org
Fri Jan 12 02:02:31 PST 2024


================
@@ -10088,9 +10088,13 @@ static bool allowAmbiguity(ASTContext &Context, const FunctionDecl *F1,
                            const FunctionDecl *F2) {
   if (declaresSameEntity(F1, F2))
     return true;
-  if (F1->isTemplateInstantiation() && F2->isTemplateInstantiation() &&
-      declaresSameEntity(F1->getPrimaryTemplate(), F2->getPrimaryTemplate())) {
-    return true;
+  if (F1->isTemplateInstantiation() && F2->isTemplateInstantiation()) {
+    auto PT1 = F1->getPrimaryTemplate();
+    auto PT2 = F2->getPrimaryTemplate();
+    if (declaresSameEntity(PT1, PT2) ||
----------------
ilya-biryukov wrote:

I believe your godbolt invocation is incomplete, it misses the actual comparisons. My example also needs an update to actually get some reasonably-looking code, see https://godbolt.org/z/G4914bf3z:

```cpp
template <class T>
struct Foo {};
template <class T, class U> bool operator==(Foo<U>, Foo<T*>);
template <class T, class U> bool operator==(Foo<T*>, Foo<U>);

void test() {
    Foo<int*>() == Foo<int*>();
}
```

I think that's supposed to excercise the code path I was referring to. Could we add this test case?

https://github.com/llvm/llvm-project/pull/72213


More information about the cfe-commits mailing list