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

`A7-1-2`: Alert on move constructor declaration that cannot be `constexpr` specified

Open rvermeulen opened this issue 1 year ago • 0 comments

Affected rules

  • cpp/autosar/function-missing-constexpr

Description

The query alerts on a move constructor declaration outside the class body. Per [dcl.constexpr] paragraph 1, a constexpr shall only be applied to the declaration of a function with the additional constraint that all of its declarations shall contain the constexpr. When the advice associated with the alert is followed, this results in the compilation error:

error: constexpr declaration of 'MyClass' follows non-constexpr declaration

Example

File: myclass.hpp

class MyClass {
 public:
  ...
  MyClass(MyClass&&) noexcept;
  ...
 private:
  int data;
}

File: myclass.cpp

MyClass::MyClass(MyClass&&) noexcept = default;

rvermeulen avatar Feb 09 '24 23:02 rvermeulen