Menu

constParameter FP

2022-05-23
2022-05-23
  • Julien Jorge

    Julien Jorge - 2022-05-23

    Hello,

    On the following code:

    struct s
    {
      int& value() { return value; }
      int m_value;
    };
    
    void
    foo(s* a, int* f)
    {
      *f = (a - 1)->value();
    }
    

    cppcheck 2.6.3, 2.7.5, and current main (8d1fd19cc66d4a15ecb62253e0cb84e9854e6b86), all report the following style error:

    style: Parameter 'a' can be declared with const [constParameter]
    foo(s a, int f)
    ^

    I think this is a false positive since s const* a would not compile, and s* const a has dubious value. Moreover there is no reason to expect the latter syntax for a and not for f. Note that both modifications prevent the error.

    Version 2.3 does not report the error, and I could not check versions in-between.

     
  • CHR

    CHR - 2022-05-23

    Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/11095

     

Log in to post a comment.