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 <cristian.adam@qt.io>
This commit is contained in:
Christian Kandeler
2020-06-05 16:23:23 +02:00
parent 54f53898bf
commit d811e7773f
3 changed files with 15 additions and 1 deletions

View File

@@ -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();

View File

@@ -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 &section, int sectionIndex)
{

View File

@@ -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