Two issue related to parsing -D flag values from compile_commands.json:
* Quotes are dropped from quoted values
* Flag values containing spaces are completely dropped
This can be shown by looking at the -D values printed by cppcheck in its config summary...
(Note that in the config summary, the value passed on the CLI remains quoted, whereas the one from the project file does not.)
@danielmarjamaki I've attached a patch file for test/testimportproject.cpp
that adds tests for quoted -D symbol values.
We have code that requires certain string literals to be supplied via -D defines.
Dropping the quotes results in cppcheck reporting syntax errors or false-positive errors (e.g if contents of the string literal matches a valid symbol name)
Using cppcheck 2.13.0
Two issue related to parsing
-D
flag values fromcompile_commands.json
:* Quotes are dropped from quoted values
* Flag values containing spaces are completely dropped
This can be shown by looking at the
-D
values printed by cppcheck in its config summary...(Note that in the config summary, the value passed on the CLI remains quoted, whereas the one from the project file does not.)
(using bear to generate the json file)
Inspecting
compile_commands.json
we can see the JSON is well formed and properly quoted...If a quoted value contains spaces then the value is dropped completely.
(Note that
PROJ_LITERAL
is not reported in the config summary.)Last edit: Chris Hollis-Locke 2024-08-16
@danielmarjamaki I've attached a patch file for
test/testimportproject.cpp
that adds tests for quoted
-D
symbol values.We have code that requires certain string literals to be supplied via
-D
defines.Dropping the quotes results in cppcheck reporting syntax errors or false-positive errors (e.g if contents of the string literal matches a valid symbol name)
Thanks! I have created ticket: https://trac.cppcheck.net/ticket/13019
if you have time to make a fix also that would be excellent. The handling of quotes is not trivial as far as I remember.