`A7-1-2`: `constexpr` in templates

Open
#609 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
cpp
Domain
devtools

Research direction

Start by locating the implementation and tests for the A7-1-2 rule. Use the provided C++ template example to reproduce the false positive, then verify that a variable is reported only when all visible instantiations can use constexpr.

Written by the indexing model from the issue text.

Description

Difficulty-High false positive/false negative Impact-Low Standard-AUTOSAR user-report
Affected rules
  • A7-1-2
Description

We should only report a variable in a template as a candidate for adding constexpr if all visible instantiations could use constexpr.

Example
int x;

constexpr int* init_t(int i) {
  return &x;
}

float* init_t(float f) {
  return new float();
}

template <typename T> void constexpr_variable_template() {
  constexpr T t1{};
  T* t = init_t(t1); // COMPLIANT[FALSE_POSITIVE] for int, this could be constexpr, but not for float
}

void test() {
  constexpr_variable_template<int>();
  constexpr_variable_template<float>();
}
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.