Menu

Cppcheck not able to suppress errors on a symbol during preprocessing stage

Fan Zhang
2022-06-29
2022-07-05
  • Fan Zhang

    Fan Zhang - 2022-06-29

    Cppcheck reports syntaxError on the following code:

    #define DEF_VAR(NAME,ADDR) _symbol NAME ADDR
    DEF_VAR(nice_name, 0x00)
    

    Output:

    Checking test.h ...
    test.h:5:1: error: syntax error [syntaxError]
    DEF_VAR(nice_name, 0x00)
    ^
    

    I stepped into the source code and it turned out to be that the syntax error was due to missing ';' at the end, therefore an exception was raised during preprocessing(simplifyTokens). It doesn't pass the symbol name (DEF_VAR) to the error message, so errors on this symbol will not be suppressed.

    And I cannot define a rule to make it a different severity because it happens during preprocessing.

    The only way I currently found working was adding inline suppression (too many of them) or suppressing the error for the whole file (other errors in the file will be suppressed, too).

    My questions:

    Is it the intention that symbol name is not passed to the error message during preprocessing so that it is not supposed to be suppressed? If yes why?
    What would be the best why to suppress this error? (This is a compiler specific syntax)

     
  • Daniel Marjamäki

    if it's some kind of variable declaration it should end with a semicolon or something.

    gcc output:

    danielm@debian:~/cppcheck$ cat 1.c
    int x
    danielm@debian:~/cppcheck$ gcc -fsyntax-only 1.c
    1.c:1:1: error: expected =, ,, ;, asm or __attribute__ at end of input
        1 | int x
          | ^~~
    
     
    • Fan Zhang

      Fan Zhang - 2022-07-05

      For gcc yes. But there are other compilers in the world for example chess compiler from Synopsys takes lines like _symbol myvar 123 without semicolon in the end

       

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.