Menu

New enum type in sizeof expressions gives an error

Rob Arthan
2022-04-24
2022-04-25
  • Rob Arthan

    Rob Arthan - 2022-04-24

    The following 4 line example gives an error on line 4:

    extern int a;
    extern int b;
    int a = sizeof(struct stag {int x, y;});
    int b = sizeof(enum etag {X, Y});
    

    as follows

    Checking t.c ...
    t.c:4:16: error: syntax error [syntaxError]
    int b = sizeof(enum etag {X, Y});
                   ^
    

    I can't see anything wrong with the C code and nor can gcc or clang. I am using the Macports installation of cppcheck version 2.7 and the command line was:

    cppcheck t.c
    

    Using --clang provides a work-around, but I am mainly interested in the MISRA add-on and that doesn't seem to work with --clang.

    I appreciate that the example is fairly silly C, but I am writing test cases and want some obscure examples of type introduction.

    The code is attached.

     
  • CHR

    CHR - 2022-04-25

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

     

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.