diff --git a/src/plugins/cppeditor/cppeditorplugin.h b/src/plugins/cppeditor/cppeditorplugin.h index 2dd3163a343..ea58b290e48 100644 --- a/src/plugins/cppeditor/cppeditorplugin.h +++ b/src/plugins/cppeditor/cppeditorplugin.h @@ -147,6 +147,7 @@ private slots: void test_quickfix_InsertDefFromDecl_unicodeIdentifier(); void test_quickfix_InsertDeclFromDef(); + void test_quickfix_InsertDeclFromDef_notTriggeredForTemplateFunc(); void test_quickfix_AddIncludeForUndefinedIdentifier_data(); void test_quickfix_AddIncludeForUndefinedIdentifier(); diff --git a/src/plugins/cppeditor/cppquickfix_test.cpp b/src/plugins/cppeditor/cppquickfix_test.cpp index 50d0a30a085..5b2c7a9e258 100644 --- a/src/plugins/cppeditor/cppquickfix_test.cpp +++ b/src/plugins/cppeditor/cppquickfix_test.cpp @@ -2715,6 +2715,22 @@ void CppEditorPlugin::test_quickfix_InsertDeclFromDef() insertToSectionDeclFromDef("private slots", 5); } +void CppEditorPlugin::test_quickfix_InsertDeclFromDef_notTriggeredForTemplateFunc() +{ + QByteArray contents = + "class Foo\n" + "{\n" + " template\n" + " void func();\n" + "};\n" + "\n" + "template\n" + "void Foo::fu@nc() {}\n"; + + InsertDeclFromDef factory; + QuickFixOperationTest(singleDocument(contents, ""), &factory); +} + void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_data() { QTest::addColumn("headerPath"); diff --git a/src/plugins/cppeditor/cppquickfixes.cpp b/src/plugins/cppeditor/cppquickfixes.cpp index f65f1b6a57b..371ec66f8e2 100644 --- a/src/plugins/cppeditor/cppquickfixes.cpp +++ b/src/plugins/cppeditor/cppquickfixes.cpp @@ -2465,7 +2465,17 @@ void InsertDeclFromDef::match(const CppQuickFixInterface &interface, QuickFixOpe Function *fun = funDef->symbol; if (Class *matchingClass = isMemberFunction(interface.context(), fun)) { const QualifiedNameId *qName = fun->name()->asQualifiedNameId(); - for (Symbol *s = matchingClass->find(qName->identifier()); s; s = s->next()) { + for (Symbol *symbol = matchingClass->find(qName->identifier()); + symbol; symbol = symbol->next()) { + Symbol *s = symbol; + if (fun->enclosingScope()->isTemplate()) { + if (const Template *templ = s->type()->asTemplateType()) { + if (Symbol *decl = templ->declaration()) { + if (decl->type()->isFunctionType()) + s = decl; + } + } + } if (!s->name() || !qName->identifier()->match(s->identifier()) || !s->type()->isFunctionType())