diff --git a/include/fmt/format.h b/include/fmt/format.h index 52e2e7c4..30a638ad 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -381,7 +381,7 @@ template inline T* make_checked(T* p, size_t) { return p; } #endif template ::value)> -#if FMT_CLANG_VERSION +#if FMT_CLANG_VERSION >= 307 __attribute__((no_sanitize("undefined"))) #endif inline checked_ptr @@ -940,8 +940,8 @@ template struct FMT_EXTERN_TEMPLATE_API basic_data { static const char reset_color[5]; static const wchar_t wreset_color[5]; static const char signs[]; - static constexpr const char left_padding_shifts[] = {31, 31, 0, 1, 0}; - static constexpr const char right_padding_shifts[] = {0, 31, 0, 1, 0}; + static constexpr const char left_padding_shifts[5] = {31, 31, 0, 1, 0}; + static constexpr const char right_padding_shifts[5] = {0, 31, 0, 1, 0}; // DEPRECATED! These are for ABI compatibility. static const uint32_t zero_or_powers_of_10_32[]; diff --git a/include/fmt/ranges.h b/include/fmt/ranges.h index 7b58f4e1..0ebf9652 100644 --- a/include/fmt/ranges.h +++ b/include/fmt/ranges.h @@ -368,7 +368,7 @@ template struct tuple_arg_join : detail::view { basic_string_view sep; tuple_arg_join(const std::tuple& t, basic_string_view s) - : tuple{t}, sep{s} {} + : tuple(t), sep{s} {} }; template diff --git a/test/ranges-test.cc b/test/ranges-test.cc index 802f4ab2..19538b84 100644 --- a/test/ranges-test.cc +++ b/test/ranges-test.cc @@ -11,17 +11,18 @@ #include "fmt/ranges.h" +#include +#include +#include +#include + #include "gtest.h" -// Check if 'if constexpr' is supported. -#if (__cplusplus > 201402L) || \ - (defined(_MSVC_LANG) && _MSVC_LANG > 201402L && _MSC_VER >= 1910) - -# include -# include -# include -# include +#if FMT_GCC_VERSION == 0 || FMT_GCC_VERSION >= 601 +# define FMT_ENABLE_C_STYLE_ARRAY_TEST +#endif +#ifdef FMT_ENABLE_C_STYLE_ARRAY_TEST TEST(RangesTest, FormatArray) { int32_t ia[] = {1, 2, 3, 5, 7, 11}; auto iaf = fmt::format("{}", ia); @@ -33,6 +34,7 @@ TEST(RangesTest, Format2dArray) { auto iaf = fmt::format("{}", ia); EXPECT_EQ("{{1, 2}, {3, 5}, {7, 11}}", iaf); } +#endif TEST(RangesTest, FormatVector) { std::vector iv{1, 2, 3, 5, 7, 11}; @@ -51,10 +53,12 @@ TEST(RangesTest, FormatMap) { EXPECT_EQ("{(\"one\", 1), (\"two\", 2)}", fmt::format("{}", simap)); } +#ifdef FMT_ENABLE_C_STYLE_ARRAY_TEST TEST(RangesTest, FormatArrayOfLiterals) { const char* aol[] = {"1234", "abcd"}; EXPECT_EQ("{\"1234\", \"abcd\"}", fmt::format("{}", aol)); } +#endif TEST(RangesTest, FormatPair) { std::pair pa1{42, 1.5f}; @@ -96,15 +100,17 @@ TEST(RangesTest, JoinInitializerList) { struct my_struct { int32_t i; std::string str; // can throw - template decltype(auto) get() const noexcept { - if constexpr (N == 0) - return i; - else if constexpr (N == 1) - return fmt::string_view{str}; + template fmt::enable_if_t get() const noexcept { + return i; + } + template + fmt::enable_if_t get() const noexcept { + return {str}; } }; -template decltype(auto) get(const my_struct& s) noexcept { +template +auto get(const my_struct& s) noexcept -> decltype(s.get()) { return s.get(); } @@ -125,7 +131,7 @@ TEST(RangesTest, FormatStruct) { TEST(RangesTest, FormatTo) { char buf[10]; - auto end = fmt::format_to(buf, "{}", std::vector{1, 2, 3}); + auto end = fmt::format_to(buf, "{}", std::vector{1, 2, 3}); *end = '\0'; EXPECT_STREQ(buf, "{1, 2, 3}"); } @@ -141,9 +147,6 @@ TEST(RangesTest, PathLike) { EXPECT_FALSE((fmt::is_range::value)); } -#endif // (__cplusplus > 201402L) || (defined(_MSVC_LANG) && _MSVC_LANG > - // 201402L && _MSC_VER >= 1910) - #ifdef FMT_USE_STRING_VIEW struct string_like { const char* begin();