diff --git a/src/plugins/cppeditor/cppquickfix_test.cpp b/src/plugins/cppeditor/cppquickfix_test.cpp index 206a88ff740..6471134ec47 100644 --- a/src/plugins/cppeditor/cppquickfix_test.cpp +++ b/src/plugins/cppeditor/cppquickfix_test.cpp @@ -1745,6 +1745,16 @@ void QuickfixTest::testGeneric_data() << CppQuickFixFactoryPtr(new EscapeStringLiteral) << _(R"(const char *str = @"\xc3\xa0""f23\xd0\xb1g\xd0\xb1""1";)") << _(R"(const char *str = "àf23бgб1";)"); + QTest::newRow("AddLocalDeclaration_QTCREATORBUG-26004") + << CppQuickFixFactoryPtr(new AddLocalDeclaration) + << _("void func() {\n" + " QStringList list;\n" + " @it = list.cbegin();\n" + "}\n") + << _("void func() {\n" + " QStringList list;\n" + " auto it = list.cbegin();\n" + "}\n"); } void QuickfixTest::testGeneric() diff --git a/src/plugins/cppeditor/cppquickfixes.cpp b/src/plugins/cppeditor/cppquickfixes.cpp index 50170e82767..42f90edf7c6 100644 --- a/src/plugins/cppeditor/cppquickfixes.cpp +++ b/src/plugins/cppeditor/cppquickfixes.cpp @@ -1634,6 +1634,10 @@ private: { CppRefactoringChanges refactoring(snapshot()); CppRefactoringFilePtr currentFile = refactoring.file(filePath()); + Overview oo = CppCodeStyleSettings::currentProjectCodeStyleOverview(); + + if (currentFile->cppDocument()->languageFeatures().cxx11Enabled) + return "auto " + oo.prettyName(simpleNameAST->name); TypeOfExpression typeOfExpression; typeOfExpression.init(semanticInfo().doc, snapshot(), context().bindings()); @@ -1656,7 +1660,6 @@ private: Control *control = context().bindings()->control().data(); FullySpecifiedType tn = rewriteType(result.first().type(), &env, control); - Overview oo = CppCodeStyleSettings::currentProjectCodeStyleOverview(); QString declaration = oo.prettyType(tn, simpleNameAST->name); return declaration; } @@ -3864,7 +3867,7 @@ void GetterSetterRefactoringHelper::performGeneration(ExistingGetterSetterData d FullySpecifiedType memberVariableType = data.declarationSymbol->type(); memberVariableType.setConst(false); - const bool isMemberVariableStatic = data.declarationSymbol->isStatic(); + const bool isMemberVariableStatic = memberVariableType.isStatic(); memberVariableType.setStatic(false); Overview overview = CppCodeStyleSettings::currentProjectCodeStyleOverview(); overview.showTemplateParameters = false;