From 423841e965ee72a474f176b16b79ce421549d5b9 Mon Sep 17 00:00:00 2001 From: ericLemanissier Date: Thu, 3 May 2018 08:08:41 +0200 Subject: [PATCH 1/4] fix requirement on not_null template it should be comparable to nullptr, it does not have to be assignable --- include/gsl/pointers | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/gsl/pointers b/include/gsl/pointers index ad15ce3..891dfc5 100644 --- a/include/gsl/pointers +++ b/include/gsl/pointers @@ -69,7 +69,7 @@ template class not_null { public: - static_assert(std::is_assignable::value, "T cannot be assigned nullptr."); + static_assert(std::is_convertible() != nullptr), bool>::value, "T cannot be compared to nullptr."); template ::value>> constexpr explicit not_null(U&& u) : ptr_(std::forward(u)) From f5cf01083baf7e8dc8318db3648bc6098dc32d67 Mon Sep 17 00:00:00 2001 From: Nicholas Guriev Date: Sat, 18 Apr 2020 13:30:17 +0300 Subject: [PATCH 2/4] Search for GoogleTest via pkg-config first --- tests/CMakeLists.txt | 59 ++++++++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 27 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 0219319..53d475c 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,37 +1,42 @@ cmake_minimum_required(VERSION 3.0.2) project(GSLTests CXX) +include(FindPkgConfig) # will make visual studio generated project group files set_property(GLOBAL PROPERTY USE_FOLDERS ON) -configure_file(CMakeLists.txt.in googletest-download/CMakeLists.txt) -execute_process( - COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" . - RESULT_VARIABLE result - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download -) -if(result) - message(FATAL_ERROR "CMake step for googletest failed: ${result}") +pkg_search_module(GTestMain gtest_main) +if (NOT GTestMain_FOUND) + configure_file(CMakeLists.txt.in googletest-download/CMakeLists.txt) + execute_process( + COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" . + RESULT_VARIABLE result + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download + ) + if(result) + message(FATAL_ERROR "CMake step for googletest failed: ${result}") + endif() + + execute_process( + COMMAND ${CMAKE_COMMAND} --build . + RESULT_VARIABLE result + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download + ) + if(result) + message(FATAL_ERROR "CMake step for googletest failed: ${result}") + endif() + + set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) + set(GTestMain_LIBRARIES gtest_main) + + add_subdirectory( + ${CMAKE_CURRENT_BINARY_DIR}/googletest-src + ${CMAKE_CURRENT_BINARY_DIR}/googletest-build + EXCLUDE_FROM_ALL + ) endif() -execute_process( - COMMAND ${CMAKE_COMMAND} --build . - RESULT_VARIABLE result - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download -) -if(result) - message(FATAL_ERROR "CMake step for googletest failed: ${result}") -endif() - -set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) - -add_subdirectory( - ${CMAKE_CURRENT_BINARY_DIR}/googletest-src - ${CMAKE_CURRENT_BINARY_DIR}/googletest-build - EXCLUDE_FROM_ALL -) - if (MSVC AND (GSL_CXX_STANDARD EQUAL 17)) set(GSL_CPLUSPLUS_OPT -Zc:__cplusplus -permissive-) endif() @@ -149,7 +154,7 @@ function(add_gsl_test name) target_link_libraries(${name} GSL gsl_tests_config - gtest_main + ${GTestMain_LIBRARIES} ) add_test( ${name} @@ -254,7 +259,7 @@ function(add_gsl_test_noexcept name) target_link_libraries(${name} GSL gsl_tests_config_noexcept - gtest_main + ${GTestMain_LIBRARIES} ) add_test( ${name} From 01eaf5bef131ff51274ca57f5ade2d10851aa00b Mon Sep 17 00:00:00 2001 From: Jordan Maples Date: Mon, 10 Aug 2020 16:45:47 -0700 Subject: [PATCH 3/4] macro version --- include/gsl/gsl_util | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/include/gsl/gsl_util b/include/gsl/gsl_util index 89fb2ee..2e79605 100644 --- a/include/gsl/gsl_util +++ b/include/gsl/gsl_util @@ -32,6 +32,12 @@ #endif // _MSC_VER +#if __has_cpp_attribute(nodiscard) >= 201603L +#define GSL_NODISCARD [[nodiscard]] +#else +#define GSL_NODISCARD +#endif + namespace gsl { // @@ -67,13 +73,13 @@ private: // finally() - convenience function to generate a final_action template -final_action finally(const F& f) noexcept +GSL_NODISCARD final_action finally(const F& f) noexcept { return final_action(f); } template -final_action finally(F&& f) noexcept +GSL_NODISCARD final_action finally(F&& f) noexcept { return final_action(std::forward(f)); } @@ -98,16 +104,16 @@ constexpr T narrow(U u) noexcept(false) { constexpr const bool is_different_signedness = (std::is_signed::value != std::is_signed::value); - + const T t = narrow_cast(u); - + if (static_cast(t) != u || (is_different_signedness && ((t < T{}) != (u < U{})))) { throw narrowing_error{}; } - + return t; } From afe824490ebae9188be0e96ecff3dbc73b37285c Mon Sep 17 00:00:00 2001 From: Jordan Maples Date: Wed, 12 Aug 2020 12:13:19 -0700 Subject: [PATCH 4/4] change macro test to use __cplusplus instead of __has_cpp_attribute --- include/gsl/gsl_util | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/gsl/gsl_util b/include/gsl/gsl_util index 2e79605..974655b 100644 --- a/include/gsl/gsl_util +++ b/include/gsl/gsl_util @@ -32,11 +32,11 @@ #endif // _MSC_VER -#if __has_cpp_attribute(nodiscard) >= 201603L +#if defined(__cplusplus) && (__cplusplus >= 201703L) #define GSL_NODISCARD [[nodiscard]] #else #define GSL_NODISCARD -#endif +#endif // defined(__cplusplus) && (__cplusplus >= 201703L) namespace gsl {