diff --git a/src/gettext_boost.cpp b/src/gettext_boost.cpp index f99d9793b25f..cae252d986e1 100644 --- a/src/gettext_boost.cpp +++ b/src/gettext_boost.cpp @@ -437,10 +437,10 @@ std::string strftime(const std::string& format, const std::tm* time) std::basic_ostringstream dummy; dummy.imbue(get_manager().get_locale()); // See utils/io.hpp for explanation of this check -#if (defined(__clang__) && !__has_include()) || (defined(__GNUC__) && __GNUC__ < 5) - dummy << bl::as::ftime(format) << mktime(const_cast(time)); -#else +#if HAVE_PUT_TIME dummy << std::put_time(time, format.c_str()); +#else + dummy << bl::as::ftime(format) << mktime(const_cast(time)); #endif return dummy.str(); diff --git a/src/global.hpp b/src/global.hpp index d48d353e829c..26926c58418a 100644 --- a/src/global.hpp +++ b/src/global.hpp @@ -62,6 +62,7 @@ // Some C++11 features are not available on all supported platforms #if defined(_MSC_VER) +#define HAVE_PUT_TIME 1 // MSVC supports these starting in MSVC 2015 #if _MSC_VER >= 1900 #define HAVE_REF_QUALIFIERS 1 @@ -77,6 +78,10 @@ #endif #if defined(__clang__) +#include // To ensure standard library version macros are defined +// If it's libc++, no problem. Otherwise, attempt to detect libstdc++ version (needs GCC 5.1 or higher) +// by testing for the existence of a header added in that version. +#define HAVE_PUT_TIME (defined(_LIBCPP_VERSION) || __has_include()) // Clang has convenient feature detection macros \o/ #define HAVE_REF_QUALIFIERS __has_feature(cxx_reference_qualified_functions) #define HAVE_INHERITING_CTORS __has_feature(cxx_inheriting_constructors) @@ -97,7 +102,9 @@ #endif #if defined(__GNUC__) && !defined(__clang__) -// GCC supports two of these from 4.6 up and the others from 4.8 up +// GCC 5 required for this +#define HAVE_PUT_TIME (__GNUC__ >= 5) +// GCC supports these from 4.8 up #define CONSTEXPR constexpr #define NOEXCEPT noexcept #define NORETURN [[noreturn]] diff --git a/src/utils/io.hpp b/src/utils/io.hpp index 1f839f26a5ef..8559f083cda6 100644 --- a/src/utils/io.hpp +++ b/src/utils/io.hpp @@ -11,13 +11,15 @@ but WITHOUT ANY WARRANTY. See the COPYING file for more details. */ +#include "global.hpp" + // The version of libstdc++ shipped with GCC 4.x does not have put_time in the header // Thus if GCC is the compiler being used, we can simply check the compiler version. // However, if clang is being used, this won't work. // Instead, we check for the presence of the header. // This was introduced in GCC 5.1, so it's not a perfect check, but it appears to be the best available. // (Boost also uses the same check internally.) -#if (defined(__clang__) && !__has_include()) || (defined(__GNUC__) && __GNUC__ < 5) +#if !HAVE_PUT_TIME #include