diff --git a/src/plugins/cppeditor/cppquickfix_test.cpp b/src/plugins/cppeditor/cppquickfix_test.cpp index 7d51e66414e..3434f87b72d 100644 --- a/src/plugins/cppeditor/cppquickfix_test.cpp +++ b/src/plugins/cppeditor/cppquickfix_test.cpp @@ -771,6 +771,66 @@ void CppEditorPlugin::test_quickfix_data() "}\n" ); + // Checks: No special treatment for reference to non const. + QTest::newRow("GenerateGetterSetter_referenceToNonConst") + << CppQuickFixFactoryPtr(new GenerateGetterSetter) << _( + "\n" + "class Something\n" + "{\n" + " int &it@;\n" + "};\n" + ) << _( + "\n" + "class Something\n" + "{\n" + " int ⁢\n" + "\n" + "public:\n" + " int &getIt() const;\n" + " void setIt(const int &value);\n" + "};\n" + "\n" + "int &Something::getIt() const\n" + "{\n" + " return it;\n" + "}\n" + "\n" + "void Something::setIt(const int &value)\n" + "{\n" + " it = value;\n" + "}\n" + ); + + // Checks: No special treatment for reference to const. + QTest::newRow("GenerateGetterSetter_referenceToConst") + << CppQuickFixFactoryPtr(new GenerateGetterSetter) << _( + "\n" + "class Something\n" + "{\n" + " const int &it@;\n" + "};\n" + ) << _( + "\n" + "class Something\n" + "{\n" + " const int ⁢\n" + "\n" + "public:\n" + " const int &getIt() const;\n" + " void setIt(const int &value);\n" + "};\n" + "\n" + "const int &Something::getIt() const\n" + "{\n" + " return it;\n" + "}\n" + "\n" + "void Something::setIt(const int &value)\n" + "{\n" + " it = value;\n" + "}\n" + ); + // Checks: // 1. Setter: Setter is a static function. // 2. Getter: Getter is a static, non const function. diff --git a/src/plugins/cppeditor/cppquickfixes.cpp b/src/plugins/cppeditor/cppquickfixes.cpp index b7923d7217e..6fd02fd873a 100644 --- a/src/plugins/cppeditor/cppquickfixes.cpp +++ b/src/plugins/cppeditor/cppquickfixes.cpp @@ -3018,10 +3018,12 @@ public: if (passByValue) { paramString = oo.prettyType(fullySpecifiedType, paramName); } else { - FullySpecifiedType constParamType(fullySpecifiedType); + const ReferenceType *refType = type->asReferenceType(); + FullySpecifiedType constParamType(refType ? refType->elementType() + : fullySpecifiedType); constParamType.setConst(true); QScopedPointer referenceType(new ReferenceType(constParamType, false)); - FullySpecifiedType referenceToConstParamType(referenceType.data()); + const FullySpecifiedType referenceToConstParamType(referenceType.data()); paramString = oo.prettyType(referenceToConstParamType, paramName); }