codeql-coding-standards icon indicating copy to clipboard operation
codeql-coding-standards copied to clipboard

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

Open fjatWbyT opened this issue 1 year ago • 0 comments

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.

fjatWbyT avatar Oct 03 '24 08:10 fjatWbyT