Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
M9-3-1 and std::span-like classes
#1
Hi,

Our static analyzer is reporting a violation of M9-3-1 in the following backport of C++20's `std:Confusedpan`:

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!
Reply


Messages In This Thread
M9-3-1 and std::span-like classes - by cgpzs - 18-02-2022, 09:42 AM
RE: M9-3-1 and std::span-like classes - by cgpzs - 23-02-2022, 12:00 PM

Forum Jump:


Users browsing this thread: 2 Guest(s)