Using a very simple test application I noticed that Cppcheck seems to fail to check code after a macro has been used. More specifically, this seems to be an issue when there is no semicolon after the line refering to the macro.
Assume I have some code that uses the USE_A_MACRO macro, defined in an external header called macrodef.h. This header is not part of the files being checked (assume it's in an external library). First of all, I would expect cppcheck to complain about a missing macro definition. I have seen this before, but it does not happen in this case. Worse, when checking the code below, cppcheck will completely skip checking the testfunc() function.
Strangely enough, when I add a semicolon anywhere before the definition of testfunc() cppcheck seems to ignore the missing macro and checks testfunc() as well (without reporting anything about a missing definition).
In the ticket https://trac.cppcheck.net/ticket/6975 which is somewhat similar Daniel wrote that the macro definition should be shown to Cppcheck.
IMHO since there is now a message to report unknown macros i would expect to get at least such a message so the user knows that something is missing.
Last edit: versat 2019-01-03
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi all,
Using a very simple test application I noticed that Cppcheck seems to fail to check code after a macro has been used. More specifically, this seems to be an issue when there is no semicolon after the line refering to the macro.
Assume I have some code that uses the USE_A_MACRO macro, defined in an external header called macrodef.h. This header is not part of the files being checked (assume it's in an external library). First of all, I would expect cppcheck to complain about a missing macro definition. I have seen this before, but it does not happen in this case. Worse, when checking the code below, cppcheck will completely skip checking the testfunc() function.
Strangely enough, when I add a semicolon anywhere before the definition of testfunc() cppcheck seems to ignore the missing macro and checks testfunc() as well (without reporting anything about a missing definition).
I would think this is incorrect behavior, resulting in unpredictable code checking results. Would it be possible to look into this?
Related trac tickets i found:
https://trac.cppcheck.net/ticket/6975
https://trac.cppcheck.net/ticket/7902
With the latest git HEAD i can reproduce the results:
In the ticket https://trac.cppcheck.net/ticket/6975 which is somewhat similar Daniel wrote that the macro definition should be shown to Cppcheck.
IMHO since there is now a message to report unknown macros i would expect to get at least such a message so the user knows that something is missing.
Last edit: versat 2019-01-03