CppEditor: Fix "move definition" quickfix for template member functions

There are a lot more problems in this area (e.g. with nested classes),
but let's tackle them one by one.

Fixes: QTCREATORBUG-24801
Change-Id: I4b3805ea6f8b28373925693650150bbd89508096
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
Christian Kandeler
2020-10-26 15:07:55 +01:00
parent b5e9dd006a
commit d2ebc16b92
4 changed files with 49 additions and 2 deletions

View File

@@ -177,6 +177,7 @@ private slots:
void test_quickfix_MoveFuncDefOutside_respectWsInOperatorNames2();
void test_quickfix_MoveFuncDefOutside_macroUses();
void test_quickfix_MoveFuncDefOutside_template();
void test_quickfix_MoveFuncDefOutside_unnamedTemplate();
void test_quickfix_MoveAllFuncDefOutside_MemberFuncToCpp();
void test_quickfix_MoveAllFuncDefOutside_MemberFuncOutside();

View File

@@ -5573,7 +5573,24 @@ void CppEditorPlugin::test_quickfix_MoveFuncDefOutside_template()
"class Foo { void fu@nc(); };\n"
"\n"
"template<class T>\n"
"void Foo::func() {}\n"; // Should be Foo<T>::func
"void Foo<T>::func() {}\n";
;
MoveFuncDefOutside factory;
QuickFixOperationTest(singleDocument(original, expected), &factory);
}
void CppEditorPlugin::test_quickfix_MoveFuncDefOutside_unnamedTemplate()
{
QByteArray original =
"template<typename T, typename>\n"
"class Foo { void fu@nc() {} };\n";
QByteArray expected =
"template<typename T, typename>\n"
"class Foo { void fu@nc(); };\n"
"\n"
"template<typename T, typename T2>\n"
"void Foo<T, T2>::func() {}\n";
;
MoveFuncDefOutside factory;

View File

@@ -5952,6 +5952,7 @@ QString definitionSignature(const CppQuickFixInterface *assist,
oo.showReturnTypes = true;
oo.showArgumentNames = true;
oo.showEnclosingTemplate = true;
oo.showTemplateParameters = true;
const Name *name = func->name();
if (name && nameIncludesOperatorName(name)) {
CoreDeclaratorAST *coreDeclarator = functionDefinitionAST->declarator->core_declarator;