forked from qt-creator/qt-creator
CppEditor: Fix crash with invalid switch/case statement
Task-number: QTCREATORBUG-14925 Change-Id: Iea2cf17070d9db48924e76f6c7febca0d52e4686 Reviewed-by: Marco Bubke <marco.bubke@theqtcompany.com> Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
@@ -514,6 +514,21 @@ void CppEditorPlugin::test_quickfix_data()
|
|||||||
"}\n"
|
"}\n"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Checks: Do not crash on incomplete case statetement.
|
||||||
|
QTest::newRow("CompleteSwitchCaseStatement_doNotCrashOnIncompleteCase")
|
||||||
|
<< CppQuickFixFactoryPtr(new CompleteSwitchCaseStatement) << _(
|
||||||
|
"enum E {};\n"
|
||||||
|
"void f(E o)\n"
|
||||||
|
"{\n"
|
||||||
|
" @switch (o)\n"
|
||||||
|
" {\n"
|
||||||
|
" case\n"
|
||||||
|
" }\n"
|
||||||
|
"}\n"
|
||||||
|
) << _(
|
||||||
|
""
|
||||||
|
);
|
||||||
|
|
||||||
// Checks:
|
// Checks:
|
||||||
// 1. If the name does not start with ("m_" or "_") and does not
|
// 1. If the name does not start with ("m_" or "_") and does not
|
||||||
// end with "_", we are forced to prefix the getter with "get".
|
// end with "_", we are forced to prefix the getter with "get".
|
||||||
|
@@ -2212,11 +2212,13 @@ public:
|
|||||||
bool preVisit(AST *ast) {
|
bool preVisit(AST *ast) {
|
||||||
if (CaseStatementAST *cs = ast->asCaseStatement()) {
|
if (CaseStatementAST *cs = ast->asCaseStatement()) {
|
||||||
foundCaseStatementLevel = true;
|
foundCaseStatementLevel = true;
|
||||||
if (ExpressionAST *expression = cs->expression->asIdExpression()) {
|
if (ExpressionAST *csExpression = cs->expression) {
|
||||||
QList<LookupItem> candidates = typeOfExpression(expression, document, scope);
|
if (ExpressionAST *expression = csExpression->asIdExpression()) {
|
||||||
if (!candidates .isEmpty() && candidates.first().declaration()) {
|
QList<LookupItem> candidates = typeOfExpression(expression, document, scope);
|
||||||
Symbol *decl = candidates.first().declaration();
|
if (!candidates .isEmpty() && candidates.first().declaration()) {
|
||||||
values << prettyPrint.prettyName(LookupContext::fullyQualifiedName(decl));
|
Symbol *decl = candidates.first().declaration();
|
||||||
|
values << prettyPrint.prettyName(LookupContext::fullyQualifiedName(decl));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
Reference in New Issue
Block a user