diff --git a/src/libs/cplusplus/LookupContext.cpp b/src/libs/cplusplus/LookupContext.cpp index dae8eb6a023ed20a78242fa1ac096e316e3e9ffa..5fb0e2e3eca01f12c3c6ebb808171378b9698415 100644 --- a/src/libs/cplusplus/LookupContext.cpp +++ b/src/libs/cplusplus/LookupContext.cpp @@ -416,6 +416,8 @@ QList<LookupItem> ClassOrNamespace::lookup_helper(const Name *name, bool searchI QList<LookupItem> result; if (name) { + QSet<ClassOrNamespace *> processed; + if (const QualifiedNameId *q = name->asQualifiedNameId()) { if (! q->base()) result = globalNamespace()->find(q->name()); @@ -423,10 +425,11 @@ QList<LookupItem> ClassOrNamespace::lookup_helper(const Name *name, bool searchI else if (ClassOrNamespace *binding = lookupType(q->base())) result = binding->find(q->name()); + lookup_helper(name, this, &result, &processed, /*templateId = */ 0); + return result; } - QSet<ClassOrNamespace *> processed; ClassOrNamespace *binding = this; do { lookup_helper(name, binding, &result, &processed, /*templateId = */ 0); diff --git a/src/plugins/cpptools/cppcompletion_test.cpp b/src/plugins/cpptools/cppcompletion_test.cpp index 7d9d9f3417f274fe664e303af99a98a41a2420e3..a6681bb39813bf22fd2acc839911b95ce0267ada 100644 --- a/src/plugins/cpptools/cppcompletion_test.cpp +++ b/src/plugins/cpptools/cppcompletion_test.cpp @@ -121,6 +121,40 @@ static void setup(TestData *data) data->doc = data->editor->document(); } +void CppToolsPlugin::test_completion_forward_declarations_present() +{ + TestData data; + data.srcText = "\n" + "class Foo\n" + "{\n" + " struct Bar;\n" + " int i;\n" + "};\n" + "\n" + "struct Foo::Bar \n" + "{\n" + " Bar() {}\n" + "};\n" + "\n" + "@\n" + "// padding so we get the scope right\n"; + + setup(&data); + + Utils::ChangeSet change; + change.insert(data.pos, "Foo::Bar::"); + QTextCursor cursor(data.doc); + change.apply(&cursor); + data.pos += 10; + + QStringList expected; + expected.append("Bar"); + + QStringList completions = getCompletions(data); + + QCOMPARE(completions, expected); +} + void CppToolsPlugin::test_completion_basic_1() { TestData data; diff --git a/src/plugins/cpptools/cpptoolsplugin.h b/src/plugins/cpptools/cpptoolsplugin.h index 5a07c0add3f71842c942f01f1383fe339cd42981..ba88d11896e11912095a035b451f7f6ce5329f4e 100644 --- a/src/plugins/cpptools/cpptoolsplugin.h +++ b/src/plugins/cpptools/cpptoolsplugin.h @@ -90,6 +90,7 @@ private slots: void test_codegen_definition_last_member(); void test_codegen_definition_middle_member(); + void test_completion_forward_declarations_present(); void test_completion_basic_1(); void test_completion_template_1(); void test_completion_template_as_base();