cppcheck currently has issue parsing the macros of the catch2 project, a test suite for c++
A minimal example for reproducing the issue looks like following
main.cpp
#define CATCH_CONFIG_MAIN#include"catch_amalgamated.hpp"intfactorial(intnumber){returnnumber<=1?number:factorial(number-1)*number;}TEST_CASE("Factorials are computed"){REQUIRE_THROWS_AS(factorial(1),int);}
then download catch_amalgamated.cpp and catch_amalgamated.hpp from the catch project (https://github.com/catchorg/Catch2) in the same directory (issue is also reproducible with the non-amalgamated library
the project can be compiled and executed with "g++ main.cpp catch_amalgamated.cpp && ./a.out"
It's probably best to create a library configuration for Catch2 (similar to e.g. googletest.cfg that we already have) and not make headers like catch_amalgamated.hppvisible to cppcheck.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
It would be better if cppcheck is able to handle such construct too, but having a short-term solution is fine too, as it makes possible to use cppcheck on the test suite too
catch headers should all match the pattern "catch_.*\.hpp"
Last edit: federico 2024-07-11
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello, I want to report a bug.
cppcheck currently has issue parsing the macros of the catch2 project, a test suite for c++
A minimal example for reproducing the issue looks like following
main.cpp
then download catch_amalgamated.cpp and catch_amalgamated.hpp from the catch project (https://github.com/catchorg/Catch2) in the same directory (issue is also reproducible with the non-amalgamated library
the project can be compiled and executed with "g++ main.cpp catch_amalgamated.cpp && ./a.out"
compile_command.json
"cppcheck main.cpp" reports as error
and the issue persists when using a compile_command.json project file
Note that _catch_sr is not a macro, but is concatenated to a macro, for example
Last edit: federico 2024-06-28
It's probably best to create a library configuration for Catch2 (similar to e.g. googletest.cfg that we already have) and not make headers like
catch_amalgamated.hpp
visible to cppcheck.It would be better if cppcheck is able to handle such construct too, but having a short-term solution is fine too, as it makes possible to use cppcheck on the test suite too
catch headers should all match the pattern "catch_.*\.hpp"
Last edit: federico 2024-07-11