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

`A7-1-2`: Qualifier cannot be declared `constexpr`

Open jsinglet opened this issue 2 years ago • 0 comments

Affected rules

  • A7-1-2

Description

False positive reported for the following test case. In the example, below, a712 must be constexpr for value to be declared constexpr. However, it is not possible to declare parameters (easily) as constexpr. The mitigation for this issue is likely that cases where it is not possible to declare the qualifier as constexpr.

Example

class A7_1_2 {
 public:
  constexpr auto GetValue() const noexcept { return value_; }
  void SetValue(int32_t value) noexcept { value_ = value; }
 private:
  int32_t value_;
};
std::ostream &operator<<(std::ostream &os, const A7_1_2 a712) noexcept {
  const auto value = a712.GetValue(); // Variable value could be marked 'constexpr'.
  os << value;
  return os;
}

jsinglet avatar Sep 14 '22 14:09 jsinglet