CppEditor: Fix switch statement completion

... for the case where the value is retrieved via a call to a template
function whose scope does not include the template type.

Fixes: QTCREATORBUG-25998
Change-Id: Ie33817f445fb53595b783f716093637926297549
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
Christian Kandeler
2021-07-27 12:36:21 +02:00
parent ec9f972355
commit 2798c11d1d
2 changed files with 29 additions and 1 deletions

View File

@@ -907,6 +907,34 @@ void CppEditorPlugin::test_quickfix_data()
"}\n"
);
// Checks: Complete switch statement where enum is return type of a template function
// which is outside the scope of the return value.
// TODO: Type minimization.
QTest::newRow("CompleteSwitchCaseStatement_QTCREATORBUG-25998")
<< CppQuickFixFactoryPtr(new CompleteSwitchCaseStatement) << _(
"template <typename T> T enumCast(int value) { return static_cast<T>(value); }\n"
"class Test {\n"
" enum class E { V1, V2 };"
" void func(int i) {\n"
" @switch (enumCast<E>(i)) {\n"
" }\n"
" }\n"
"};\n"
) << _(
"template <typename T> T enumCast(int value) { return static_cast<T>(value); }\n"
"class Test {\n"
" enum class E { V1, V2 };"
" void func(int i) {\n"
" switch (enumCast<E>(i)) {\n"
" case Test::E::V1:\n"
" break;\n"
" case Test::E::V2:\n"
" break;\n"
" }\n"
" }\n"
"};\n"
);
// Checks: No special treatment for reference to non const.
// Check: Quick fix is not triggered on a member function.