diff --git a/src/plugins/cppeditor/cppeditorplugin.h b/src/plugins/cppeditor/cppeditorplugin.h index 0d52cde553be81274478d85dc24a3985578bee5d..301aa880cdc67bfa1f2854323ce1d0e07fc2e621 100644 --- a/src/plugins/cppeditor/cppeditorplugin.h +++ b/src/plugins/cppeditor/cppeditorplugin.h @@ -158,6 +158,7 @@ private slots: void test_quickfix_InsertDefFromDecl_freeFunction(); void test_quickfix_InsertDefFromDecl_insideClass(); void test_quickfix_InsertDefFromDecl_notTriggeringWhenDefinitionExists(); + void test_quickfix_InsertDefFromDecl_notTriggeringStatement(); void test_quickfix_InsertDeclFromDef(); diff --git a/src/plugins/cppeditor/cppquickfix_test.cpp b/src/plugins/cppeditor/cppquickfix_test.cpp index 34b36138867c5ea95469440cca41cf749196a4f8..b68458b81e0d743234bf1cfe056cfb394cfe9b01 100644 --- a/src/plugins/cppeditor/cppquickfix_test.cpp +++ b/src/plugins/cppeditor/cppquickfix_test.cpp @@ -908,6 +908,24 @@ void CppEditorPlugin::test_quickfix_InsertDefFromDecl_notTriggeringWhenDefinitio data.run(&factory, 1); } +/// Check not triggering when it is a statement +void CppEditorPlugin::test_quickfix_InsertDefFromDecl_notTriggeringStatement() +{ + const QByteArray original = + "class Foo {\n" + "public:\n" + " Foo() {}\n" + "};\n" + "void freeFunc() {\n" + " Foo @f();" + "}\n"; + const QByteArray expected = original + "\n"; + + InsertDefFromDecl factory; + TestCase data(original, expected); + data.run(&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 5057d843a98658ef62ded0638aaf665b0b0cc78e..b577a8086048972735b4b72c43bdb296492f962a 100644 --- a/src/plugins/cppeditor/cppquickfixes.cpp +++ b/src/plugins/cppeditor/cppquickfixes.cpp @@ -2609,6 +2609,8 @@ void InsertDefFromDecl::match(const CppQuickFixInterface &interface, QuickFixOpe for (; idx >= 0; --idx) { AST *node = path.at(idx); if (SimpleDeclarationAST *simpleDecl = node->asSimpleDeclaration()) { + if (idx > 0 && path.at(idx - 1)->asStatement()) + return; if (simpleDecl->symbols && ! simpleDecl->symbols->next) { if (Symbol *symbol = simpleDecl->symbols->value) { if (Declaration *decl = symbol->asDeclaration()) {