codeql-coding-standards
codeql-coding-standards copied to clipboard
`M9-3-3`: Identify indirect assignment of member data
Affected rules
-
M9-3-3
Description
Improve the rule to detect assignment into references or pointers into member data.
Example
In this example we see a member function which modifies a member variable called values_, by iterating through and taking a reference to each element.
template <typename U = T>
void fill(const T& val) {
for (auto& elem : values_) {
elem = val;
}
}
Another example:
constexpr T& front() noexcept { return values_[0]; }
the original issue reported here was related to templates, and was fixed in a previous issue
but the second example constexpr int &front() noexcept { return values[0]; } // COMPLIANT was due to a logic omission