From e6107a781c35f5e0a366e526631ea8cef8f246c5 Mon Sep 17 00:00:00 2001 From: Dominic Hamon Date: Sat, 11 Oct 2014 15:52:50 -0700 Subject: [PATCH] Fix #50 by using nullptr and adding stricter warning. --- CMakeLists.txt | 1 + cmake/CXXFeatureCheck.cmake | 11 ++++++++--- cmake/gnu_posix_regex.cpp | 2 +- cmake/posix_regex.cpp | 2 +- cmake/std_regex.cpp | 4 +++- 5 files changed, 14 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 340055ce..ec98408a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,6 +40,7 @@ add_cxx_compiler_flag(-Wall) add_cxx_compiler_flag(-Wshadow) add_cxx_compiler_flag(-Werror) add_cxx_compiler_flag(-pedantic-errors) +add_cxx_compiler_flag(-Wzero-as-null-pointer-constant) # Release flags add_cxx_compiler_flag(-fno-strict-aliasing RELEASE) diff --git a/cmake/CXXFeatureCheck.cmake b/cmake/CXXFeatureCheck.cmake index 7adebcac..23ee8ac6 100644 --- a/cmake/CXXFeatureCheck.cmake +++ b/cmake/CXXFeatureCheck.cmake @@ -22,13 +22,18 @@ function(cxx_feature_check FILE) string(TOUPPER ${FILE} VAR) string(TOUPPER "HAVE_${VAR}" FEATURE) message("-- Performing Test ${FEATURE}") - try_run(RUN_${FEATURE} COMPILE_${FEATURE} ${CMAKE_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/${FILE}.cpp) + try_run(RUN_${FEATURE} COMPILE_${FEATURE} + ${CMAKE_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/${FILE}.cpp) if(RUN_${FEATURE} EQUAL 0) - message("-- Performing Test ${FEATURE} -- Success") + message("-- Performing Test ${FEATURE} -- success") set(HAVE_${VAR} 1 PARENT_SCOPE) add_definitions(-DHAVE_${VAR}) else() - message("-- Performing Test ${FEATURE} -- Failed") + if(NOT COMPILE_${FEATURE}) + message("-- Performing Test ${FEATURE} -- failed to compile") + else() + message("-- Performing Test ${FEATURE} -- compiled but failed to run") + endif() endif() endfunction() diff --git a/cmake/gnu_posix_regex.cpp b/cmake/gnu_posix_regex.cpp index 480ab25c..b5b91cda 100644 --- a/cmake/gnu_posix_regex.cpp +++ b/cmake/gnu_posix_regex.cpp @@ -7,6 +7,6 @@ int main() { if (ec != 0) { return ec; } - return regexec(&re, str.c_str(), 0, NULL, 0) ? -1 : 0; + return regexec(&re, str.c_str(), 0, nullptr, 0) ? -1 : 0; } diff --git a/cmake/posix_regex.cpp b/cmake/posix_regex.cpp index 1f7fe07e..a31af804 100644 --- a/cmake/posix_regex.cpp +++ b/cmake/posix_regex.cpp @@ -7,6 +7,6 @@ int main() { if (ec != 0) { return ec; } - return regexec(&re, str.c_str(), 0, NULL, 0) ? -1 : 0; + return regexec(&re, str.c_str(), 0, nullptr, 0) ? -1 : 0; } diff --git a/cmake/std_regex.cpp b/cmake/std_regex.cpp index 4f227d44..2059a9f0 100644 --- a/cmake/std_regex.cpp +++ b/cmake/std_regex.cpp @@ -2,7 +2,9 @@ #include int main() { const std::string str = "test0159"; - const std::regex re("^[a-z]+[0-9]+$", std::regex_constants::extended | std::regex_constants::nosubs); + const std::regex re( + "^[a-z]+[0-9]+$", + std::regex_constants::extended | std::regex_constants::nosubs); return std::regex_search(str, re) ? 0 : -1; }