`M7-5-1`: Class members are considered as **automatic** variables
Closed this issue · 1 comments
nbusser-sr commented
Affected rules
M7-5-1
Rule 7–5–1
A function shall not return a reference or a pointer to
an automatic variable (including parameters), defined
within the function
Description
When a function returns a reference to a class member, this class member is wrongly considered as an automatic variable.
Example
class M7_5_1 {
private:
/// Variable to be referenced
std::uint32_t val_;
public:
/// Triggers M7_5_1
std::uint32_t& M7_5_1() noexcept {
return val_;
}
}lcartey commented
Thanks! This issue was introduced during some refactoring for MISRA C++ 2023. The problem is that the query refers to Variable instead of StackVariable, so no longer considers locality. This should be a straightforward fix, along with augmenting our test cases.