`A0-1-1`: initialization of constexpr used as NTTP is detected as useless assignment

Open
#728 0 comments 0 reactions 1 assignee View on GitHub

@lcartey is already working on this.

Since Jan 17, 2025.

  • #732 by @fjatWbyT — merged

Assessment

This issue has not been assessed yet.

Description

Difficulty-Medium false positive/false negative Impact-Medium Standard-AUTOSAR user-report
Affected rules
  • A0-1-1 (useless assignment)
Description

Constant expression used as non-type template parameter (NTTP) produces useless-assignment false positive. It can be reproduced with integer NTTP.

Example
#include <ratio>

int main() {
  constexpr int one      = 1;     // True positive, this one is indeed unused (therefore, assignment is useless).
  constexpr int thirteen = 13;    // False positive, used in the second argument:
                                  // it can be verified that main returns 13.
  std::ratio<1, thirteen> ratio;
  return ratio.den;
}

Both definitions of one and thirteen are alerted as unused on query cpp/autosar/src/rules/A0-1-1/UselessAssignment.ql.

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.