Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A7-1-2: constexpr in templates #609

Open
lcartey opened this issue Jun 3, 2024 · 0 comments
Open

A7-1-2: constexpr in templates #609

lcartey opened this issue Jun 3, 2024 · 0 comments
Labels
Difficulty-High A false positive or false negative report which is expected to take 1+ week effort to address false positive/false negative An issue related to observed false positives or false negatives. Impact-Low user-report Issue reported by an end user of CodeQL Coding Standards

Comments

@lcartey
Copy link
Collaborator

lcartey commented Jun 3, 2024

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>();
}
@lcartey lcartey added Difficulty-High A false positive or false negative report which is expected to take 1+ week effort to address false positive/false negative An issue related to observed false positives or false negatives. Impact-Low user-report Issue reported by an end user of CodeQL Coding Standards labels Jun 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Difficulty-High A false positive or false negative report which is expected to take 1+ week effort to address false positive/false negative An issue related to observed false positives or false negatives. Impact-Low user-report Issue reported by an end user of CodeQL Coding Standards
Projects
Development

No branches or pull requests

1 participant