Commit 5416557a authored by Przemyslaw Gorszkowski's avatar Przemyslaw Gorszkowski Committed by Nikolai Kosjar
Browse files

C++: fix findusage for member of typedefed anonymous struct



Task-number: QTCREATORBUG-11859
Task-number: QTCREATORBUG-11860
Change-Id: I7484b3b88daefbb3c76bb86a9b573e8291072872
Reviewed-by: Orgad Shaneh's avatarOrgad Shaneh <orgads@gmail.com>
Reviewed-by: default avatarNikolai Kosjar <nikolai.kosjar@digia.com>
parent 589945b7
......@@ -675,7 +675,7 @@ void ClassOrNamespace::lookup_helper(const Name *name, ClassOrNamespace *binding
for (; cit != citEnd; ++cit) {
const AnonymousNameId *anonymousNameId = cit.key();
ClassOrNamespace *a = cit.value();
if (!binding->_declaredAnonymouses.contains(anonymousNameId))
if (!binding->_declaredOrTypedefedAnonymouses.contains(anonymousNameId))
lookup_helper(name, a, result, processed, binding->_templateId);
}
}
......@@ -1580,10 +1580,11 @@ bool CreateBindings::visit(Declaration *decl)
}
}
}
} else if (Class *clazz = decl->type()->asClassType()) {
}
if (Class *clazz = decl->type()->asClassType()) {
if (const Name *name = clazz->name()) {
if (const AnonymousNameId *anonymousNameId = name->asAnonymousNameId())
_currentClassOrNamespace->_declaredAnonymouses.insert(anonymousNameId);
_currentClassOrNamespace->_declaredOrTypedefedAnonymouses.insert(anonymousNameId);
}
}
return false;
......
......@@ -143,7 +143,7 @@ private:
TemplateNameIdTable _specializations;
QMap<const TemplateNameId *, ClassOrNamespace *> _instantiations;
Anonymouses _anonymouses;
QSet<const AnonymousNameId *> _declaredAnonymouses;
QSet<const AnonymousNameId *> _declaredOrTypedefedAnonymouses;
QHash<Internal::FullyQualifiedName, Symbol *> *_scopeLookupCache;
......
......@@ -104,6 +104,7 @@ private Q_SLOTS:
void templateFunctionParameters();
void anonymousClass_QTCREATORBUG8963();
void anonymousClass_QTCREATORBUG11859();
void using_insideGlobalNamespace();
void using_insideNamespace();
void using_insideFunction();
......@@ -562,6 +563,49 @@ void tst_FindUsages::anonymousClass_QTCREATORBUG8963()
QCOMPARE(findUsages.usages().size(), 2);
}
void tst_FindUsages::anonymousClass_QTCREATORBUG11859()
{
const QByteArray src =
"struct Foo {\n"
"};\n"
"typedef struct {\n"
" int Foo;\n"
"} Struct;\n"
"void foo()\n"
"{\n"
" Struct s;\n"
" s.Foo;\n"
"}\n"
;
Document::Ptr doc = Document::create("anonymousClass_QTCREATORBUG11859");
doc->setUtf8Source(src);
doc->parse();
doc->check();
QVERIFY(doc->diagnosticMessages().isEmpty());
QCOMPARE(doc->globalSymbolCount(), 4U);
Snapshot snapshot;
snapshot.insert(doc);
Class *fooAsStruct = doc->globalSymbolAt(0)->asClass();
QVERIFY(fooAsStruct);
Class *structSymbol = doc->globalSymbolAt(1)->asClass();
QVERIFY(structSymbol);
QCOMPARE(structSymbol->memberCount(), 1U);
Declaration *fooAsMemberOfAnonymousStruct = structSymbol->memberAt(0)->asDeclaration();
QVERIFY(fooAsMemberOfAnonymousStruct);
QCOMPARE(fooAsMemberOfAnonymousStruct->name()->identifier()->chars(), "Foo");
FindUsages findUsages(src, doc, snapshot);
findUsages(fooAsStruct);
QCOMPARE(findUsages.references().size(), 1);
findUsages(fooAsMemberOfAnonymousStruct);
QCOMPARE(findUsages.references().size(), 2);
}
void tst_FindUsages::using_insideGlobalNamespace()
{
const QByteArray src =
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment