Menu

Preprocessor fails to make arithmetic calculation

vilox
2021-01-21
2021-01-23
  • vilox

    vilox - 2021-01-21

    Let check this test.c:

    #if ((0xffffffffffffffffULL) % 0xFFFF)
    # error BOOOOM
    #endif
    int main(void) { return 0; }
    

    $ cppcheck --enable=all --error-exitcode=17 test.c ; echo $?
    Checking test.c ...
    0

    ... nice. But suddenly

    $ cppcheck --enable=all --error-exitcode=17 -DSOME test.c; echo $?
    Checking test.c ...
    test.c:2:0: error: #error BOOOOM [preprocessorErrorDirective]
    # error BOOOOM
    ^
    17

    Applies to version 2.3, current git (2020-12-28 b94a6d595), debian 10 on x64.
    I do not have bugtracker account, so report this here.

     
  • Daniel Marjamäki

    Thanks! I have created ticket https://trac.cppcheck.net/ticket/10132

    The analysis of the test.c is essentially skipped because there is #error. I believe this is a usability problem more or less.

    Normally we just want to skip configurations that lead to an #error.. we do not want to set the error exitcode and we do not want to check those configurations..

    If all configurations that are checked have an #error then maybe it would make sense to write some information message that cppcheck fails to analyze the file. Setting the error exitcode also sounds reasonable..

     

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.