diff --git a/CMakeLists.txt b/CMakeLists.txt index 49b665d..1121345 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,9 +9,11 @@ option(toml11_TEST_WITH_UBSAN "use LLVM undefined behavior sanitizer" OFF) include(CheckCXXCompilerFlag) if("${CMAKE_VERSION}" VERSION_GREATER 3.1) - set(CMAKE_CXX_STANDARD 11 CACHE STRING "The C++ standard whose features are requested to build all targets.") - set(CMAKE_CXX_STANDARD_REQUIRED ON CACHE BOOL "Boolean describing whether the value of CXX_STANDARD is a requirement.") set(CMAKE_CXX_EXTENSIONS OFF CACHE BOOL "Boolean specifying whether compiler specific extensions are requested.") + if(NOT DEFINED CMAKE_CXX_STANDARD) + set(CMAKE_CXX_STANDARD 11 CACHE STRING "The C++ standard whose features are requested to build all targets.") + endif() + set(CMAKE_CXX_STANDARD_REQUIRED ON CACHE BOOL "Boolean describing whether the value of CXX_STANDARD is a requirement.") else() # Manually check for C++11 compiler flag. CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 49ebcb4..99d73b9 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -149,6 +149,10 @@ if(MSVC) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4820") # pragma warning(pop): likely mismatch, popping warning state pushed in different file set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd5031") + # pragma warning(pop): spectre warnings in tests + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd5045") + # pragma warning(pop): spectre warnings in tests + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4265") endif() find_package(Boost COMPONENTS unit_test_framework REQUIRED) @@ -185,6 +189,7 @@ option(TOML11_REQUIRE_FILESYSTEM_LIBRARY "need to link -lstdc++fs or -lc++fs" OF foreach(TEST_NAME ${TEST_NAMES}) add_executable(${TEST_NAME} ${TEST_NAME}.cpp) target_link_libraries(${TEST_NAME} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY} toml11::toml11) + target_include_directories(${TEST_NAME} SYSTEM PRIVATE ${Boost_INCLUDE_DIRS}) # to compile tests with ... if(TOML11_REQUIRE_FILESYSTEM_LIBRARY) diff --git a/toml/get.hpp b/toml/get.hpp index 6669e34..d7fdf55 100644 --- a/toml/get.hpp +++ b/toml/get.hpp @@ -140,7 +140,7 @@ get(basic_value&& v) // ============================================================================ // std::string_view -#if __cplusplus >= 201703L +#if defined(TOML11_USING_STRING_VIEW) && TOML11_USING_STRING_VIEW>0 template class M, template class V> inline detail::enable_if_t::value, std::string_view> diff --git a/toml/string.hpp b/toml/string.hpp index a6ed080..5136d8c 100644 --- a/toml/string.hpp +++ b/toml/string.hpp @@ -9,6 +9,7 @@ #if __cplusplus >= 201703L #if __has_include() +#define TOML11_USING_STRING_VIEW 1 #include #endif #endif @@ -53,7 +54,7 @@ struct string string& operator+=(const std::string& rhs) {str += rhs; return *this;} string& operator+=(const string& rhs) {str += rhs.str; return *this;} -#if __cplusplus >= 201703L +#if defined(TOML11_USING_STRING_VIEW) && TOML11_USING_STRING_VIEW>0 explicit string(std::string_view s): kind(string_t::basic), str(s){} string(std::string_view s, string_t k): kind(k), str(s){} diff --git a/toml/traits.hpp b/toml/traits.hpp index 0064e37..5495c93 100644 --- a/toml/traits.hpp +++ b/toml/traits.hpp @@ -209,7 +209,9 @@ struct is_container : conjunction< negation>, // not a map negation>, // not a std::string #if __cplusplus >= 201703L +#if __has_include() negation>, // not a std::string_view +#endif // has_include() #endif has_iterator, // has T::iterator has_value_type // has T::value_type @@ -280,7 +282,7 @@ using enable_if_t = typename std::enable_if::type; // --------------------------------------------------------------------------- // return_type_of_t -#if __cplusplus >= 201703L +#if __cplusplus >= 201703L && defined(__cpp_lib_is_invocable) && __cpp_lib_is_invocable>=201703 template using return_type_of_t = std::invoke_result_t; diff --git a/toml/value.hpp b/toml/value.hpp index ecae2c3..1b43db8 100644 --- a/toml/value.hpp +++ b/toml/value.hpp @@ -624,7 +624,7 @@ class basic_value assigner(this->string_, toml::string(std::string(s), kind)); } -#if __cplusplus >= 201703L +#if defined(TOML11_USING_STRING_VIEW) && TOML11_USING_STRING_VIEW>0 basic_value(std::string_view s) : type_(value_t::string), region_info_(std::make_shared(region_base{}))