From 39047fac5bbcc212d9422b42bfeb8c7f30cbfac4 Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Thu, 4 Jun 2020 11:47:02 +0200 Subject: [PATCH] CPlusPlus: Add missing type information for enum variables Consider these two variable declarations: enum EX { EX1, EX2}; EX ex; emum EY { EY1, EY2} ey; The ex variable would correctly get assigned type EX, but the ey variable would not have any type. This is now fixed. Task-number: QTCREATORBUG-7487 Change-Id: I3e09c5766fdb9e6baf3a8d7bc6f2fc581f2d824b Reviewed-by: Cristian Adam --- src/libs/3rdparty/cplusplus/Bind.cpp | 1 + src/plugins/cppeditor/cppquickfix_test.cpp | 25 ++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/libs/3rdparty/cplusplus/Bind.cpp b/src/libs/3rdparty/cplusplus/Bind.cpp index 53a14f6defc..801349c872c 100644 --- a/src/libs/3rdparty/cplusplus/Bind.cpp +++ b/src/libs/3rdparty/cplusplus/Bind.cpp @@ -3176,6 +3176,7 @@ bool Bind::visit(EnumSpecifierAST *ast) } (void) switchScope(previousScope); + _type.setType(control()->namedType(this->name(ast->name))); return false; } diff --git a/src/plugins/cppeditor/cppquickfix_test.cpp b/src/plugins/cppeditor/cppquickfix_test.cpp index 09207c1dbe6..afb6f87aec9 100644 --- a/src/plugins/cppeditor/cppquickfix_test.cpp +++ b/src/plugins/cppeditor/cppquickfix_test.cpp @@ -369,6 +369,31 @@ void CppEditorPlugin::test_quickfix_data() "}\n" ); + // Checks: All enum values are added as case statements for a blank switch when + // the variable is declared alongside the enum definition. + QTest::newRow("CompleteSwitchCaseStatement_basic1_enum_with_declaration") + << CppQuickFixFactoryPtr(new CompleteSwitchCaseStatement) << _( + "enum EnumType { V1, V2 } t;\n" + "\n" + "void f()\n" + "{\n" + " @switch (t) {\n" + " }\n" + "}\n" + ) << _( + "enum EnumType { V1, V2 } t;\n" + "\n" + "void f()\n" + "{\n" + " switch (t) {\n" + " case V1:\n" + " break;\n" + " case V2:\n" + " break;\n" + " }\n" + "}\n" + ); + // Checks: All enum values are added as case statements for a blank switch with a default case. QTest::newRow("CompleteSwitchCaseStatement_basic2") << CppQuickFixFactoryPtr(new CompleteSwitchCaseStatement) << _(