Menu

cppcheck reporting an AST error

Alex
2022-08-09
2022-08-09
  • Alex

    Alex - 2022-08-09

    cppcheck 2.3
    when i used two compound statement, cppcheck reporting an AST error

    #include <stdio.h>
    #include <stdbool.h>
    
    #define TEST_MACRO(a, b) ({ \
        bool v##a = ((a) & (b)); \
        v##a; \
    }) 
    
    int main() {
        bool r = TEST_MACRO(1, 2) || TEST_MACRO(2, 4);
        if (r) {
            printf("true\n");
        } else {
            printf("false\n");
        }
        return 0;
    }
    

    =>

    Checking test.c ...
    test.c:10:28: error: Syntax Error: AST broken, binary operator '||' doesn't have two operands. [internalAstError]
     bool r = TEST_MACRO(1, 2) || TEST_MACRO(2, 4);
                               ^
    
     
  • CHR

    CHR - 2022-08-09

    Statement expressions are not very well supported, see this ticket: https://trac.cppcheck.net/ticket/9513

     

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.