C++: Limit template instantiation depth

A recursive template generates infinite expansions.

Consider the following example:

template <class R1>
struct Base
{
};

template<typename R>
struct Derived :
  Base<
    typename Derived<typename Base<R>::type>::type,
    typename Derived<typename Base<R>::type>::type
  >::type
{};

R is instantiated as Base<R>::type, which causes another
instantiation of R into Base<Base<R>> etc...

This is not a solution, but a workaround.

Task-number: QTCREATORBUG-15141
Change-Id: Ib04f70275e07919e2cb6c7fb61a2045bd52f4a7d
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
This commit is contained in:
Orgad Shaneh
2015-11-11 23:13:19 +02:00
committed by Orgad Shaneh
parent a27cd12538
commit 0bcddcd014
3 changed files with 28 additions and 0 deletions

View File

@@ -209,6 +209,7 @@ private:
LookupScope *_globalNamespace;
LookupScope *_currentLookupScope;
bool _expandTemplates;
int _depth;
};
class CPLUSPLUS_EXPORT LookupContext