Search code examples
c++static-analysiscppcheck

A warning with cppcheck, "hides typedef with same name"


This is a cppcheck warning message.
Variable 'BUFFER_INFO' hides typedef with same name

The BUFFER_INFO is defined as following.

typedef struct tagBufferInfo
{
    CRITICAL_SECTION cs;
    Buffer* pBuffer1;
    Buffer* pBuffer2;
    Buffer* pLoggingBuffer;
    Buffer* pSendingBuffer;
}BUFFER_INFO, *PBUFFER_INFO;

And I wrote,

PBUFFER_INFO p = new BUFFER_INFO; // causes the warning.

What is the problem? How do I solve it?
Thanks.


Solution

  • This looks like it might be a cppcheck bug.

    However... what you have written is bad C++ style, prefer:

    struct BUFFER_INFO
    {
        CRITICAL_SECTION cs;
        Buffer* pBuffer1;
        Buffer* pBuffer2;
        Buffer* pLoggingBuffer;
        Buffer* pSendingBuffer;
    };
    

    I would also observe that it is not good C++ style to use all uppercase for type names (these are normally reserved for constants) and that typedefs that hide the fact that something is a pointer are normally not a good idea.