<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/55614>55614</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [clang-tidy] Infinity templates recursion causing clang-tidy to crash
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          datacompboy
      </td>
    </tr>
</table>

<pre>
    Minimal repro is:

```
template<typename T> struct t1;
template<typename T> struct t2: t1< T > {};
template<typename T> struct t1: t2< T > {};


int main() {
  t1<int> a;
  return 0;
}
```

Causing stack-crash in infinity chain of
```
clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor::classIsDerivedFrom()
```

this can't be compiled by clang either, but doesn't trigger recursion.

It does trigger recursion in clang with
```
template<typename T> struct t1: t2< t1< T > > {};
```
or
```
template<typename T> struct t1: t2< t2< T > > {};
```

but the recursion is cut with correct error:
> mint.cpp:4:33: note: use -ftemplate-depth=N to increase recursive template instantiation depth

so only clang_tidy is affected.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJylVMFunDAQ_RpzGS0CAyEcOGx2GymH9NKo18gYA26NjWyTaP--Y5xNtmpapa1kDPbMvHl-zLgz_am9l1rOTIEVizUgHSn2JDuS7DxfZS9jW3oxL4p5QYqDPy1Cs1nAAyk-gfN25R58ToqbD7pSTLUFHOABgoHUN6Q-fhwg3wDobwEuZ6k9zExqQq8JbTbPbR8iAzQHAPYaCyiIX62G7A0Ood_TJM4HtjqpRyTH-Pcdt8xNIDWOAQX2J-ATZgczvAvBFdNjUL7YM-cfZ-b5JKyLO8hNWM1UXOEBmDb6NJvVQdDELYwLPFM034fQ_ZeHr9JJb2zcRHjn7txRWPkk-ltr5ijDH47jJ-mAM9Sr9tAJ4GZepBI9dHiUwBaE9MiR0AN0q4feCBedvZXjKCzqx1frpNHpJe5ddP3VK4gVgZ8R-J-L71wQP9XVO6XxMzIK9d8J6d8kjHMQDkW8FAFFx80gAUpu0eBBWBt_ZIxE7BlLIuXLgpslPkURaGgTiO5hdQJ2w5n6rhcLylkcP4PH9tbcCuZeMz4JODuiDUtXe8l8IBLDLrg6A0arl5__6GV_CmTZMCBF0adJ3xZ9UzQs8dIr0ZLqZvPcBU9SHeHu3AjnhO7i2Pyled5CAtutiZLVqnbyftm6gd7iGFGdtUt5KONbpZ7Orx3eYN-QDi6lc6tw-FFVV3mZTG1Tl311zXne8Jpdd1WTdz0dsjwbOlHxpkwU64RygTehVItn2CDwG8knsqUZpVlFs7yqaElTXl9lxVA2dOgbWpcZKTOB14tKA4_U2DGx7UapW0eHRiWdd29GbEc5arHJFPDZ6idj257h5YGN1plTsqVvN_o_ANMLtjE">