Issue |
148610
|
Summary |
[clang] Compiler fails to detect infinite recursion in `A<T, T>`-style nested templates
|
Labels |
clang
|
Assignees |
|
Reporter |
GitSparTV
|
```cpp
template <typename T, typename U = T>
class A {};
template <typename T>
void RecursiveFunction(T t) {
RecursiveFunction(A<T>());
}
int main() { RecursiveFunction(42); }
```
> Demo: https://godbolt.org/z/jbTWh1Kej
Compiler is able to detect recursion in cases like $\text{A<...A\<T\>...>}$, but not in $\text{A<...A\<T\>..., ...A\<T\>...>}$.
In other words this is what happens in the example: $T_0 = \texttt{B}, \quad T_{n+1} = \texttt{A<}T_n,\ T_n\texttt{>}$
All major compilers don't generate any information, just eating RAM and stack space.
Another example where the generated template can be examined: https://godbolt.org/z/MKdcqbqjW
Here you can see `Add` function is instantiated with:
`unique_ptr<D, D>` -> `unique_ptr<unique_ptr<D, D>, unique_ptr<D, D>>` -> `unique_ptr<unique_ptr<unique_ptr<D, D>, unique_ptr<D, D>>, unique_ptr<unique_ptr<D, D>, unique_ptr<D, D>>>` -> and so on
This bug was found when using real `std::unique_ptr`, since it has 2 parameters both of which are dependent on `T`, current recursion detection doesn't work.
Real example: https://godbolt.org/z/6TK94576j
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs