Skip to content

M5-3-1: False positives in unevaluated contexts associated with uninstantiated templates #851

Closed
@lcartey

Description

@lcartey

Affected rules

  • M5-3-1

Description

This rule is reporting false positives in unevaluated contexts associated with uninstantiated templates. For example:

  • noexcept specifiers 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>(); }

Metadata

Metadata

Assignees

Labels

Difficulty-LowA false positive or false negative report which is expected to take <1 day effort to addressImpact-Mediumfalse positive/false negativeAn issue related to observed false positives or false negatives.

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions