18-02-2022, 09:42 AM
Hi,
Our static analyzer is reporting a violation of M9-3-1 in the following backport of C++20's `std:pan`:
The `Span` class is merely a non-owning wrapper around a memory buffer. Furthermore, the `data()` function is not returning a reference to any class member, it's returning a copy of a class member.
Would you say M9-3-1 is violated in this example?
Thanks!
Our static analyzer is reporting a violation of M9-3-1 in the following backport of C++20's `std:pan`:
Code:
template <typename T>
class Span
{
public:
Span(T* const ptr, std::size_t size) :
data_{ptr},
size_{size}
{}
T* data() const { return data_; } // M9-3-1 reported here
private:
T* data_;
std::size_t size_;
};
int main()
{
std::array<int, 3> arr{1,2,3};
Span<int> s{arr.data(), arr.size()};
}
The `Span` class is merely a non-owning wrapper around a memory buffer. Furthermore, the `data()` function is not returning a reference to any class member, it's returning a copy of a class member.
Would you say M9-3-1 is violated in this example?
Thanks!