From d811e7773f7d7431fe58fd997da1a3a15ba53f85 Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Fri, 5 Jun 2020 16:23:23 +0200 Subject: [PATCH] CppEditor: Do not treat friend declaration as member function ... when trying to create definitions from declarations. Instead, we completely ignore friends in this context, arguing that the respective function normally should have a proper declaration somewhere else. Fixes: QTCREATORBUG-7164 Change-Id: I3ddb89cefecbc494f9c7e63600b65fd6288b7169 Reviewed-by: Cristian Adam --- src/plugins/cppeditor/cppeditorplugin.h | 1 + src/plugins/cppeditor/cppquickfix_test.cpp | 13 +++++++++++++ src/plugins/cppeditor/cppquickfixes.cpp | 2 +- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/plugins/cppeditor/cppeditorplugin.h b/src/plugins/cppeditor/cppeditorplugin.h index dfb167dd60d..f3e98c0491d 100644 --- a/src/plugins/cppeditor/cppeditorplugin.h +++ b/src/plugins/cppeditor/cppeditorplugin.h @@ -135,6 +135,7 @@ private slots: void test_quickfix_InsertDefFromDecl_unicodeIdentifier(); void test_quickfix_InsertDefFromDecl_templateClass(); void test_quickfix_InsertDefFromDecl_templateFunction(); + void test_quickfix_InsertDefFromDecl_notTriggeredForFriendFunc(); void test_quickfix_InsertDeclFromDef(); void test_quickfix_InsertDeclFromDef_templateFuncTypename(); diff --git a/src/plugins/cppeditor/cppquickfix_test.cpp b/src/plugins/cppeditor/cppquickfix_test.cpp index 0e0ccfccfc5..3e65e3dde81 100644 --- a/src/plugins/cppeditor/cppquickfix_test.cpp +++ b/src/plugins/cppeditor/cppquickfix_test.cpp @@ -2909,6 +2909,19 @@ void CppEditorPlugin::test_quickfix_InsertDefFromDecl_templateFunction() QuickFixOperationTest(singleDocument(original, expected), &factory); } +void CppEditorPlugin::test_quickfix_InsertDefFromDecl_notTriggeredForFriendFunc() +{ + const QByteArray contents = + "class Foo\n" + "{\n" + " friend void f@unc();\n" + "};\n" + "\n"; + + InsertDefFromDecl factory; + QuickFixOperationTest(singleDocument(contents, ""), &factory); +} + // Function for one of InsertDeclDef section cases void insertToSectionDeclFromDef(const QByteArray §ion, int sectionIndex) { diff --git a/src/plugins/cppeditor/cppquickfixes.cpp b/src/plugins/cppeditor/cppquickfixes.cpp index 7c3f210d1b8..1753f9ff070 100644 --- a/src/plugins/cppeditor/cppquickfixes.cpp +++ b/src/plugins/cppeditor/cppquickfixes.cpp @@ -2847,7 +2847,7 @@ void InsertDefFromDecl::match(const CppQuickFixInterface &interface, QuickFixOpe if (Symbol *symbol = simpleDecl->symbols->value) { if (Declaration *decl = symbol->asDeclaration()) { if (Function *func = decl->type()->asFunctionType()) { - if (func->isSignal() || func->isPureVirtual()) + if (func->isSignal() || func->isPureVirtual() || func->isFriend()) return; // Check if there is already a definition