summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPrzemyslaw Gorszkowski <pgorszkowski@gmail.com>2013-04-02 23:04:12 +0200
committerErik Verbruggen <erik.verbruggen@digia.com>2013-04-09 11:23:14 +0200
commit7c74482ad361ee81f87c8ed039b789807934f0e7 (patch)
tree27d26259d19396ec7a0ccb18dd5510bfc0445626
parentbe085863fcc555ca9fb6a18d38f5c36a4b0ea690 (diff)
downloadqt-creator-7c74482ad361ee81f87c8ed039b789807934f0e7.tar.gz
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>
-rw-r--r--src/libs/cplusplus/TypeOfExpression.h6
-rw-r--r--src/plugins/cppeditor/cppeditor.cpp1
-rw-r--r--tests/auto/cplusplus/checksymbols/tst_checksymbols.cpp47
-rw-r--r--tests/auto/cplusplus/findusages/tst_findusages.cpp46
4 files changed, 99 insertions, 1 deletions
diff --git a/src/libs/cplusplus/TypeOfExpression.h b/src/libs/cplusplus/TypeOfExpression.h
index 848999f7d0..adeb1d9644 100644
--- a/src/libs/cplusplus/TypeOfExpression.h
+++ b/src/libs/cplusplus/TypeOfExpression.h
@@ -124,7 +124,11 @@ public:
QByteArray preprocessedExpression(const QByteArray &utf8code) const;
void setExpandTemplates(bool expandTemplates)
- { m_expandTemplates = expandTemplates; }
+ {
+ if (m_bindings)
+ m_bindings->setExpandTemplates(expandTemplates);
+ m_expandTemplates = expandTemplates;
+ }
private:
diff --git a/src/plugins/cppeditor/cppeditor.cpp b/src/plugins/cppeditor/cppeditor.cpp
index 1924aa4577..a9f406480a 100644
--- a/src/plugins/cppeditor/cppeditor.cpp
+++ b/src/plugins/cppeditor/cppeditor.cpp
@@ -321,6 +321,7 @@ struct CanonicalSymbol
: editor(editor), info(info)
{
typeOfExpression.init(info.doc, info.snapshot);
+ typeOfExpression.setExpandTemplates(true);
}
const LookupContext &context() const
diff --git a/tests/auto/cplusplus/checksymbols/tst_checksymbols.cpp b/tests/auto/cplusplus/checksymbols/tst_checksymbols.cpp
index de6435677e..432fd2dad4 100644
--- a/tests/auto/cplusplus/checksymbols/tst_checksymbols.cpp
+++ b/tests/auto/cplusplus/checksymbols/tst_checksymbols.cpp
@@ -179,6 +179,7 @@ private slots:
void test_checksymbols_QTCREATORBUG8890_danglingPointer();
void test_checksymbols_QTCREATORBUG8974_danglingPointer();
+ void operatorAsteriskOfNestedClassOfTemplateClass_QTCREATORBUG9006();
};
void tst_CheckSymbols::test_checksymbols_TypeUse()
@@ -1233,5 +1234,51 @@ void tst_CheckSymbols::test_checksymbols_QTCREATORBUG8974_danglingPointer()
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)
#include "tst_checksymbols.moc"
diff --git a/tests/auto/cplusplus/findusages/tst_findusages.cpp b/tests/auto/cplusplus/findusages/tst_findusages.cpp
index 339d852ca0..f2098ab838 100644
--- a/tests/auto/cplusplus/findusages/tst_findusages.cpp
+++ b/tests/auto/cplusplus/findusages/tst_findusages.cpp
@@ -94,6 +94,7 @@ private Q_SLOTS:
// templates
void instantiateTemplateWithNestedClass();
+ void operatorAsteriskOfNestedClassOfTemplateClass_QTCREATORBUG9006();
};
void tst_FindUsages::inlineMethod()
@@ -444,5 +445,50 @@ void tst_FindUsages::instantiateTemplateWithNestedClass()
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)
#include "tst_findusages.moc"