From cc9cce28aea26edb27a72d1a3aa72bfa2ddb7806 Mon Sep 17 00:00:00 2001 From: Anton Bachin Date: Fri, 26 Feb 2016 23:24:08 -0600 Subject: [PATCH] Enabled more warnings during testing. To avoid problems with warnings in CxxTest, the extra warnings are enabled during one test (linking) that does not use CxxTest. Resolves #16. --- enum.h | 8 ++++---- test/CMakeLists.txt | 36 +++++++++++++++++++++++++++++++++--- test/linking/helper.h | 6 +++--- test/linking/shared.h | 6 +++--- 4 files changed, 43 insertions(+), 13 deletions(-) diff --git a/enum.h b/enum.h index f56b32f..e1dc713 100644 --- a/enum.h +++ b/enum.h @@ -264,7 +264,7 @@ namespace better_enums { template BETTER_ENUMS_CONSTEXPR_ inline T _default() { - return (typename T::_enumerated)0; + return static_cast(0); } template <> @@ -302,7 +302,7 @@ template BETTER_ENUMS_CONSTEXPR_ static optional _map_index(const Element *array, optional index) { - return index ? (CastTo)array[*index] : optional(); + return index ? static_cast(array[*index]) : optional(); } #ifdef BETTER_ENUMS_VC2008_WORKAROUNDS @@ -425,7 +425,7 @@ _select(const char *from, std::size_t from_length, std::size_t index) BETTER_ENUMS_CONSTEXPR_ inline char _to_lower_ascii(char c) { - return c >= 0x41 && c <= 0x5A ? (char)(c + 0x20) : c; + return c >= 0x41 && c <= 0x5A ? static_cast(c + 0x20) : c; } BETTER_ENUMS_CONSTEXPR_ inline bool _names_match(const char *stringizedName, @@ -1000,7 +1000,7 @@ BETTER_ENUMS_CONSTEXPR_ inline bool operator >=(const Enum &a, const Enum &b) \ #ifndef BETTER_ENUMS_DEFAULT_CONSTRUCTOR # define BETTER_ENUMS_DEFAULT_CONSTRUCTOR(Enum) \ private: \ - Enum() { } + Enum() : _value(0) { } #endif diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 2e77663..789ea13 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -153,13 +153,27 @@ include_directories(../extra) if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES Clang) include(CheckCXXCompilerFlag) + macro(add_cxx_flag_if_supported FLAG) + check_cxx_compiler_flag("${FLAG}" HAVE_FLAG_${FLAG}) + + if(HAVE_FLAG_${FLAG}) + add_definitions(${FLAG}) + endif() + endmacro() + + macro(add_cxx_flag_to_target_if_supported TARGET FLAG) string(REPLACE "=" "_equals_" ESCAPED ${FLAG}) string(REPLACE "+" "_plus_" ESCAPED ${ESCAPED}) - check_cxx_compiler_flag("${FLAG}" HAVE_FLAG_${ESCAPED}) + check_cxx_compiler_flag("${FLAG}" HAVE_FLAG_${FLAG}) - if(HAVE_FLAG_${ESCAPED}) - add_definitions(${FLAG}) + if(HAVE_FLAG_${FLAG}) + get_target_property(FLAGS ${TARGET} COMPILE_FLAGS) + if(${FLAGS} STREQUAL "FLAGS-NOTFOUND") + set(FLAGS "") + endif() + set_target_properties( + ${TARGET} PROPERTIES COMPILE_FLAGS "${FLAGS} ${FLAG}") endif() endmacro() @@ -169,5 +183,21 @@ if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES Clang) add_cxx_flag_if_supported("-Wno-variadic-macros") add_cxx_flag_if_supported("-Wno-unused-const-variable") + add_cxx_flag_to_target_if_supported(linking "-Weverything") + add_cxx_flag_to_target_if_supported(linking "-Wno-c++98-compat-pedantic") + add_cxx_flag_to_target_if_supported(linking "-Wno-padded") + add_cxx_flag_to_target_if_supported(linking "-Wno-global-constructors") + add_cxx_flag_to_target_if_supported(linking "-Wno-old-style-cast") + add_cxx_flag_to_target_if_supported(linking "-Wno-missing-prototypes") + add_cxx_flag_to_target_if_supported(linking "-Wshadow") + add_cxx_flag_to_target_if_supported(linking "-Weffc++") + add_cxx_flag_to_target_if_supported(linking "-Wstrict-aliasing") + add_cxx_flag_to_target_if_supported(linking "-Wformat") + add_cxx_flag_to_target_if_supported(linking "-Wmissing-include-dirs") + add_cxx_flag_to_target_if_supported(linking "-Wsync-nand") + add_cxx_flag_to_target_if_supported(linking "-Wconditionally-supported") + add_cxx_flag_to_target_if_supported(linking "-Wconversion") + add_cxx_flag_to_target_if_supported(linking "-Wuseless-cast") + add_definitions("-Werror") endif() diff --git a/test/linking/helper.h b/test/linking/helper.h index 65f8fe1..d192432 100644 --- a/test/linking/helper.h +++ b/test/linking/helper.h @@ -1,8 +1,8 @@ -#ifndef _HELPER_H_ -#define _HELPER_H_ +#ifndef HELPER_H +#define HELPER_H #include "shared.h" void print(Channel channel); -#endif // #ifndef _HELPER_H_ +#endif // #ifndef HELPER_H diff --git a/test/linking/shared.h b/test/linking/shared.h index 0d3c642..33564b0 100644 --- a/test/linking/shared.h +++ b/test/linking/shared.h @@ -1,8 +1,8 @@ -#ifndef _SHARED_H_ -#define _SHARED_H_ +#ifndef SHARED_H +#define SHARED_H #include BETTER_ENUM(Channel, int, Red, Green, Blue) -#endif // #ifndef _SHARED_H_ +#endif // #ifndef SHARED_H