Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
lcartey opened this issue Feb 6, 2025 · 0 comments · May be fixed by #852
Open

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

lcartey opened this issue Feb 6, 2025 · 0 comments · May be fixed by #852
Assignees
Labels
Difficulty-Low A false positive or false negative report which is expected to take <1 day effort to address false positive/false negative An issue related to observed false positives or false negatives. Impact-Medium

Comments

@lcartey
Copy link
Collaborator

lcartey commented Feb 6, 2025

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>(); }
@lcartey lcartey added Difficulty-Low A false positive or false negative report which is expected to take <1 day effort to address false positive/false negative An issue related to observed false positives or false negatives. Impact-Medium labels Feb 6, 2025
@lcartey lcartey self-assigned this Feb 6, 2025
@lcartey lcartey moved this from Reported to Triaged in Coding Standards Public Development Board Feb 6, 2025
@lcartey lcartey moved this from Triaged to In Progress in Coding Standards Public Development Board Feb 6, 2025
@lcartey lcartey moved this from In Progress to Ready for review in Coding Standards Public Development Board Feb 6, 2025
@lcartey lcartey linked a pull request Feb 6, 2025 that will close this issue
30 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Difficulty-Low A false positive or false negative report which is expected to take <1 day effort to address false positive/false negative An issue related to observed false positives or false negatives. Impact-Medium
Projects
Status: Ready for review
Development

Successfully merging a pull request may close this issue.

1 participant