CppEditor: Consider templates in "complete switch" quickfix

Fixes: QTCREATORBUG-24752
Change-Id: I39bc007e5f493a9826adb4575eb210bf9ec21159
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
Christian Kandeler
2020-10-09 15:38:23 +02:00
parent bd05e01e3d
commit 023a77ea80
2 changed files with 27 additions and 0 deletions

View File

@@ -596,6 +596,32 @@ void CppEditorPlugin::test_quickfix_data()
"" ""
); );
// Checks: complete switch statement where enum is goes via a template type parameter
QTest::newRow("CompleteSwitchCaseStatement_QTCREATORBUG-24752")
<< CppQuickFixFactoryPtr(new CompleteSwitchCaseStatement) << _(
"enum E {EA, EB};\n"
"template<typename T> struct S {\n"
" static T theType() { return T(); }\n"
"};\n"
"int main() {\n"
" @switch (S<E>::theType()) {\n"
" }\n"
"}\n"
) << _(
"enum E {EA, EB};\n"
"template<typename T> struct S {\n"
" static T theType() { return T(); }\n"
"};\n"
"int main() {\n"
" switch (S<E>::theType()) {\n"
" case EA:\n"
" break;\n"
" case EB:\n"
" break;\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".

View File

@@ -2744,6 +2744,7 @@ Enum *conditionEnum(const CppQuickFixInterface &interface, SwitchStatementAST *s
Block *block = statement->symbol; Block *block = statement->symbol;
Scope *scope = interface.semanticInfo().doc->scopeAt(block->line(), block->column()); Scope *scope = interface.semanticInfo().doc->scopeAt(block->line(), block->column());
TypeOfExpression typeOfExpression; TypeOfExpression typeOfExpression;
typeOfExpression.setExpandTemplates(true);
typeOfExpression.init(interface.semanticInfo().doc, interface.snapshot()); typeOfExpression.init(interface.semanticInfo().doc, interface.snapshot());
const QList<LookupItem> results = typeOfExpression(statement->condition, const QList<LookupItem> results = typeOfExpression(statement->condition,
interface.semanticInfo().doc, interface.semanticInfo().doc,