diff --git a/.cppcheck b/.cppcheck new file mode 100644 index 0000000000..23c339928e --- /dev/null +++ b/.cppcheck @@ -0,0 +1,9 @@ +// clang-format off +constParameter +unusedFunction +missingIncludeSystem +noConstructor +noExplicitConstructor +redundantAssignment +uselessAssignmentPtrArg +preprocessorErrorDirective diff --git a/CMakeLists.txt b/CMakeLists.txt index 3635237e69..85b3a368b6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -77,6 +77,7 @@ option(WITH_STOKESIAN_DYNAMICS "Build with Stokesian Dynamics" OFF) option(WITH_BENCHMARKS "Enable benchmarks" OFF) option(WITH_VALGRIND_INSTRUMENTATION "Build with valgrind instrumentation markers" OFF) +option(WITH_CPPCHECK "Run Cppcheck during compilation" OFF) if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") option(WITH_CLANG_TIDY "Run Clang-Tidy during compilation" OFF) endif() @@ -421,6 +422,19 @@ if(WITH_CLANG_TIDY) set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_EXE};--extra-arg=--cuda-host-only") endif() +if(WITH_CPPCHECK) + find_program(CMAKE_CXX_CPPCHECK NAMES cppcheck) + if(NOT CMAKE_CXX_CPPCHECK) + message(FATAL_ERROR "Could not find the program cppcheck.") + endif() + list(APPEND CMAKE_CXX_CPPCHECK "--enable=all" + "--std=c++${CMAKE_CXX_STANDARD}" "--quiet" "--inline-suppr" + "--suppressions-list=${CMAKE_CURRENT_SOURCE_DIR}/.cppcheck") + if(WARNINGS_ARE_ERRORS) + list(APPEND CMAKE_CXX_CPPCHECK "--error-exitcode=2") + endif() +endif() + # # Testing # diff --git a/src/core/CellStructure.hpp b/src/core/CellStructure.hpp index d792ae99a5..d204154c5c 100644 --- a/src/core/CellStructure.hpp +++ b/src/core/CellStructure.hpp @@ -153,6 +153,7 @@ struct CellStructure { */ void update_particle_index(int id, Particle *p) { assert(id >= 0); + // cppcheck-suppress assertWithSideEffect assert(not p or id == p->identity()); if (id >= m_particle_index.size())