Menu

False positive: [preprocessorErrorDirective]

Fan Zhang
2022-08-03
2022-08-03
  • Fan Zhang

    Fan Zhang - 2022-08-03
    #include <stdio.h>
    
    #define CAT_HELP(A,B)   A##B
    #define CAT(A,B)        CAT_HELP(A,B)
    
    #define NAME(ID)        CAT(bc,ID)
    #define FUNC_NAME(ID)   CAT(NAME(ID),_handler)
    
    // void CAT(NAME(module_1),_handler)() // Changing to this makes the error disappear
    void FUNC_NAME(module_1)()
    {
        printf("Hello\n");
    }
    
    int main()
    {
        bcmodule_1_handler();
    }
    

    Cppcheck outputs:

    Checking ..\test.c ...
    ..\test.c:3:0: error: failed to expand 'FUNC_NAME', Invalid ## usage when expanding 'CAT_HELP': Unexpected token ')' [preprocessorErrorDirective]
    #define CAT_HELP(A,B)   A##B
    ^
    
     
  • Paul Fultz

    Paul Fultz - 2022-08-03

    This might be related to this issue: https://trac.cppcheck.net/ticket/10783

     

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.