Menu

false positive syntaxError for more than one unnamed volatile bitfield

Adel Mamin
2025-03-18
2025-03-18
  • Adel Mamin

    Adel Mamin - 2025-03-18

    Cppcheck 2.16.0

    C code (bitfields.c):

    #include <stdint.h>
    #include <stdio.h>
    
    struct foo {
        volatile uint32_t a : 10;
        volatile uint32_t /*reserved*/ : 6;
        volatile uint32_t b : 10;
        volatile uint32_t /*reserved*/ : 6;
    };
    
    int main(void) {
        struct foo foo_ = {0};
        for (uint32_t i = 0; i < (uint32_t)2; ++i) {
            printf("[%u] foo_ = %u\n", foo_.b);
        }
        return 0;
    }
    

    cppcheck output:

    > cppcheck bitfields.c
    Checking bitfield.c ...
    bitfield.c:13:5: error: syntax error [syntaxError]
        for (uint32_t i = 0; i < (uint32_t)2; ++i) {
        ^
    

    Assigning dummy names to unnamed bitfields of struct foo makes the warning disappear.

     

    Last edit: Adel Mamin 2025-03-18
  • CHR

    CHR - 2025-03-18

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

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.