Description
template <typename T, typename U = T>
class A {};
template <typename T>
void RecursiveFunction(T t) {
RecursiveFunction(A<T>());
}
int main() { RecursiveFunction(42); }
Compiler is able to detect recursion in cases like
In other words this is what happens in the example:
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