diff --git a/src/plugins/cppeditor/cppquickfix_test.cpp b/src/plugins/cppeditor/cppquickfix_test.cpp index f2e91ab8079..a5646c068ea 100644 --- a/src/plugins/cppeditor/cppquickfix_test.cpp +++ b/src/plugins/cppeditor/cppquickfix_test.cpp @@ -725,6 +725,36 @@ void CppEditorPlugin::test_quickfix_data() "};\n" ) << _(); + // Checks if "m_" is recognized as "m" with the postfix "_" and not simply as "m_" prefix. + QTest::newRow("GenerateGetterSetter_recognizeMasVariableName") + << CppQuickFixFactoryPtr(new GenerateGetterSetter) << _( + "\n" + "class Something\n" + "{\n" + " int @m_;\n" + "};\n" + ) << _( + "\n" + "class Something\n" + "{\n" + " int m_;\n" + "\n" + "public:\n" + " int m() const;\n" + " void setM(int m);\n" + "};\n" + "\n" + "int Something::m() const\n" + "{\n" + " return m_;\n" + "}\n" + "\n" + "void Something::setM(int m)\n" + "{\n" + " m_ = m;\n" + "}\n" + ); + QTest::newRow("MoveDeclarationOutOfIf_ifOnly") << CppQuickFixFactoryPtr(new MoveDeclarationOutOfIf) << _( "void f()\n" diff --git a/src/plugins/cppeditor/cppquickfixes.cpp b/src/plugins/cppeditor/cppquickfixes.cpp index 918d44889cd..181119049f5 100644 --- a/src/plugins/cppeditor/cppquickfixes.cpp +++ b/src/plugins/cppeditor/cppquickfixes.cpp @@ -2827,12 +2827,12 @@ public: m_variableString = QString::fromUtf8(variableId->chars(), variableId->size()); m_baseName = m_variableString; - if (m_baseName.startsWith(QLatin1String("m_"))) - m_baseName.remove(0, 2); - else if (m_baseName.startsWith(QLatin1Char('_'))) + if (m_baseName.startsWith(QLatin1Char('_'))) m_baseName.remove(0, 1); else if (m_baseName.endsWith(QLatin1Char('_'))) m_baseName.chop(1); + else if (m_baseName.startsWith(QLatin1String("m_"))) + m_baseName.remove(0, 2); m_getterName = m_baseName != m_variableString ? m_baseName