Florian George - 2019-03-19

Starting with version 1.82, the attached error.cpp will cause CppCheck to show a syntax error in line 50:

"c:\Program Files\Cppcheck\cppcheck.exe" error.cpp
Checking error.cpp ...
[error.cpp:50]: (error) syntax error

This is a minimum repro case, if something like this is encountered in e.g. an include file, checking of the cpp file including this file will not continue after this error is encountered.

With version 1.81, the syntax error will not occur, and checking will continue.

Something similar has been reported previously in 2016 but has probably a different cause as 1.81 was released in 2017: https://sourceforge.net/p/cppcheck/discussion/general/thread/c1894ccb/?limit=25

From that thread, I tried this:

cppcheck -E file-with-syntax-error.cpp > E.cpp
cppcheck E.cpp

Here's the output with version 1.87:

"c:\Program Files\Cppcheck\cppcheck.exe" -E error.cpp > E.cpp
"c:\Program Files\Cppcheck\cppcheck.exe" E.cpp
Checking E.cpp ...
[E.cpp:51]: (error) syntax error

Here's the output with version 1.81:

"c:\Program Files\Cppcheck\cppcheck.exe" -E error.cpp > E.cpp
"c:\Program Files\Cppcheck\cppcheck.exe" E.cpp
Checking E.cpp ...

The created E.cpp seems to be identical for both versions, with all the defines from error.cpp removed, and STRIP_PARENTHESES being replaced with COND_STRIP_PARENS_1.

So apparently in both versions, the cppcheck preprocessor stops replacing terms after a couple iterations (maybe to avoid a possible endless loop?), and the old version would give such an aborted replacement term a pass, while the new version is kindof correct in giving an error, but the resulting behavior is of course less desirable than just ignoring the incompletely replaced term.