forked from qt-creator/qt-creator
CppEditor: Use "auto" in AssignToLocalVariableOperation
Fixes: QTCREATORBUG-9577 Fixes: QTCREATORBUG-18412 Change-Id: I46a925611939a3dade142eaf76e20090ae203856 Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -1077,7 +1077,7 @@ void QuickfixTest::testGeneric_data()
|
|||||||
"void bar() {fo@o();}\n"
|
"void bar() {fo@o();}\n"
|
||||||
) << _(
|
) << _(
|
||||||
"int foo() {return 1;}\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.
|
// Check: Add local variable for a member function.
|
||||||
@@ -1092,7 +1092,7 @@ void QuickfixTest::testGeneric_data()
|
|||||||
"class Foo {public: int* fooFunc();}\n"
|
"class Foo {public: int* fooFunc();}\n"
|
||||||
"void bar() {\n"
|
"void bar() {\n"
|
||||||
" Foo *f = new Foo;\n"
|
" Foo *f = new Foo;\n"
|
||||||
" int *localFooFunc = f->fooFunc();\n"
|
" auto localFooFunc = f->fooFunc();\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -1110,7 +1110,7 @@ void QuickfixTest::testGeneric_data()
|
|||||||
"struct Baz {Foo* foo();};\n"
|
"struct Baz {Foo* foo();};\n"
|
||||||
"void bar() {\n"
|
"void bar() {\n"
|
||||||
" Baz *b = new Baz;\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"
|
"struct Baz {Foo* foo();};\n"
|
||||||
"void bar() {\n"
|
"void bar() {\n"
|
||||||
" Baz *b = new Baz;\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"
|
"class Foo {public: static int* fooFunc();}\n"
|
||||||
"void bar() {\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"
|
"class Foo {}\n"
|
||||||
"void bar() {\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"
|
"#include \"file.h\"\n"
|
||||||
"void foo() {\n"
|
"void foo() {\n"
|
||||||
" List<int> list;\n"
|
" List<int> list;\n"
|
||||||
" int localFirst = list.first();\n"
|
" auto localFirst = list.first();\n"
|
||||||
"}\n";
|
"}\n";
|
||||||
testDocuments << CppTestDocument::create("file.cpp", original, expected);
|
testDocuments << CppTestDocument::create("file.cpp", original, expected);
|
||||||
|
|
||||||
|
@@ -6760,6 +6760,9 @@ private:
|
|||||||
|
|
||||||
QString deduceType() const
|
QString deduceType() const
|
||||||
{
|
{
|
||||||
|
if (m_file->cppDocument()->languageFeatures().cxx11Enabled)
|
||||||
|
return "auto " + m_originalName;
|
||||||
|
|
||||||
TypeOfExpression typeOfExpression;
|
TypeOfExpression typeOfExpression;
|
||||||
typeOfExpression.init(semanticInfo().doc, snapshot(), context().bindings());
|
typeOfExpression.init(semanticInfo().doc, snapshot(), context().bindings());
|
||||||
typeOfExpression.setExpandTemplates(true);
|
typeOfExpression.setExpandTemplates(true);
|
||||||
|
Reference in New Issue
Block a user