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:
Christian Kandeler
2022-05-16 13:58:49 +02:00
parent 6d1ec54679
commit 15665680df
2 changed files with 10 additions and 7 deletions

View File

@@ -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<int> list;\n"
" int localFirst = list.first();\n"
" auto localFirst = list.first();\n"
"}\n";
testDocuments << CppTestDocument::create("file.cpp", original, expected);

View File

@@ -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);