From 7c0bc1384c3c2209e6e13eb1e26d4d3dbf07ed9d Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Tue, 29 Nov 2022 16:32:38 +0100 Subject: [PATCH] CppEditor: Prevent showing unwanted function template parameters Task-number: QTCREATORBUG-28186 Change-Id: Ic52090e873b4defa68cf98e2a5d08f2f0604e714 Reviewed-by: Reviewed-by: Qt CI Bot Reviewed-by: Christian Stenger --- src/libs/cplusplus/TypePrettyPrinter.cpp | 7 ++++--- src/plugins/cppeditor/cppquickfixes.cpp | 1 + 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/libs/cplusplus/TypePrettyPrinter.cpp b/src/libs/cplusplus/TypePrettyPrinter.cpp index 41fb22c86b8..848757ffc32 100644 --- a/src/libs/cplusplus/TypePrettyPrinter.cpp +++ b/src/libs/cplusplus/TypePrettyPrinter.cpp @@ -361,11 +361,13 @@ static bool endsWithPtrOrRef(const QString &type) void TypePrettyPrinter::visit(Function *type) { - if (_overview->showTemplateParameters) { + bool showTemplateParameters = _overview->showTemplateParameters; QStringList nameParts = _name.split("::"); int i = nameParts.length() - 1; for (Scope *s = type->enclosingScope(); s && i >= 0; s = s->enclosingScope()) { - if (Template *templ = s->asTemplate()) { + if (s->asClass()) + showTemplateParameters = true; + if (Template *templ = s->asTemplate(); templ && showTemplateParameters) { QString &n = nameParts[i]; const int paramCount = templ->templateParameterCount(); if (paramCount > 0) { @@ -388,7 +390,6 @@ void TypePrettyPrinter::visit(Function *type) --i; } _name = nameParts.join("::"); - } if (_needsParens) { _text.prepend(QLatin1Char('(')); diff --git a/src/plugins/cppeditor/cppquickfixes.cpp b/src/plugins/cppeditor/cppquickfixes.cpp index c57c6360daa..7f8d6badab6 100644 --- a/src/plugins/cppeditor/cppquickfixes.cpp +++ b/src/plugins/cppeditor/cppquickfixes.cpp @@ -6277,6 +6277,7 @@ QString definitionSignature(const CppQuickFixInterface *assist, oo.includeWhiteSpaceInOperatorName = operatorNameText.contains(QLatin1Char(' ')); } const QString nameText = oo.prettyName(LookupContext::minimalName(func, cppCoN, control)); + oo.showTemplateParameters = false; const FullySpecifiedType tn = rewriteType(func->type(), &env, control); return oo.prettyType(tn, nameText);