diff --git a/src/plugins/cppeditor/cppquickfix_test.cpp b/src/plugins/cppeditor/cppquickfix_test.cpp index 8a3daa026f4..206a88ff740 100644 --- a/src/plugins/cppeditor/cppquickfix_test.cpp +++ b/src/plugins/cppeditor/cppquickfix_test.cpp @@ -1077,7 +1077,7 @@ void QuickfixTest::testGeneric_data() "void bar() {fo@o();}\n" ) << _( "int foo() {return 1;}\n" - "void bar() {int localFoo = foo();}\n" + "void bar() {auto localFoo = foo();}\n" ); // Check: Add local variable for a member function. @@ -1092,7 +1092,7 @@ void QuickfixTest::testGeneric_data() "class Foo {public: int* fooFunc();}\n" "void bar() {\n" " Foo *f = new Foo;\n" - " int *localFooFunc = f->fooFunc();\n" + " auto localFooFunc = f->fooFunc();\n" "}\n" ); @@ -1110,7 +1110,7 @@ void QuickfixTest::testGeneric_data() "struct Baz {Foo* foo();};\n" "void bar() {\n" " Baz *b = new Baz;\n" - " int *localFunc = b->foo()->func();\n" + " auto localFunc = b->foo()->func();\n" "}" ); @@ -1128,7 +1128,7 @@ void QuickfixTest::testGeneric_data() "struct Baz {Foo* foo();};\n" "void bar() {\n" " Baz *b = new Baz;\n" - " int *localFunc = b->foo()->func();\n" + " auto localFunc = b->foo()->func();\n" "}" ); @@ -1142,7 +1142,7 @@ void QuickfixTest::testGeneric_data() ) << _( "class Foo {public: static int* fooFunc();}\n" "void bar() {\n" - " int *localFooFunc = Foo::fooFunc();\n" + " auto localFooFunc = Foo::fooFunc();\n" "}" ); @@ -1156,7 +1156,7 @@ void QuickfixTest::testGeneric_data() ) << _( "class Foo {}\n" "void bar() {\n" - " Foo *localFoo = new Foo;\n" + " auto localFoo = new Foo;\n" "}" ); @@ -7384,7 +7384,7 @@ void QuickfixTest::testAssignToLocalVariableTemplates() "#include \"file.h\"\n" "void foo() {\n" " List list;\n" - " int localFirst = list.first();\n" + " auto localFirst = list.first();\n" "}\n"; testDocuments << CppTestDocument::create("file.cpp", original, expected); diff --git a/src/plugins/cppeditor/cppquickfixes.cpp b/src/plugins/cppeditor/cppquickfixes.cpp index f7f605361b1..7f1f7a7a79d 100644 --- a/src/plugins/cppeditor/cppquickfixes.cpp +++ b/src/plugins/cppeditor/cppquickfixes.cpp @@ -6760,6 +6760,9 @@ private: QString deduceType() const { + if (m_file->cppDocument()->languageFeatures().cxx11Enabled) + return "auto " + m_originalName; + TypeOfExpression typeOfExpression; typeOfExpression.init(semanticInfo().doc, snapshot(), context().bindings()); typeOfExpression.setExpandTemplates(true);