Menu

Inconsistent behavior in autoVariable checker

safans
2026-06-11
2026-06-12
  • safans

    safans - 2026-06-11

    Hi, I found an inconsistent behavior in the autoVariables checker.

    The following two cases are semantically equivalent. However, cppcheck correctly flags the first program with an autoVariables warning, while missing the issue in the second program. Therefore, I believe this is a false negative bug.

    static void foo(int **a)
    {
        int b = 1;
        *a = &b;
    }
    int main()
    {
        int *c;
        foo(&c);
        return 0;
    }
    
    static void foo(int **a)
    {
        auto b = 1;
        *a = &b;
    }
    int main()
    {
        int *c;
        foo(&c);
        return 0;
    }
    

    Version: 2.19.0

     
  • CHR

    CHR - 2026-06-11

    Please check with current head, I'm getting a warning for both examples.

     
  • safans

    safans - 2026-06-12

    Thank you! I verified it with a newer version and Cppcheck caught the warning. It's indeed an old bug.

     

Log in to post a comment.

Auth0 Logo