`RULE-0-1-1`: Findings should be suppressed for [[maybe_unused]] initialization

Open
#1,175 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
65/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
cpp
Domain
devtools

Research direction

Locate the implementation and tests for RULE-0-1-1, then trace how initialization assignments involving [[maybe_unused]] are reported. Use the examples in the issue as behavioral cases: suppress the initialization finding, while retaining findings for the later assignments to y and z.

Written by the indexing model from the issue text.

Description

false positive/false negative
Affected rules
  • RULE-0-1-1
Description

If the assignment is initializing a variable with the [[maybe_unused]] attribute, we should not report this.

The presence of [[maybe_unused]] disables other rules according to the MISRA spec, and we should follow that principle here as well. If a variable is [[maybe_unused]], that strongly indicates that there's some kind of conditional compilation that uses the variable value, and that the write is ok.

Note that [[maybe_unused]] should not disable all violations of the rule, only ones that would be fixed by adding any read to the variable.

Example
void example_function() {
  [[maybe_unused]] int x = 0; // reported, but should not be.
  
  [[maybe_unused]] int y = 1; // should still be reported
  y = 2;

  [[maybe_unused]] int z = 3;
  f(z);
  z = 4; // should still be reported.
}
Dominant language
CodeQL
Stars
227
Forks
82
Avg merge
6d 7h
Merged PRs (30d)
9

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from github/codeql-coding-standards

All issues in github/codeql-coding-standards

Similar issues

More DevTools issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.