Menu

Cppcheck 2.18 False positive constParameterReference

2025-10-08
2026-02-25
  • Félix-Antoine Constantin

    Running cppcheck cppcheck --enable=style test.cpp on the following code snippet will result in an error .

    using IntPtr = int *;
    
    int* foo(IntPtr bar)
    {
      return bar = 0;
    }
    

    test.cpp:3:17: style: Parameter 'bar' can be declared as pointer to const [constParameterPointer]

    The problem is that since the type is defined through using (the same behaviour would be observed if I was using typedef), it is not possible to add const here, since it will result in the underlying type int *const rather than const int*.

     
  • Oliver Stöneberg

    Thanks for your report. I filed https://trac.cppcheck.net/ticket/14539 about it.

     

Log in to post a comment.

MongoDB Logo MongoDB