Issue 64725
Summary [AST] Question about ADL lookup & structural equivalence of produced templates
Labels new issue
Assignees
Reporter danix800
    1. Without overloaded `operator+`:
```c
template <class T, T v>
struct integral_constant { static constexpr const T value = v; };

template <int N>
constexpr const int a = integral_constant<int,  N>::value + 1;
```
produces plain `BinaryOperator +` for `a`:
```c
  VarTemplateDecl 0x5622692efab0 <line:13:1, line:14:61> col:21 a
  |-NonTypeTemplateParmDecl 0x5622692c1780 <line:13:11, col:15> col:15 referenced 'int' depth 0 index 0 N
  `-VarDecl 0x5622692c1810 <line:14:1, col:61> col:21 a 'const int' constexpr cinit
    `-BinaryOperator 0x5622692efd28 <col:25, col:61> '<dependent type>' '+'
      |-DependentScopeDeclRefExpr 0x5622692efcd0 <col:25, col:53> '<dependent type>' lvalue
      `-IntegerLiteral 0x5622692efd08 <col:61> 'int' 1
```
2. With overloaded `operator+`:
```c
template <class T> class A {};

template <class T> A<T> operator+(int N, const A<T> &X) { return A<T>(); }

template <class T, T v>
struct integral_constant { static constexpr const T value = v; };

template <int N>
constexpr const int a = integral_constant<int,  N>::value + 1;
```
produces overloaded `CXXOperatorCallExpr +` for `a`:
```c
  VarTemplateDecl 0x560e6a7e6ee8 <line:8:1, line:9:61> col:21 a
  |-NonTypeTemplateParmDecl 0x560e6a7e6df0 <line:8:11, col:15> col:15 referenced 'int' depth 0 index 0 N
  `-VarDecl 0x560e6a7e6e80 <line:9:1, col:61> col:21 a 'const int' constexpr cinit
 `-CXXOperatorCallExpr 0x560e6a7e7190 <col:25, col:61> '<dependent type>' '+'
      |-UnresolvedLookupExpr 0x560e6a7e7148 <col:59> '<overloaded function type>' lvalue (ADL) = 'operator+' 0x560e6a7b83c8
 |-DependentScopeDeclRefExpr 0x560e6a7e70f0 <col:25, col:53> '<dependent type>' lvalue
      `-IntegerLiteral 0x560e6a7e7128 <col:61> 'int' 1
```

Current ASTStructuralEquivalence.cpp implementation considers the two variable templates of `a` as inequivalent.
So I'm wondering which part could be the problem.
1. Is this overload resolution correct? If not then what's the correct one? Otherwise,
2. Should these two variable templates be considered as equivalent? If true, then then equivalence algorithm might
    need improved in this case.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to