diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 6aaa779..e6a1f5b 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -48,6 +48,8 @@ CHECK_CXX_COMPILER_FLAG("-Wduplicated-branches" COMPILER_SUPPORTS_WDUPLICATED_BR CHECK_CXX_COMPILER_FLAG("-Wlogical-op" COMPILER_SUPPORTS_WLOGICAL_OP) CHECK_CXX_COMPILER_FLAG("-Wuseless-cast" COMPILER_SUPPORTS_WUSELESS_CAST) CHECK_CXX_COMPILER_FLAG("-Wdouble-promotion" COMPILER_SUPPORTS_WDOUBLE_PROMOTION) +CHECK_CXX_COMPILER_FLAG("-Wrange-loop-analysis" COMPILER_SUPPORTS_WRANGE_LOOP_ANALYSIS) +CHECK_CXX_COMPILER_FLAG("-Wundef" COMPILER_SUPPORTS_WUNDEF) if(COMPILER_SUPPORTS_WALL) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") @@ -82,6 +84,12 @@ endif() if(COMPILER_SUPPORTS_WDOUBLE_PROMOTION) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wdouble-promotion") endif() +if(COMPILER_SUPPORTS_WRANGE_LOOP_ANALYSIS) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wrange-loop-analysis") +endif() +if(COMPILER_SUPPORTS_WUNDEF) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wundef") +endif() option(TOML11_USE_UNRELEASED_TOML_FEATURES "use features in toml-lang/toml master while testing" OFF) diff --git a/toml/datetime.hpp b/toml/datetime.hpp index 0d56e76..3fdec44 100644 --- a/toml/datetime.hpp +++ b/toml/datetime.hpp @@ -20,7 +20,7 @@ namespace toml namespace detail { // TODO: find more sophisticated way to handle this -#if _POSIX_C_SOURCE >= 1 || defined(_XOPEN_SOURCE) || defined(_BSD_SOURCE) || defined(_SVID_SOURCE) || defined(_POSIX_SOURCE) +#if (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 1) || defined(_XOPEN_SOURCE) || defined(_BSD_SOURCE) || defined(_SVID_SOURCE) || defined(_POSIX_SOURCE) inline std::tm localtime_s(const std::time_t* src) { std::tm dst; @@ -35,7 +35,7 @@ inline std::tm gmtime_s(const std::time_t* src) if (!result) { throw std::runtime_error("gmtime_r failed."); } return dst; } -#elif _MSC_VER +#elif defined(_MSC_VER) inline std::tm localtime_s(const std::time_t* src) { std::tm dst; diff --git a/toml/region.hpp b/toml/region.hpp index bf9ba12..77ba943 100644 --- a/toml/region.hpp +++ b/toml/region.hpp @@ -511,7 +511,7 @@ inline std::string format_underline(const std::string& message, retval << '\n'; retval << make_string(static_cast(line_num_width + 1), ' '); retval << color::bold << color::blue << " | " << color::reset; - for(const auto help : helps) + for(const auto& help : helps) { retval << color::bold << "\nHint: " << color::reset; retval << help; diff --git a/toml/serializer.hpp b/toml/serializer.hpp index 6503f08..1a65d2b 100644 --- a/toml/serializer.hpp +++ b/toml/serializer.hpp @@ -619,7 +619,7 @@ struct serializer // print non-table stuff first. because after printing [foo.bar], the // remaining non-table values will be assigned into [foo.bar], not [foo] - for(const auto kv : v) + for(const auto& kv : v) { if(kv.second.is_table() || is_array_of_tables(kv.second)) {