diff --git a/include/gsl/gsl_util b/include/gsl/gsl_util index d771414..585b3f9 100644 --- a/include/gsl/gsl_util +++ b/include/gsl/gsl_util @@ -32,6 +32,12 @@ #endif // _MSC_VER +#if defined(__cplusplus) && (__cplusplus >= 201703L) +#define GSL_NODISCARD [[nodiscard]] +#else +#define GSL_NODISCARD +#endif // defined(__cplusplus) && (__cplusplus >= 201703L) + 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)); } diff --git a/include/gsl/pointers b/include/gsl/pointers index 0ec0fc3..bb80b92 100644 --- a/include/gsl/pointers +++ b/include/gsl/pointers @@ -63,7 +63,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 not_null(U&& u) : ptr_(std::forward(u)) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 2bd1bbe..a4bd7e6 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}