C++: fix 'using' for templates in typedefs

Fix resolving typedef of templates which is from different namespace
and there was 'using' used for it.
Examples are in tests.
Another step to bring code completion for stl containters.

Task-number: QTCREATORBUG-7978

Change-Id: I2e9e71b45d60536c1e25cf2d371c4719b15edf79
Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
This commit is contained in:
Przemyslaw Gorszkowski
2013-02-21 15:06:02 +01:00
committed by Erik Verbruggen
parent ea32191542
commit 798d84b391
4 changed files with 119 additions and 2 deletions

View File

@@ -752,6 +752,12 @@ ClassOrNamespace *ClassOrNamespace::nestedType(const Name *name, ClassOrNamespac
const TemplateNameId *templId = name->asTemplateNameId();
if (templId) {
// for "using" we should use the real one ClassOrNamespace(it should be the first
// one item from usings list)
// we indicate that it is a 'using' by checking number of symbols(it should be 0)
if (reference->symbols().count() == 0 && reference->usings().count() != 0)
reference = reference->_usings[0];
// if it is a TemplateNameId it could be a specialization(full or partial) or
// instantiation of one of the specialization(reference->_specialization) or
// base class(reference)

View File

@@ -835,8 +835,9 @@ public:
void resolve(FullySpecifiedType *type, Scope **scope, ClassOrNamespace *binding)
{
QSet<Symbol *> visited;
_binding = binding;
while (NamedType *namedTy = getNamedType(*type)) {
QList<LookupItem> namedTypeItems = getNamedTypeItems(namedTy->name(), *scope, binding);
QList<LookupItem> namedTypeItems = getNamedTypeItems(namedTy->name(), *scope, _binding);
#ifdef DEBUG_LOOKUP
qDebug() << "-- we have" << namedTypeItems.size() << "candidates";
@@ -908,7 +909,7 @@ private:
}
bool findTypedef(const QList<LookupItem>& namedTypeItems, FullySpecifiedType *type,
Scope **scope, QSet<Symbol *>& visited) const
Scope **scope, QSet<Symbol *>& visited)
{
bool foundTypedef = false;
foreach (const LookupItem &it, namedTypeItems) {
@@ -921,6 +922,7 @@ private:
// continue working with the typedefed type and scope
*type = declaration->type();
*scope = it.scope();
_binding = it.binding();
foundTypedef = true;
break;
}
@@ -930,6 +932,8 @@ private:
}
const LookupContext &_context;
// binding has to be remembered in case of resolving typedefs for templates
ClassOrNamespace *_binding;
};
ClassOrNamespace *ResolveExpression::baseExpression(const QList<LookupItem> &baseResults,