Skip to content

A7-1-2: constexpr in templates #609

Open
@lcartey

Description

@lcartey

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>();
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Difficulty-HighA false positive or false negative report which is expected to take 1+ week effort to addressImpact-LowStandard-AUTOSARfalse positive/false negativeAn issue related to observed false positives or false negatives.user-reportIssue reported by an end user of CodeQL Coding Standards

    Type

    No type

    Projects

    Status

    Triaged

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions