diff --git a/.github/workflows/CI-mingw.yml b/.github/workflows/CI-mingw.yml index b5c067dc7..75de79ed1 100644 --- a/.github/workflows/CI-mingw.yml +++ b/.github/workflows/CI-mingw.yml @@ -47,6 +47,7 @@ jobs: with: key: ${{ github.workflow }}-${{ github.job }}-${{ matrix.os }} + # TODO: bail out on warning - name: Build cppcheck run: | export PATH="/mingw64/lib/ccache/bin:$PATH" diff --git a/.github/workflows/CI-unixish-docker.yml b/.github/workflows/CI-unixish-docker.yml index 9bfc5a017..c8095c54a 100644 --- a/.github/workflows/CI-unixish-docker.yml +++ b/.github/workflows/CI-unixish-docker.yml @@ -135,13 +135,13 @@ jobs: run: | # "/usr/lib64" for centos / "/usr/lib" for ubuntu export PATH="/usr/lib64/ccache:/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH" - make -j$(nproc) HAVE_RULES=yes + make -j$(nproc) HAVE_RULES=yes CXXFLAGS="-w" - name: Build test run: | # "/usr/lib64" for centos / "/usr/lib" for ubuntu export PATH="/usr/lib64/ccache:/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH" - make -j$(nproc) testrunner HAVE_RULES=yes + make -j$(nproc) testrunner HAVE_RULES=yes CXXFLAGS="-w" - name: Run test run: | diff --git a/.github/workflows/CI-unixish.yml b/.github/workflows/CI-unixish.yml index b2d35df36..9f80c4500 100644 --- a/.github/workflows/CI-unixish.yml +++ b/.github/workflows/CI-unixish.yml @@ -450,7 +450,7 @@ jobs: run: | export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH" # compile with verification and ast matchers - make -j$(nproc) -s CPPFLAGS="-DCHECK_INTERNAL" CXXFLAGS="-g -O2 -DHAVE_BOOST" MATCHCOMPILER=yes VERIFY=1 + make -j$(nproc) -s CPPFLAGS="-DCHECK_INTERNAL" CXXFLAGS="-g -O2 -w -DHAVE_BOOST" MATCHCOMPILER=yes VERIFY=1 - name: Generate UI files run: | diff --git a/.github/workflows/asan.yml b/.github/workflows/asan.yml index 428528e4a..e57ac201d 100644 --- a/.github/workflows/asan.yml +++ b/.github/workflows/asan.yml @@ -59,6 +59,7 @@ jobs: modules: 'qtcharts' cache: true + # TODO: disable all warnings - name: CMake run: | cmake -S . -B cmake.output -DCMAKE_BUILD_TYPE=RelWithDebInfo -DHAVE_RULES=On -DBUILD_TESTS=On -DBUILD_GUI=Off -DWITH_QCHART=Off -DUSE_MATCHCOMPILER=Verify -DANALYZE_ADDRESS=On -DENABLE_CHECK_INTERNAL=On -DUSE_BOOST=On -DCPPCHK_GLIBCXX_DEBUG=Off -DCMAKE_DISABLE_PRECOMPILE_HEADERS=On -DCMAKE_GLOBAL_AUTOGEN_TARGET=Off -DDISABLE_DMAKE=On -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache diff --git a/.github/workflows/scriptcheck.yml b/.github/workflows/scriptcheck.yml index d7e78896f..627cff4af 100644 --- a/.github/workflows/scriptcheck.yml +++ b/.github/workflows/scriptcheck.yml @@ -37,7 +37,7 @@ jobs: - name: build cppcheck run: | export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH" - make -j$(nproc) -s + make -j$(nproc) -s CXXFLAGS="-w" strip -s ./cppcheck scriptcheck: @@ -183,5 +183,5 @@ jobs: - name: dmake if: matrix.python-latest run: | - make -j$(nproc) run-dmake + make -j$(nproc) CXXFLAGS="-w" run-dmake git diff --exit-code diff --git a/.github/workflows/ubsan.yml b/.github/workflows/ubsan.yml index 335edbd62..cf6333b04 100644 --- a/.github/workflows/ubsan.yml +++ b/.github/workflows/ubsan.yml @@ -58,6 +58,7 @@ jobs: modules: 'qtcharts' cache: true + # TODO: disable warnings - name: CMake run: | cmake -S . -B cmake.output -DCMAKE_BUILD_TYPE=RelWithDebInfo -DHAVE_RULES=On -DBUILD_TESTS=On -DBUILD_GUI=ON -DWITH_QCHART=ON -DUSE_MATCHCOMPILER=Verify -DANALYZE_UNDEFINED=On -DENABLE_CHECK_INTERNAL=On -DUSE_BOOST=On -DCPPCHK_GLIBCXX_DEBUG=Off -DCMAKE_DISABLE_PRECOMPILE_HEADERS=On -DCMAKE_GLOBAL_AUTOGEN_TARGET=On -DDISABLE_DMAKE=On -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache diff --git a/.github/workflows/valgrind.yml b/.github/workflows/valgrind.yml index cf03ff89f..97f875d52 100644 --- a/.github/workflows/valgrind.yml +++ b/.github/workflows/valgrind.yml @@ -38,12 +38,12 @@ jobs: - name: Build cppcheck run: | export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH" - CXXFLAGS="-O1 -g -DHAVE_BOOST" make -j$(nproc) HAVE_RULES=yes MATCHCOMPILER=yes + CXXFLAGS="-O1 -g -w -DHAVE_BOOST" make -j$(nproc) HAVE_RULES=yes MATCHCOMPILER=yes - name: Build test run: | export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH" - CXXFLAGS="-O1 -g -DHAVE_BOOST" make -j$(nproc) testrunner HAVE_RULES=yes MATCHCOMPILER=yes + CXXFLAGS="-O1 -g -w -DHAVE_BOOST" make -j$(nproc) testrunner HAVE_RULES=yes MATCHCOMPILER=yes - name: Run valgrind run: | diff --git a/Makefile b/Makefile index 75a849bbd..f5844225c 100644 --- a/Makefile +++ b/Makefile @@ -137,7 +137,7 @@ ifeq (clang++, $(findstring clang++,$(CXX))) CPPCHK_GLIBCXX_DEBUG= endif ifndef CXXFLAGS - CXXFLAGS=-pedantic -Wall -Wextra -Wcast-qual -Wno-deprecated-declarations -Wfloat-equal -Wmissing-declarations -Wmissing-format-attribute -Wno-long-long -Wpacked -Wredundant-decls -Wundef -Wno-shadow -Wno-missing-field-initializers -Wno-missing-braces -Wno-sign-compare -Wno-multichar $(CPPCHK_GLIBCXX_DEBUG) -g + CXXFLAGS=-pedantic -Wall -Wextra -Wcast-qual -Wfloat-equal -Wmissing-declarations -Wmissing-format-attribute -Wno-long-long -Wpacked -Wredundant-decls -Wundef -Wno-shadow -Wno-missing-field-initializers -Wno-missing-braces -Wno-sign-compare -Wno-multichar -Woverloaded-virtual $(CPPCHK_GLIBCXX_DEBUG) -g endif ifeq (g++, $(findstring g++,$(CXX))) @@ -575,7 +575,7 @@ $(libcppdir)/ctu.o: lib/ctu.cpp externals/tinyxml2/tinyxml2.h lib/addoninfo.h li $(libcppdir)/errorlogger.o: lib/errorlogger.cpp externals/tinyxml2/tinyxml2.h lib/addoninfo.h lib/analyzerinfo.h lib/check.h lib/color.h lib/config.h lib/cppcheck.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/templatesimplifier.h lib/token.h lib/tokenlist.h lib/utils.h lib/vfvalue.h $(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/errorlogger.cpp -$(libcppdir)/errortypes.o: lib/errortypes.cpp lib/config.h lib/errortypes.h +$(libcppdir)/errortypes.o: lib/errortypes.cpp lib/config.h lib/errortypes.h lib/utils.h $(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/errortypes.cpp $(libcppdir)/forwardanalyzer.o: lib/forwardanalyzer.cpp lib/addoninfo.h lib/analyzer.h lib/astutils.h lib/config.h lib/errortypes.h lib/forwardanalyzer.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/smallvector.h lib/sourcelocation.h lib/standards.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/utils.h lib/valueptr.h lib/vfvalue.h diff --git a/cmake/compileroptions.cmake b/cmake/compileroptions.cmake index 4c5ad9af8..38df5d106 100644 --- a/cmake/compileroptions.cmake +++ b/cmake/compileroptions.cmake @@ -43,13 +43,20 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang add_compile_options(-Wno-missing-braces) add_compile_options(-Wno-sign-compare) add_compile_options(-Wno-multichar) + add_compile_options(-Woverloaded-virtual) # when a function declaration hides virtual functions from a base class + + # TODO: evaluate + #add_compile_options(-Wconversion) # danmar: gives fp. for instance: unsigned int sizeof_pointer = sizeof(void *); + #add_compile_options(-Wlogical-op) # doesn't work on older GCC + #add_compile_options(-Wsign-conversion) # too many warnings + #add_compile_options(-Wunreachable-code) # some GCC versions report lots of warnings + #add_compile_options(-Wsign-promo) endif() if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") # use pipes instead of temporary files - greatly reduces I/O usage add_compile_options(-pipe) - add_compile_options(-Woverloaded-virtual) # when a function declaration hides virtual functions from a base class add_compile_options(-Wno-maybe-uninitialized) # there are some false positives add_compile_options(-Wsuggest-attribute=noreturn) add_compile_options(-Wno-shadow) # whenever a local variable or type declaration shadows another one diff --git a/lib/errortypes.cpp b/lib/errortypes.cpp index cd9ca5771..1653df844 100644 --- a/lib/errortypes.cpp +++ b/lib/errortypes.cpp @@ -18,6 +18,8 @@ #include "errortypes.h" +#include "utils.h" + static std::string typeToString(InternalError::Type type) { switch (type) { @@ -34,6 +36,7 @@ static std::string typeToString(InternalError::Type type) case InternalError::Type::INSTANTIATION: return "instantiationError"; } + cppcheck::unreachable(); } InternalError::InternalError(const Token *tok, std::string errorMsg, Type type) : diff --git a/lib/keywords.cpp b/lib/keywords.cpp index 87f1bef35..192b5faac 100644 --- a/lib/keywords.cpp +++ b/lib/keywords.cpp @@ -18,6 +18,8 @@ #include "keywords.h" +#include "utils.h" + #include // see https://en.cppreference.com/w/c/keyword @@ -164,7 +166,7 @@ const std::unordered_set& Keywords::getAll(Standards::cstd_t cStd) /*case Standards::cstd_t::C23: return c23_keywords_all;*/ } - assert(false && "unreachable"); + cppcheck::unreachable(); } // cppcheck-suppress unusedFunction @@ -184,7 +186,7 @@ const std::unordered_set& Keywords::getAll(Standards::cppstd_t cppS case Standards::cppstd_t::CPP23: return cpp23_keywords_all; } - assert(false && "unreachable"); + cppcheck::unreachable(); } // cppcheck-suppress unusedFunction @@ -201,7 +203,7 @@ const std::unordered_set& Keywords::getOnly(Standards::cstd_t cStd) /*case Standards::cstd_t::C23: return c23_keywords_all;*/ } - assert(false && "unreachable"); + cppcheck::unreachable(); } // cppcheck-suppress unusedFunction @@ -222,6 +224,6 @@ const std::unordered_set& Keywords::getOnly(Standards::cppstd_t cpp case Standards::cppstd_t::CPP23: return cpp23_keywords; } - assert(false && "unreachable"); + cppcheck::unreachable(); } diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index c6d2cc50a..100603dd3 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -3044,7 +3044,7 @@ bool Function::returnsConst(const Function* function, bool unknown) bool Function::returnsReference(const Function* function, bool unknown, bool includeRValueRef) { - return checkReturns(function, unknown, false, [includeRValueRef](UNUSED const Token* defStart, const Token* defEnd) { + return checkReturns(function, unknown, false, [includeRValueRef](const Token* /*defStart*/, const Token* defEnd) { return includeRValueRef ? Token::Match(defEnd->previous(), "&|&&") : Token::simpleMatch(defEnd->previous(), "&"); }); } diff --git a/lib/utils.h b/lib/utils.h index 5218ab1c4..2ac0df275 100644 --- a/lib/utils.h +++ b/lib/utils.h @@ -331,4 +331,18 @@ static inline const char* bool_to_string(bool b) return b ? "true" : "false"; } +namespace cppcheck +{ + NORETURN inline void unreachable() + { +#if defined(__GNUC__) + __builtin_unreachable(); +#elif defined(_MSC_VER) + __assume(false); +#else +#error "no unreachable implementation" +#endif + } +} + #endif diff --git a/tools/dmake.cpp b/tools/dmake.cpp index 0072f211f..c9b47989e 100644 --- a/tools/dmake.cpp +++ b/tools/dmake.cpp @@ -589,36 +589,26 @@ int main(int argc, char **argv) // Makefile settings.. if (release) { - makeConditionalVariable(fout, "CXXFLAGS", "-std=c++0x -O2 -DNDEBUG -Wall -Wno-sign-compare"); + makeConditionalVariable(fout, "CXXFLAGS", "-std=c++0x -O2 -DNDEBUG -Wall -Wno-sign-compare -Wno-multichar"); } else { - // TODO: add more compiler warnings. - // -Wlogical-op : doesn't work on older GCC - // -Wsign-conversion : too many warnings - // -Wunreachable-code : some GCC versions report lots of warnings makeConditionalVariable(fout, "CXXFLAGS", "-pedantic " "-Wall " "-Wextra " "-Wcast-qual " -// "-Wconversion " // danmar: gives fp. for instance: unsigned int sizeof_pointer = sizeof(void *); - "-Wno-deprecated-declarations " "-Wfloat-equal " -// "-Wlogical-op " "-Wmissing-declarations " "-Wmissing-format-attribute " "-Wno-long-long " -// "-Woverloaded-virtual " // danmar: we get fp when overloading analyseWholeProgram() "-Wpacked " "-Wredundant-decls " "-Wundef " "-Wno-shadow " -// "-Wsign-conversion " -// "-Wsign-promo " "-Wno-missing-field-initializers " "-Wno-missing-braces " -// "-Wunreachable-code " - "-Wno-sign-compare " // danmar: I don't like this warning, it's very rarely a bug + "-Wno-sign-compare " "-Wno-multichar " + "-Woverloaded-virtual " "$(CPPCHK_GLIBCXX_DEBUG) " "-g"); }