diff --git a/src/libs/cplusplus/TypePrettyPrinter.cpp b/src/libs/cplusplus/TypePrettyPrinter.cpp index 871bb3a87f5..43eba638548 100644 --- a/src/libs/cplusplus/TypePrettyPrinter.cpp +++ b/src/libs/cplusplus/TypePrettyPrinter.cpp @@ -389,18 +389,22 @@ void TypePrettyPrinter::visit(Function *type) for (Scope *s = type->enclosingScope(); s && i >= 0; s = s->enclosingScope()) { if (Template *templ = s->asTemplate()) { QString &n = nameParts[i]; - n += '<'; - for (int index = 0; index < templ->templateParameterCount(); ++index) { - if (index) - n += QLatin1String(", "); - QString arg = _overview->prettyName(templ->templateParameterAt(index)->name()); - if (arg.isEmpty()) { - arg += 'T'; - arg += QString::number(index + 1); + const int paramCount = templ->templateParameterCount(); + if (paramCount > 0) { + n += '<'; + for (int index = 0; index < paramCount; ++index) { + if (index) + n += QLatin1String(", "); + QString arg = _overview->prettyName( + templ->templateParameterAt(index)->name()); + if (arg.isEmpty()) { + arg += 'T'; + arg += QString::number(index + 1); + } + n += arg; } - n += arg; + n += '>'; } - n += '>'; } if (s->identifier()) --i; @@ -435,7 +439,8 @@ void TypePrettyPrinter::visit(Function *type) if (_overview->showEnclosingTemplate) { if (Template *templ = type->enclosingTemplate()) { QString templateScope = "template<"; - for (int i = 0, total = templ->templateParameterCount(); i < total; ++i) { + const int paramCount = templ->templateParameterCount(); + for (int i = 0; i < paramCount; ++i) { if (Symbol *param = templ->templateParameterAt(i)) { if (i > 0) templateScope.append(", "); @@ -452,7 +457,8 @@ void TypePrettyPrinter::visit(Function *type) } } } - _text.prepend(templateScope + ">\n"); + if (paramCount > 0) + _text.prepend(templateScope + ">\n"); } } diff --git a/src/plugins/cppeditor/cppeditorplugin.h b/src/plugins/cppeditor/cppeditorplugin.h index 74a50ad406c..5bb1abc9cb2 100644 --- a/src/plugins/cppeditor/cppeditorplugin.h +++ b/src/plugins/cppeditor/cppeditorplugin.h @@ -203,6 +203,7 @@ private slots: void test_quickfix_MoveFuncDefOutside_respectWsInOperatorNames2(); void test_quickfix_MoveFuncDefOutside_macroUses(); void test_quickfix_MoveFuncDefOutside_template(); + void test_quickfix_MoveFuncDefOutside_template_specializedClass(); void test_quickfix_MoveFuncDefOutside_unnamedTemplate(); void test_quickfix_MoveFuncDefOutside_MemberFuncToCpp_Static(); void test_quickfix_MoveFuncDefOutside_MemberFuncToCpp_WithInlinePartOfName(); diff --git a/src/plugins/cppeditor/cppquickfix_test.cpp b/src/plugins/cppeditor/cppquickfix_test.cpp index 35f35a3cc3f..1190edb18d0 100644 --- a/src/plugins/cppeditor/cppquickfix_test.cpp +++ b/src/plugins/cppeditor/cppquickfix_test.cpp @@ -6521,6 +6521,33 @@ void CppEditorPlugin::test_quickfix_MoveFuncDefOutside_template() QuickFixOperationTest(singleDocument(original, expected), &factory); } +void CppEditorPlugin::test_quickfix_MoveFuncDefOutside_template_specializedClass() +{ + QByteArray original = R"( +template class base {}; +template<> +class base +{ +public: + void @bar() {} +}; +)"; + QByteArray expected = R"( +template class base {}; +template<> +class base +{ +public: + void bar(); +}; + +void base::bar() {} +)"; + + MoveFuncDefOutside factory; + QuickFixOperationTest(singleDocument(original, expected), &factory); +} + void CppEditorPlugin::test_quickfix_MoveFuncDefOutside_unnamedTemplate() { QByteArray original =