From 7c159427516124ba8c01262b15f492b6b6789dce Mon Sep 17 00:00:00 2001 From: Patrick Johnmeyer Date: Sat, 27 Aug 2016 08:26:05 -0500 Subject: [PATCH 1/6] Up warning level to /W4 /WX for MSVC-like compilers Also adds a CMake option, UTPP_AMPLIFY_WARNINGS, that can be turned OFF to disable the new behavior. --- CMakeLists.txt | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index e99ee13..89e61f5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,6 +7,9 @@ option(UTPP_USE_PLUS_SIGN option(UTPP_INCLUDE_TESTS_IN_BUILD "Set this to OFF if you do not wish to automatically build or run unit tests as part of the default cmake --build" ON) +option(UTPP_AMPLIFY_WARNINGS + "Set this to OFF if you wish to use CMake default warning levels; should generally only use to work around support issues for your specific compiler" + ON) if(MSVC14 OR MSVC12) # has the support we need @@ -23,6 +26,15 @@ else() endif() endif() +# up warning level for project +if (${UTPP_AMPLIFY_WARNINGS}) + # instead of getting compiler specific, we're going to try making an assumption that an existing /W# means + # we are dealing with an MSVC or MSVC-like compiler (e.g. Intel on Windows) + if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]") + string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /WX") + endif() +endif() + # get the main sources file(GLOB headers_ RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} UnitTest++/*.h) file(GLOB sources_ RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} UnitTest++/*.cpp) From 7e4fff3bb420820b67562ccd1d706e17d795cf8d Mon Sep 17 00:00:00 2001 From: Patrick Johnmeyer Date: Sat, 27 Aug 2016 08:27:15 -0500 Subject: [PATCH 2/6] Fix "assignment operator could not be generated" warning This shows up with /W4 on MSVC. Fixes #107. --- UnitTest++/RequiredCheckTestReporter.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/UnitTest++/RequiredCheckTestReporter.h b/UnitTest++/RequiredCheckTestReporter.h index 117ae01..99d9cdd 100644 --- a/UnitTest++/RequiredCheckTestReporter.h +++ b/UnitTest++/RequiredCheckTestReporter.h @@ -19,6 +19,9 @@ namespace UnitTest { bool Next(); private: + RequiredCheckTestReporter(RequiredCheckTestReporter const&); + RequiredCheckTestReporter& operator =(RequiredCheckTestReporter const&); + TestResults& m_results; TestReporter* m_originalTestReporter; ThrowingTestReporter m_throwingReporter; From f0044e919dcae4a171d2db45f2aea92850df2b0c Mon Sep 17 00:00:00 2001 From: Patrick Johnmeyer Date: Sat, 27 Aug 2016 09:54:32 -0500 Subject: [PATCH 3/6] Up warning level to -Wall/extra/error for non-MSVC UTPP_AMPLIFY_WARNINGS can be turned OFF to disable the new behavior. --- CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 89e61f5..76c8665 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,6 +32,8 @@ if (${UTPP_AMPLIFY_WARNINGS}) # we are dealing with an MSVC or MSVC-like compiler (e.g. Intel on Windows) if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]") string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /WX") + else() + string(CONCAT CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" " -Wall -Wextra -Werror -Wno-ignored-qualifiers") endif() endif() From 2e2475fa5401c4ef123b3ca26f7a8e60ee5eb425 Mon Sep 17 00:00:00 2001 From: Patrick Johnmeyer Date: Sat, 27 Aug 2016 09:55:37 -0500 Subject: [PATCH 4/6] Fix unused variable warnings --- UnitTest++/Posix/SignalTranslator.cpp | 4 ++-- UnitTest++/Posix/SignalTranslator.h | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/UnitTest++/Posix/SignalTranslator.cpp b/UnitTest++/Posix/SignalTranslator.cpp index 4039896..69cc194 100644 --- a/UnitTest++/Posix/SignalTranslator.cpp +++ b/UnitTest++/Posix/SignalTranslator.cpp @@ -28,12 +28,12 @@ namespace UnitTest { sigaction( SIGFPE, &action, &m_old_SIGFPE_action ); sigaction( SIGTRAP, &action, &m_old_SIGTRAP_action ); sigaction( SIGBUS, &action, &m_old_SIGBUS_action ); - sigaction( SIGILL, &action, &m_old_SIGBUS_action ); + sigaction( SIGILL, &action, &m_old_SIGILL_action ); } SignalTranslator::~SignalTranslator() { - sigaction( SIGILL, &m_old_SIGBUS_action, 0 ); + sigaction( SIGILL, &m_old_SIGILL_action, 0 ); sigaction( SIGBUS, &m_old_SIGBUS_action, 0 ); sigaction( SIGTRAP, &m_old_SIGTRAP_action, 0 ); sigaction( SIGFPE, &m_old_SIGFPE_action, 0 ); diff --git a/UnitTest++/Posix/SignalTranslator.h b/UnitTest++/Posix/SignalTranslator.h index efb3618..66d388d 100644 --- a/UnitTest++/Posix/SignalTranslator.h +++ b/UnitTest++/Posix/SignalTranslator.h @@ -22,8 +22,7 @@ namespace UnitTest { struct sigaction m_old_SIGTRAP_action; struct sigaction m_old_SIGSEGV_action; struct sigaction m_old_SIGBUS_action; - struct sigaction m_old_SIGABRT_action; - struct sigaction m_old_SIGALRM_action; + struct sigaction m_old_SIGILL_action; }; #if !defined (__GNUC__) From e161d44077646e63e8956ce0c70002cecda3d2be Mon Sep 17 00:00:00 2001 From: Patrick Johnmeyer Date: Sat, 27 Aug 2016 10:04:54 -0500 Subject: [PATCH 5/6] Use CMake SET instead of string CONCAT string(CONCAT...) was not available in older versions of CMake targeted by this project. --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 76c8665..32023b9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,7 +33,7 @@ if (${UTPP_AMPLIFY_WARNINGS}) if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]") string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /WX") else() - string(CONCAT CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" " -Wall -Wextra -Werror -Wno-ignored-qualifiers") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror -Wno-ignored-qualifiers") endif() endif() From 7d7ba0aba44d5a9d76442e5e8286686e01eaf222 Mon Sep 17 00:00:00 2001 From: Patrick Johnmeyer Date: Sat, 27 Aug 2016 20:41:41 -0500 Subject: [PATCH 6/6] Re-enable ignored-qualifiers warning and fix --- CMakeLists.txt | 2 +- tests/TestMemoryOutStream.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 32023b9..a7411bc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,7 +33,7 @@ if (${UTPP_AMPLIFY_WARNINGS}) if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]") string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /WX") else() - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror -Wno-ignored-qualifiers") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror") endif() endif() diff --git a/tests/TestMemoryOutStream.cpp b/tests/TestMemoryOutStream.cpp index 7c1ffbc..854277e 100644 --- a/tests/TestMemoryOutStream.cpp +++ b/tests/TestMemoryOutStream.cpp @@ -11,7 +11,7 @@ using namespace std; namespace { - const char* const maxSignedIntegralStr(size_t nBytes) + const char* maxSignedIntegralStr(size_t nBytes) { switch(nBytes) { @@ -28,7 +28,7 @@ namespace { } } - const char* const minSignedIntegralStr(size_t nBytes) + const char* minSignedIntegralStr(size_t nBytes) { switch(nBytes) { @@ -45,7 +45,7 @@ namespace { } } - const char* const maxUnsignedIntegralStr(size_t nBytes) + const char* maxUnsignedIntegralStr(size_t nBytes) { switch(nBytes) {