Commit 80e1ae80 authored by Przemyslaw Gorszkowski's avatar Przemyslaw Gorszkowski Committed by Erik Verbruggen

C++: fix crash during code completion with base template class

ResolveExpression has to have a reference of ContextLookup. If not there
will be a crash because of deleted instanitated base template class.

Task-number: QTCREATORBUG-9329
Change-Id: I7f8c83da0d81ac6311e76d15a897adbc70b08d75
Reviewed-by: default avatarErik Verbruggen <erik.verbruggen@digia.com>
parent 2e9f6a79
......@@ -122,7 +122,7 @@ protected:
private:
Scope *_scope;
LookupContext _context;
const LookupContext& _context;
Bind bind;
QList<LookupItem> _results;
bool _reference;
......
......@@ -1798,3 +1798,37 @@ void CppToolsPlugin::test_completion_namespace_alias_with_many_namespace_declara
QVERIFY(completions.contains(QLatin1String("Foo1")));
QVERIFY(completions.contains(QLatin1String("Foo2")));
}
void CppToolsPlugin::test_completion_crash_cloning_template_class_QTCREATORBUG9329()
{
TestData data;
data.srcText =
"struct A {};\n"
"template <typename T>\n"
"struct Templ {};\n"
"struct B : A, Templ<A>\n"
"{\n"
" int f()\n"
" {\n"
" @\n"
" // padding so we get the scope right\n"
" }\n"
"};\n"
;
setup(&data);
Utils::ChangeSet change;
QString txt = QLatin1String("this->");
change.insert(data.pos, txt);
QTextCursor cursor(data.doc);
change.apply(&cursor);
data.pos += txt.length();
QStringList completions = getCompletions(data);
QCOMPARE(completions.size(), 4);
QVERIFY(completions.contains(QLatin1String("A")));
QVERIFY(completions.contains(QLatin1String("B")));
QVERIFY(completions.contains(QLatin1String("Templ")));
QVERIFY(completions.contains(QLatin1String("f")));
}
......@@ -127,6 +127,7 @@ private slots:
void test_completion_typedef_using_templates1();
void test_completion_typedef_using_templates2();
void test_completion_namespace_alias_with_many_namespace_declarations();
void test_completion_crash_cloning_template_class_QTCREATORBUG9329();
void test_format_pointerdeclaration_in_simpledeclarations();
void test_format_pointerdeclaration_in_simpledeclarations_data();
......
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