Skip to content

A7-1-2: Consider constexpr function behaviour #466

Closed
@lcartey

Description

@lcartey

Affected rules

  • A7-1-2

Description

A constexpr function only returns a compile-time constant when provided with compile-time constants as arguments. The query currently incorrectly considers constexpr functions to always return constants.

Example

This function should only be considerd

constexpr int add(int x, int y) {
  return x + y;
}

void test(int p) {
  int x = add(1,2); // NON_COMPLIANT - could be marked constexpr
  int y = add(1,p); // COMPLIANT - cannot be marked constexpr

Metadata

Metadata

Assignees

Labels

Difficulty-LowA false positive or false negative report which is expected to take <1 day effort to addressImpact-Mediumfalse 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

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions