I'm using 2.5
This is a false-positive because buffer actually gets written too
constParameter - Parameter 'buffer' can be declared with const
namespace constParameterFalsePositive { class CustomBuffer { public: CustomBuffer() : Data() , Position(0) { } CustomBuffer& operator<<(char value) { if(Size > Position) { Data[Position++] = value; } return *this; } private: static const int Size = 256; unsigned char Data[Size]; int Position; }; class SerializeHelper { public: // This causes cppcheck to loose context and not realize the buffer is changed calling // the function below. This simulates having a pimpled class for ABI compatibility reasons. // In the case where this was discovered we are using the private implementation and not 'this'. SerializeHelper* getPrivatePtr() { return this; } CustomBuffer& operator<<(CustomBuffer& buffer) { buffer << '2'; return buffer; } }; CustomBuffer& operator<<(CustomBuffer& buffer, SerializeHelper& rhs) { // the problem is caused by using getPrivatePtr and loss of context return rhs.getPrivatePtr()->operator<<(buffer); } }
Sorry for slow response. I can reproduce and will work on fixing it..
Log in to post a comment.
I'm using 2.5
This is a false-positive because buffer actually gets written too
constParameter - Parameter 'buffer' can be declared with const
Last edit: Steve Albright 2021-09-09
Sorry for slow response. I can reproduce and will work on fixing it..