C++: Check for cycled parents

In the struct _Wrap_alloc (see test code) the rebind struct has
_Wrap_alloc as parent. However, within rebind the typedef of type
_Wrap_alloc has rebind as parent.

We will refactor that in master by introducing a "parent iterator"
class checking for cycles, so the client code looks less noisy.

Task-number: QTCREATORBUG-13703
Change-Id: I7b6cf819ea869139d2403e15ba085d8fba19763e
Reviewed-by: Cristian Adam <cristian.adam@gmail.com>
Reviewed-by: Przemyslaw Gorszkowski <pgorszkowski@gmail.com>
Reviewed-by: Eike Ziller <eike.ziller@theqtcompany.com>
Reviewed-by: Erik Verbruggen <erik.verbruggen@theqtcompany.com>
This commit is contained in:
Nikolai Kosjar
2015-01-20 12:33:51 +01:00
committed by Nikolai Kosjar
parent 309d38c8f0
commit 56dab9e931
2 changed files with 86 additions and 28 deletions

View File

@@ -631,10 +631,15 @@ QList<LookupItem> ClassOrNamespace::lookup_helper(const Name *name, bool searchI
// a qualified name. For instance, a nested class which is forward declared
// in the class but defined outside it - we should capture both.
Symbol *match = 0;
QSet<ClassOrNamespace *> processed;
for (ClassOrNamespace *parentBinding = binding->parent();
parentBinding && !match;
parentBinding = parentBinding->parent())
parentBinding = parentBinding->parent()) {
if (processed.contains(parentBinding))
break;
processed.insert(parentBinding);
match = parentBinding->lookupInScope(fullName);
}
if (match) {
LookupItem item;
@@ -648,8 +653,12 @@ QList<LookupItem> ClassOrNamespace::lookup_helper(const Name *name, bool searchI
}
QSet<ClassOrNamespace *> processed;
QSet<ClassOrNamespace *> processedOwnParents;
ClassOrNamespace *binding = this;
do {
if (processedOwnParents.contains(binding))
break;
processedOwnParents.insert(binding);
lookup_helper(name, binding, &result, &processed, /*templateId = */ 0);
binding = binding->_parent;
} while (searchInEnclosingScope && binding);