Menu

define alias stops analysis

2023-04-16
2024-12-13
  • Cristian Del Fabbro

    Hi,
    I found a preprocessor error in working code that stops cppcheck to continue analysis:

    #define IS_ENABLED(config_macro) Z_IS_ENABLED1(config_macro)
    #define Z_IS_ENABLED1(config_macro) Z_IS_ENABLED2(_XXXX##config_macro)
    #define _XXXX1 _YYYY,
    #define Z_IS_ENABLED2(one_or_two_args) Z_IS_ENABLED3(one_or_two_args 1, 0)
    #define Z_IS_ENABLED3(ignore_this, val, ...) val
    
    #define FOO 1
    
    int main() {
        return IS_ENABLED(FOO);
    }
    

    Cppcheck says:

    test.cpp:3:0: error: failed to expand 'IS_ENABLED', Wrong number of parameters for macro 'Z_IS_ENABLED2'. [preprocessorErrorDirective]
    #define Z_IS_ENABLED1(config_macro) Z_IS_ENABLED2(_XXXX##config_macro)
    ^
    

    but the code is compilable and works fine.
    If FOO is defined to 0, it is fine for cppcheck.
    If FOO is undefined, it is fine for cppcheck.

    The IS_ENABLED define is not mine, it is from Zephyr code:
    https://docs.zephyrproject.org/apidoc/latest/util__macro_8h_source.html
    https://docs.zephyrproject.org/apidoc/latest/util__internal_8h_source.html
    I extracted it for minimal code.

    Thanks,
    Cristian

     
  • Daniel Marjamäki

    Thanks for reporting this. I created this issue: https://github.com/danmar/simplecpp/issues/295

     
  • Daniel Marjamäki

    this is solved in the latest git head of the simplecpp library. It should work properly in coming releases simplecpp 1.2.x / cppcheck 2.17

     

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.