C++: fix endless loop during template instantiation

This is the first phase of fixing bug QTCREATORBUG-10320.
This change resolves typedefs of template parameters(and resolves
problem with endless loop).

The next step will be matching appropriate template specialization
(this is needed to solve problem with missing code completion).

Missing matching: template specialization with the same parameters,
e.g.:
template <class T1, class T2, class T3>
class T
{
};

template <class T1, class T2>
class T<T1, T2, T2>
{
};

Task-number: QTCREATORBUG-10320
Change-Id: Icb6b539c021b2a67a66db9011a2e627f7d96526b
Reviewed-by: Przemyslaw Gorszkowski <pgorszkowski@gmail.com>
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@digia.com>
This commit is contained in:
Przemyslaw Gorszkowski
2013-10-10 12:43:24 +02:00
committed by Nikolai Kosjar
parent 0224ec0a64
commit 5be56c073e
3 changed files with 78 additions and 0 deletions

View File

@@ -887,6 +887,22 @@ public:
QSet<Symbol *> visited;
_binding = binding;
while (NamedType *namedTy = getNamedType(*type)) {
const Name *name = namedTy->name();
Scope *templateScope = *scope;
if (const QualifiedNameId *q = name->asQualifiedNameId()) {
do {
const TemplateNameId *templateNameId = 0;
name = q->name();
if (name && (templateNameId = name->asTemplateNameId()))
resolve(templateNameId, templateScope, binding);
name = q->base();
if (name && (templateNameId = name->asTemplateNameId()))
resolve(templateNameId, templateScope, binding);
} while ((name && (q = name->asQualifiedNameId())));
} else if (const TemplateNameId *templateNameId = name->asTemplateNameId()) {
resolve(templateNameId, templateScope, binding);
}
QList<LookupItem> namedTypeItems = getNamedTypeItems(namedTy->name(), *scope, _binding);
#ifdef DEBUG_LOOKUP
@@ -899,6 +915,16 @@ public:
}
private:
void resolve(const TemplateNameId *templateNameId, Scope *templateScope,
ClassOrNamespace *binding)
{
for (unsigned i = 0; i < templateNameId->templateArgumentCount(); ++i) {
FullySpecifiedType &templateArgumentType
= const_cast<FullySpecifiedType &>(templateNameId->templateArgumentAt(i));
resolve(&templateArgumentType, &templateScope, binding);
}
}
NamedType *getNamedType(FullySpecifiedType& type) const
{
NamedType *namedTy = type->asNamedType();