`M5-3-1`: False positives in unevaluated contexts associated with uninstantiated templates
lcartey opened this issue · 0 comments
lcartey commented
Affected rules
M5-3-1
Description
This rule is reporting false positives in unevaluated contexts associated with uninstantiated templates. For example:
noexceptspecifiers of functions.static_asserts within template functions (not consistently).
In these cases, the type of the operand of the boolean operator is UnknownType, which is flagged by the query as not boolean.
In principle, we should be able to exclude these cases by specifying not operand.isFromUninstantiatedTemplate(_). However, this doesn't apply to e.g. noexcept specifiers. We also see examples where static_asserts for the uninstantiated template are orphaned, and not associated with the uninstantiated template.
The fix is to exclude operands with the type UnknownType.
Example
template <typename T> constexpr bool some_variable_template_v = false;
template <> constexpr bool some_variable_template_v<int> = true;
template <typename S>
void template_with_no_except()
noexcept(some_variable_template_v<S> && true) { // COMPLIANT
}
void test_template() { template_with_no_except<int>(); }