Commit 22c3bd24 authored by Przemyslaw Gorszkowski's avatar Przemyslaw Gorszkowski Committed by Erik Verbruggen
Browse files

C++: Fix code completion for Qt containers

This change solves only problem with Qt containers.
stl containers need separate change.
Problem was with predeclaration of template class after
declaration of this template class.
(there is unit test added which shows the problem).

Task-number: QTCREATORBUG-8228 (cover only Qt containers)

Change-Id: If1f76c88c955b7b55347d302b353f5cd52b244a4
Reviewed-by: default avatarErik Verbruggen <>
parent 91889a9a
......@@ -726,7 +726,7 @@ ClassOrNamespace *ClassOrNamespace::nestedType(const Name *name, ClassOrNamespac
return reference;
const TemplateNameId *templId = name->asTemplateNameId();
if (_alreadyConsideredClasses.contains(referenceClass) ||
if ((! templId && _alreadyConsideredClasses.contains(referenceClass)) ||
(templId &&
_alreadyConsideredTemplates.contains(templId))) {
return reference;
......@@ -370,6 +370,45 @@ void CppToolsPlugin::test_completion_template_5()
void CppToolsPlugin::test_completion_template_6()
TestData data;
data.srcText = "\n"
"class Item\n"
" int i;\n"
"template <typename T>\n"
"class Container\n"
" T get();\n"
"template <typename T> class Container;\n"
"class ItemContainer: public Container<Item>\n"
"ItemContainer container;\n"
Utils::ChangeSet change;
QString txt = QLatin1String("container.get().");
change.insert(data.pos, txt);
QTextCursor cursor(data.doc);
data.pos += txt.length();
QStringList completions = getCompletions(data);
QCOMPARE(completions.size(), 2);
void CppToolsPlugin::test_completion()
QFETCH(QByteArray, code);
......@@ -1013,4 +1052,6 @@ void CppToolsPlugin::test_completion_enclosing_template_class_data()
QTest::newRow("case: nested template class with enclosing template class")
<< code << completions;}
<< code << completions;
......@@ -96,6 +96,7 @@ private slots:
void test_completion_template_3();
void test_completion_template_4();
void test_completion_template_5();
void test_completion_template_6();
void test_completion_template_as_base();
void test_completion_template_as_base_data();
void test_completion_use_global_identifier_as_base_class();
Supports Markdown
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