Menu ▾ ▴

constVariable not reported for an array of a typedef'd type (2.22.0)

2026-11-02
6 days ago
  • Ahmed Lotfy

    Ahmed Lotfy - 2026-11-02

    Cppcheck 2.22.0 reports "can be declared as const array" for an array of
    unsigned char, but not when the element type is a typedef of unsigned char.

    Reported (expected):
    static int f(const unsigned char *d, int n);
    int g(void) { unsigned char a[4] = {0}; return f(a, 4); }

    constVariable: Variable 'a' can be declared as const array
    

    Not reported (false negative):
    typedef unsigned char u8;
    static int f(const u8 *d, int n);
    int g(void) { u8 a[4] = {0}; return f(a, 4); }

    Command: cppcheck --enable=style --std=c99 test.c
    It is also reported for uint8_t (from <stdint.h>) and when the type is unknown.
    Expected: constVariable for the typedef case too.</stdint.h>

     
  • CHR

    CHR - 6 days ago

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

     

Log in to post a comment.