C++: fixed operator* for nested class of enclosing template class

Fixed:
* highlighting
* follow symbol
* find usage

Task-number: QTCREATORBUG-9006

Change-Id: I34a42f8665335857f41290217e7265e8a752455b
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
Reviewed-by: Sergey Shambir <sergey.shambir.auto@gmail.com>
Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
This commit is contained in:
Przemyslaw Gorszkowski
2013-04-02 23:04:12 +02:00
committed by Erik Verbruggen
parent be085863fc
commit 7c74482ad3
4 changed files with 99 additions and 1 deletions

View File

@@ -124,7 +124,11 @@ public:
QByteArray preprocessedExpression(const QByteArray &utf8code) const; QByteArray preprocessedExpression(const QByteArray &utf8code) const;
void setExpandTemplates(bool expandTemplates) void setExpandTemplates(bool expandTemplates)
{ m_expandTemplates = expandTemplates; } {
if (m_bindings)
m_bindings->setExpandTemplates(expandTemplates);
m_expandTemplates = expandTemplates;
}
private: private:

View File

@@ -321,6 +321,7 @@ struct CanonicalSymbol
: editor(editor), info(info) : editor(editor), info(info)
{ {
typeOfExpression.init(info.doc, info.snapshot); typeOfExpression.init(info.doc, info.snapshot);
typeOfExpression.setExpandTemplates(true);
} }
const LookupContext &context() const const LookupContext &context() const

View File

@@ -179,6 +179,7 @@ private slots:
void test_checksymbols_QTCREATORBUG8890_danglingPointer(); void test_checksymbols_QTCREATORBUG8890_danglingPointer();
void test_checksymbols_QTCREATORBUG8974_danglingPointer(); void test_checksymbols_QTCREATORBUG8974_danglingPointer();
void operatorAsteriskOfNestedClassOfTemplateClass_QTCREATORBUG9006();
}; };
void tst_CheckSymbols::test_checksymbols_TypeUse() void tst_CheckSymbols::test_checksymbols_TypeUse()
@@ -1233,5 +1234,51 @@ void tst_CheckSymbols::test_checksymbols_QTCREATORBUG8974_danglingPointer()
TestData::check(source, expectedUses); TestData::check(source, expectedUses);
} }
void tst_CheckSymbols::operatorAsteriskOfNestedClassOfTemplateClass_QTCREATORBUG9006()
{
const QByteArray source =
"struct Foo { int foo; };\n"
"\n"
"template<class T>\n"
"struct Outer\n"
"{\n"
" struct Nested\n"
" {\n"
" const T &operator*() { return t; }\n"
" T t;\n"
" };\n"
"};\n"
"\n"
"void bug()\n"
"{\n"
" Outer<Foo>::Nested nested;\n"
" (*nested).foo;\n"
"}\n"
;
const QList<Use> expectedUses = QList<Use>()
<< Use(1, 8, 3, SemanticInfo::TypeUse)
<< Use(1, 18, 3, SemanticInfo::FieldUse)
<< Use(3, 16, 1, SemanticInfo::TypeUse)
<< Use(4, 8, 5, SemanticInfo::TypeUse)
<< Use(6, 10, 6, SemanticInfo::TypeUse)
<< Use(8, 11, 1, SemanticInfo::TypeUse)
<< Use(8, 14, 8, SemanticInfo::FunctionUse)
<< Use(8, 35, 1, SemanticInfo::FieldUse)
<< Use(9, 5, 1, SemanticInfo::TypeUse)
<< Use(9, 7, 1, SemanticInfo::FieldUse)
<< Use(13, 6, 3, SemanticInfo::FunctionUse)
<< Use(15, 3, 5, SemanticInfo::TypeUse)
<< Use(15, 9, 3, SemanticInfo::TypeUse)
<< Use(15, 15, 6, SemanticInfo::TypeUse)
<< Use(15, 22, 6, SemanticInfo::LocalUse)
<< Use(16, 5, 6, SemanticInfo::LocalUse)
<< Use(16, 13, 3, SemanticInfo::FieldUse)
;
TestData::check(source, expectedUses);
}
QTEST_APPLESS_MAIN(tst_CheckSymbols) QTEST_APPLESS_MAIN(tst_CheckSymbols)
#include "tst_checksymbols.moc" #include "tst_checksymbols.moc"

View File

@@ -94,6 +94,7 @@ private Q_SLOTS:
// templates // templates
void instantiateTemplateWithNestedClass(); void instantiateTemplateWithNestedClass();
void operatorAsteriskOfNestedClassOfTemplateClass_QTCREATORBUG9006();
}; };
void tst_FindUsages::inlineMethod() void tst_FindUsages::inlineMethod()
@@ -444,5 +445,50 @@ void tst_FindUsages::instantiateTemplateWithNestedClass()
QCOMPARE(findUsages.usages().size(), 2); QCOMPARE(findUsages.usages().size(), 2);
} }
void tst_FindUsages::operatorAsteriskOfNestedClassOfTemplateClass_QTCREATORBUG9006()
{
const QByteArray src = "\n"
"struct Foo { int foo; };\n"
"\n"
"template<class T>\n"
"struct Outer\n"
"{\n"
" struct Nested\n"
" {\n"
" const T &operator*() { return t; }\n"
" T t;\n"
" };\n"
"};\n"
"\n"
"void bug()\n"
"{\n"
" Outer<Foo>::Nested nested;\n"
" (*nested).foo;\n"
"}\n"
;
Document::Ptr doc = Document::create("operatorAsteriskOfNestedClassOfTemplateClass_QTCREATORBUG9006");
doc->setUtf8Source(src);
doc->parse();
doc->check();
QVERIFY(doc->diagnosticMessages().isEmpty());
QCOMPARE(doc->globalSymbolCount(), 3U);
Snapshot snapshot;
snapshot.insert(doc);
Class *classFoo = doc->globalSymbolAt(0)->asClass();
QVERIFY(classFoo);
QCOMPARE(classFoo->memberCount(), 1U);
Declaration *fooDeclaration = classFoo->memberAt(0)->asDeclaration();
QVERIFY(fooDeclaration);
QCOMPARE(fooDeclaration->name()->identifier()->chars(), "foo");
FindUsages findUsages(src, doc, snapshot);
findUsages(fooDeclaration);
QCOMPARE(findUsages.usages().size(), 2);
}
QTEST_APPLESS_MAIN(tst_FindUsages) QTEST_APPLESS_MAIN(tst_FindUsages)
#include "tst_findusages.moc" #include "tst_findusages.moc"