diff --git a/cmake/compileroptions.cmake b/cmake/compileroptions.cmake index 55656446b..b3410a7bd 100644 --- a/cmake/compileroptions.cmake +++ b/cmake/compileroptions.cmake @@ -7,6 +7,13 @@ function(add_compile_options_safe FLAG) endif() endfunction() +function(target_compile_options_safe TARGET FLAG) + check_cxx_compiler_flag(${FLAG} _has_flag) + if (_has_flag) + target_compile_options(${TARGET} PRIVATE ${FLAG}) + endif() +endfunction() + if (CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") if(CMAKE_BUILD_TYPE MATCHES "Release") # "Release" uses -O3 by default @@ -41,6 +48,7 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "GNU") 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) elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang") add_compile_options(-Wno-four-char-constants) @@ -52,6 +60,7 @@ elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang") add_compile_options_safe(-Wdocumentation-pedantic) add_compile_options_safe(-Wno-documentation-unknown-command) add_compile_options_safe(-Wimplicit-fallthrough) + add_compile_options_safe(-Wmissing-noreturn) if(ENABLE_COVERAGE OR ENABLE_COVERAGE_XML) message(FATAL_ERROR "Do not use clang for generate code coverage. Use gcc.") diff --git a/externals/tinyxml2/CMakeLists.txt b/externals/tinyxml2/CMakeLists.txt index 12b699b83..e599d40fb 100644 --- a/externals/tinyxml2/CMakeLists.txt +++ b/externals/tinyxml2/CMakeLists.txt @@ -3,13 +3,12 @@ file(GLOB srcs "*.cpp") add_library(tinyxml2_objs OBJECT ${srcs} ${hdrs}) -# TODO: need to be fixed upstream +# TODO: needs to be fixed upstream if (CMAKE_CXX_COMPILER_ID MATCHES "GNU") target_compile_options(tinyxml2_objs PRIVATE -Wno-suggest-attribute=format) endif() if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") - if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS "8.0.0") - target_compile_options(tinyxml2_objs PRIVATE -Wno-extra-semi-stmt) - endif() + target_compile_options_safe(tinyxml2_objs -Wno-extra-semi-stmt) + target_compile_options_safe(tinyxml2_objs -Wno-implicit-fallthrough) endif() diff --git a/lib/templatesimplifier.h b/lib/templatesimplifier.h index 04f528b86..fe1343ee5 100644 --- a/lib/templatesimplifier.h +++ b/lib/templatesimplifier.h @@ -451,7 +451,7 @@ private: static bool removeTemplate(Token *tok); /** Syntax error */ - static void syntaxError(const Token *tok); + NORETURN static void syntaxError(const Token *tok); static bool matchSpecialization( const Token *templateDeclarationNameToken, diff --git a/lib/tokenize.h b/lib/tokenize.h index 27754efbf..a11e113c7 100644 --- a/lib/tokenize.h +++ b/lib/tokenize.h @@ -617,7 +617,7 @@ private: * Send error message to error logger about internal bug. * @param tok the token that this bug concerns. */ - void cppcheckError(const Token *tok) const; + NORETURN void cppcheckError(const Token *tok) const; /** * Setup links for tokens so that one can call Token::link().