I see a false positive running cppcheck 2.22.0 against the following code. Note the function itself cannot be static because it's an explicit member function (deducing this).
#include <array> #include <cstddef> #include <ranges> #include <span> constexpr std::size_t GridSize{19}; class board { public: auto rows(this auto&& self) { auto* cells = self.data.data(); return std::views::iota(0zu, GridSize) | std::views::transform([cells](std::size_t row) { return std::span{cells + row * GridSize, GridSize}; }); } private: std::array<int, GridSize * GridSize> data{}; }; int main() { board value; const auto rows = value.rows(); const auto firstRow = *rows.begin(); (void)firstRow; }
cppcheck output:
cppcheck_deducing_this_rows.cpp:11:10: style: The member function 'board::rows' can be static. [functionStatic] auto rows(this auto&& self) ^
Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/15089
Log in to post a comment.
I see a false positive running cppcheck 2.22.0 against the following code. Note the function itself cannot be static because it's an explicit member function (deducing this).
cppcheck output:
Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/15089