CplusPlus: Fix type information for anonymous enums

Variables declared like this:
    enum { E1, E2 } e;
would not get assigned a proper type.

Task-number: QTCREATORBUG-7487
Change-Id: I4362f22feb0f2e4e1e754e9c623e5576fa31f4bc
Reviewed-by: Cristian Adam <cristian.adam@qt.io>
This commit is contained in:
Christian Kandeler
2020-06-04 12:31:43 +02:00
parent 93d5ed4073
commit 2262af087a
2 changed files with 29 additions and 1 deletions

View File

@@ -3176,7 +3176,10 @@ bool Bind::visit(EnumSpecifierAST *ast)
} }
(void) switchScope(previousScope); (void) switchScope(previousScope);
_type.setType(control()->namedType(this->name(ast->name))); if (ast->name)
_type.setType(control()->namedType(this->name(ast->name)));
else
_type.setType(ast->symbol);
return false; return false;
} }

View File

@@ -394,6 +394,31 @@ void CppEditorPlugin::test_quickfix_data()
"}\n" "}\n"
); );
// Checks: All enum values are added as case statements for a blank switch
// for anonymous enums.
QTest::newRow("CompleteSwitchCaseStatement_basic1_anonymous_enum")
<< CppQuickFixFactoryPtr(new CompleteSwitchCaseStatement) << _(
"enum { V1, V2 } t;\n"
"\n"
"void f()\n"
"{\n"
" @switch (t) {\n"
" }\n"
"}\n"
) << _(
"enum { 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. // Checks: All enum values are added as case statements for a blank switch with a default case.
QTest::newRow("CompleteSwitchCaseStatement_basic2") QTest::newRow("CompleteSwitchCaseStatement_basic2")
<< CppQuickFixFactoryPtr(new CompleteSwitchCaseStatement) << _( << CppQuickFixFactoryPtr(new CompleteSwitchCaseStatement) << _(