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

Ilya Biryukov via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 14 05:33:04 PST 2023


================
@@ -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 missed that `getInstantiatedFromMemberTemplate` will be null for non-member template function instantiations.
So I guess we still need it.

Could we add a test with two non-member templates that do **not** match each other and check the ambiguity is still there?

```
template <class T> bool operator ==(Foo<T>, Foo<T*>);
template <class T> bool operator ==(Foo<T*>, Foo<T>);

Foo<int*>() == Foo<int*>;
```

Because it's weird that `declaresSameEntity(nullptr, nullptr)` returns `false`, I'm worried that we miss a point where someone changes it to return `true` and we would get `declaresSameEntity(primary-template-1, primary-template-2) || true /*declaresSameEntity(null, null)*/` and start turning real ambiguities to warnings accidentally. It's useful to have a test that explicitly guards against that.

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


More information about the cfe-commits mailing list