forked from qt-creator/qt-creator
CppEditor: Fix possible crash when following typdefs
It's probably also a bug that we don't resolve the identically-named struct correctly, but at least we don't crash anymore. Fixes: QTCREATORBUG-26047 Change-Id: I272e76460c87906c9df23aaf7f37953b451bf1a8 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -146,7 +146,9 @@ TypeHierarchy TypeHierarchyBuilder::buildDerivedTypeHierarchy(QFutureInterfaceBa
|
||||
return hierarchy;
|
||||
}
|
||||
|
||||
LookupItem TypeHierarchyBuilder::followTypedef(const LookupContext &context, const Name *symbolName, Scope *enclosingScope)
|
||||
LookupItem TypeHierarchyBuilder::followTypedef(const LookupContext &context, const Name *symbolName,
|
||||
Scope *enclosingScope,
|
||||
std::set<const Symbol *> typedefs)
|
||||
{
|
||||
QList<LookupItem> items = context.lookup(symbolName, enclosingScope);
|
||||
|
||||
@@ -159,6 +161,8 @@ LookupItem TypeHierarchyBuilder::followTypedef(const LookupContext &context, con
|
||||
continue;
|
||||
if (!s->isClass() && !s->isTemplate() && !s->isTypedef())
|
||||
continue;
|
||||
if (!typedefs.insert(s).second)
|
||||
continue;
|
||||
actualBaseSymbol = s;
|
||||
matchingItem = item;
|
||||
break;
|
||||
@@ -173,7 +177,8 @@ LookupItem TypeHierarchyBuilder::followTypedef(const LookupContext &context, con
|
||||
// Anonymous aggregate such as: typedef struct {} Empty;
|
||||
return LookupItem();
|
||||
}
|
||||
return followTypedef(context, namedType->name(), actualBaseSymbol->enclosingScope());
|
||||
return followTypedef(context, namedType->name(), actualBaseSymbol->enclosingScope(),
|
||||
typedefs);
|
||||
}
|
||||
|
||||
return matchingItem;
|
||||
|
||||
@@ -34,6 +34,8 @@
|
||||
#include <QList>
|
||||
#include <QSet>
|
||||
|
||||
#include <set>
|
||||
|
||||
namespace CPlusPlus {
|
||||
class LookupContext;
|
||||
class LookupItem;
|
||||
@@ -72,7 +74,8 @@ public:
|
||||
const CPlusPlus::Snapshot &snapshot);
|
||||
static CPlusPlus::LookupItem followTypedef(const CPlusPlus::LookupContext &context,
|
||||
const CPlusPlus::Name *symbolName,
|
||||
CPlusPlus::Scope *enclosingScope);
|
||||
CPlusPlus::Scope *enclosingScope,
|
||||
std::set<const CPlusPlus::Symbol *> typedefs = {});
|
||||
private:
|
||||
TypeHierarchyBuilder() = default;
|
||||
void buildDerived(QFutureInterfaceBase &futureInterface, TypeHierarchy *typeHierarchy,
|
||||
|
||||
Reference in New Issue
Block a user