aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPrzemyslaw Gorszkowski <pgorszkowski@gmail.com>2013-05-19 07:23:57 +0200
committerErik Verbruggen <erik.verbruggen@digia.com>2013-05-24 11:35:11 +0200
commit80e1ae805982c8dd9b34903accb9ed3449337a63 (patch)
tree7aeb2900f61217bfab4170f096a15dc1b618b530
parent2e9f6a7935f0a725f357245b1cd0e7bfe8792d73 (diff)
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: Erik Verbruggen <erik.verbruggen@digia.com>
-rw-r--r--src/libs/cplusplus/ResolveExpression.h2
-rw-r--r--src/plugins/cpptools/cppcompletion_test.cpp34
-rw-r--r--src/plugins/cpptools/cpptoolsplugin.h1
3 files changed, 36 insertions, 1 deletions
diff --git a/src/libs/cplusplus/ResolveExpression.h b/src/libs/cplusplus/ResolveExpression.h
index 764268ab91..e6ce50dde4 100644
--- a/src/libs/cplusplus/ResolveExpression.h
+++ b/src/libs/cplusplus/ResolveExpression.h
@@ -122,7 +122,7 @@ protected:
private:
Scope *_scope;
- LookupContext _context;
+ const LookupContext& _context;
Bind bind;
QList<LookupItem> _results;
bool _reference;
diff --git a/src/plugins/cpptools/cppcompletion_test.cpp b/src/plugins/cpptools/cppcompletion_test.cpp
index 67af9b9497..11e380092b 100644
--- a/src/plugins/cpptools/cppcompletion_test.cpp
+++ b/src/plugins/cpptools/cppcompletion_test.cpp
@@ -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")));
+}
diff --git a/src/plugins/cpptools/cpptoolsplugin.h b/src/plugins/cpptools/cpptoolsplugin.h
index e5ef47ec3e..bf9c9b67a5 100644
--- a/src/plugins/cpptools/cpptoolsplugin.h
+++ b/src/plugins/cpptools/cpptoolsplugin.h
@@ -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();