diff --git a/fmt/format.cc b/fmt/format.cc index 266f8702..e759084b 100644 --- a/fmt/format.cc +++ b/fmt/format.cc @@ -281,10 +281,8 @@ template const uint64_t internal::basic_data::POWERS_OF_10_64[] = { 0, FMT_POWERS_OF_10(1), - FMT_POWERS_OF_10(ulong_long(1000000000)), - // Multiply several constants instead of using a single long long constant - // to avoid warnings about C++98 not supporting long long. - ulong_long(1000000000) * ulong_long(1000000000) * 10 + FMT_POWERS_OF_10(1000000000ull), + 10000000000000000000ull }; FMT_FUNC void internal::report_unknown_type(char code, const char *type) { diff --git a/fmt/format.h b/fmt/format.h index b2f3e56a..1be263e5 100644 --- a/fmt/format.h +++ b/fmt/format.h @@ -41,6 +41,7 @@ #include #include #include +#include #ifdef _SECURE_SCL # define FMT_SECURE_SCL _SECURE_SCL @@ -52,20 +53,6 @@ # include #endif -#ifdef _MSC_VER -# define FMT_MSC_VER _MSC_VER -#else -# define FMT_MSC_VER 0 -#endif - -#if FMT_MSC_VER && FMT_MSC_VER <= 1500 -typedef unsigned __int32 uint32_t; -typedef unsigned __int64 uint64_t; -typedef __int64 intmax_t; -#else -#include -#endif - #if !defined(FMT_HEADER_ONLY) && defined(_WIN32) # ifdef FMT_EXPORT # define FMT_API __declspec(dllexport) @@ -79,14 +66,9 @@ typedef __int64 intmax_t; #ifdef __GNUC__ # define FMT_GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__) -# define FMT_GCC_EXTENSION __extension__ # if FMT_GCC_VERSION >= 406 # pragma GCC diagnostic push -// Disable the warning about "long long" which is sometimes reported even -// when using __extension__. -# pragma GCC diagnostic ignored "-Wlong-long" - // Disable the warning about declaration shadowing because it affects too // many valid cases. # pragma GCC diagnostic ignored "-Wshadow" @@ -99,8 +81,6 @@ typedef __int64 intmax_t; # if __cplusplus >= 201103L || defined __GXX_EXPERIMENTAL_CXX0X__ # define FMT_HAS_GXX_CXX11 1 # endif -#else -# define FMT_GCC_EXTENSION #endif #if defined(__INTEL_COMPILER) @@ -119,6 +99,12 @@ typedef __int64 intmax_t; # define FMT_GNUC_LIBSTD_VERSION (__GNUC_LIBSTD__ * 100 + __GNUC_LIBSTD_MINOR__) #endif +#ifdef _MSC_VER +# define FMT_MSC_VER _MSC_VER +#else +# define FMT_MSC_VER 0 +#endif + #ifdef __has_feature # define FMT_HAS_FEATURE(x) __has_feature(x) #else @@ -368,11 +354,6 @@ class numeric_limits : namespace fmt { -// Fix the warning about long long on older versions of GCC -// that don't support the diagnostic pragma. -FMT_GCC_EXTENSION typedef long long long_long; -FMT_GCC_EXTENSION typedef unsigned long long ulong_long; - #if FMT_USE_RVALUE_REFERENCES using std::move; #endif @@ -523,7 +504,7 @@ FMT_SPECIALIZE_MAKE_UNSIGNED(signed char, unsigned char); FMT_SPECIALIZE_MAKE_UNSIGNED(short, unsigned short); FMT_SPECIALIZE_MAKE_UNSIGNED(int, unsigned); FMT_SPECIALIZE_MAKE_UNSIGNED(long, unsigned long); -FMT_SPECIALIZE_MAKE_UNSIGNED(long_long, ulong_long); +FMT_SPECIALIZE_MAKE_UNSIGNED(long long, unsigned long long); // Casts nonnegative integer to unsigned. template @@ -1168,7 +1149,7 @@ typedef char no[2]; template T &get(); -yes &convert(fmt::ulong_long); +yes &convert(unsigned long long); no &convert(...); template @@ -1267,8 +1248,8 @@ template <> constexpr Type gettype() { return sizeof(unsigned long) == sizeof(unsigned) ? UINT : ULONG_LONG; } -template <> constexpr Type gettype() { return LONG_LONG; } -template <> constexpr Type gettype() { return ULONG_LONG; } +template <> constexpr Type gettype() { return LONG_LONG; } +template <> constexpr Type gettype() { return ULONG_LONG; } template <> constexpr Type gettype() { return DOUBLE; } template <> constexpr Type gettype() { return DOUBLE; } template <> constexpr Type gettype() { return LONG_DOUBLE; } @@ -1305,8 +1286,8 @@ class value { union { int int_value; unsigned uint_value; - long_long long_long_value; - ulong_long ulong_long_value; + long long long_long_value; + unsigned long long ulong_long_value; double double_value; long double long_double_value; const void *pointer; @@ -1401,8 +1382,8 @@ class value { this->ulong_long_value = value; } - FMT_MAKE_VALUE(long_long, long_long_value, LONG_LONG) - FMT_MAKE_VALUE(ulong_long, ulong_long_value, ULONG_LONG) + FMT_MAKE_VALUE(long long, long_long_value, LONG_LONG) + FMT_MAKE_VALUE(unsigned long long, ulong_long_value, ULONG_LONG) FMT_MAKE_VALUE(float, double_value, DOUBLE) FMT_MAKE_VALUE(double, double_value, DOUBLE) FMT_MAKE_VALUE(long double, long_double_value, LONG_DOUBLE) @@ -2437,7 +2418,7 @@ class basic_writer { void write(long value) { write_decimal(value); } - void write(long_long value) { + void write(long long value) { write_decimal(value); } @@ -3039,12 +3020,12 @@ class FormatInt { private: // Buffer should be large enough to hold all digits (digits10 + 1), // a sign and a null character. - enum {BUFFER_SIZE = std::numeric_limits::digits10 + 3}; + enum {BUFFER_SIZE = std::numeric_limits::digits10 + 3}; mutable char buffer_[BUFFER_SIZE]; char *str_; // Formats value in reverse and returns the number of digits. - char *format_decimal(ulong_long value) { + char *format_decimal(unsigned long long value) { char *buffer_end = buffer_ + BUFFER_SIZE - 1; while (value >= 100) { // Integer division is slow so do it for a group of two digits instead @@ -3065,8 +3046,8 @@ class FormatInt { return buffer_end; } - void FormatSigned(long_long value) { - ulong_long abs_value = static_cast(value); + void FormatSigned(long long value) { + unsigned long long abs_value = static_cast(value); bool negative = value < 0; if (negative) abs_value = 0 - abs_value; @@ -3078,10 +3059,10 @@ class FormatInt { public: explicit FormatInt(int value) { FormatSigned(value); } explicit FormatInt(long value) { FormatSigned(value); } - explicit FormatInt(long_long value) { FormatSigned(value); } + explicit FormatInt(long long value) { FormatSigned(value); } explicit FormatInt(unsigned value) : str_(format_decimal(value)) {} explicit FormatInt(unsigned long value) : str_(format_decimal(value)) {} - explicit FormatInt(ulong_long value) : str_(format_decimal(value)) {} + explicit FormatInt(unsigned long long value) : str_(format_decimal(value)) {} /** Returns the number of characters written to the output buffer. */ std::size_t size() const { @@ -3246,7 +3227,7 @@ struct is_integer { struct width_handler { template - typename std::enable_if::value, ulong_long>::type + typename std::enable_if::value, unsigned long long>::type operator()(T value) { if (is_negative(value)) FMT_THROW(format_error("negative width")); @@ -3254,7 +3235,7 @@ struct width_handler { } template - typename std::enable_if::value, ulong_long>::type + typename std::enable_if::value, unsigned long long>::type operator()(T value) { FMT_THROW(format_error("width is not integer")); return 0; @@ -3263,7 +3244,7 @@ struct width_handler { struct precision_handler { template - typename std::enable_if::value, ulong_long>::type + typename std::enable_if::value, unsigned long long>::type operator()(T value) { if (is_negative(value)) FMT_THROW(format_error("negative precision")); @@ -3271,7 +3252,7 @@ struct precision_handler { } template - typename std::enable_if::value, ulong_long>::type + typename std::enable_if::value, unsigned long long>::type operator()(T value) { FMT_THROW(format_error("precision is not integer")); return 0; @@ -3308,7 +3289,7 @@ class specs_handler_base { template inline void set_dynamic_spec(T &value, basic_arg arg) { - ulong_long big_value = visit(Handler(), arg); + unsigned long long big_value = visit(Handler(), arg); if (big_value > (std::numeric_limits::max)()) FMT_THROW(format_error("number is too big")); value = static_cast(big_value); diff --git a/fmt/posix.cc b/fmt/posix.cc index 5c37de6a..59e92539 100644 --- a/fmt/posix.cc +++ b/fmt/posix.cc @@ -124,7 +124,7 @@ void fmt::File::close() { throw system_error(errno, "cannot close file"); } -fmt::long_long fmt::File::size() const { +long long fmt::File::size() const { #ifdef _WIN32 // Use GetFileSize instead of GetFileSizeEx for the case when _WIN32_WINNT // is less than 0x0500 as is the case with some default MinGW builds. @@ -137,14 +137,14 @@ fmt::long_long fmt::File::size() const { if (error != NO_ERROR) throw windows_error(GetLastError(), "cannot get file size"); } - fmt::ulong_long long_size = size_upper; + unsigned long long long_size = size_upper; return (long_size << sizeof(DWORD) * CHAR_BIT) | size_lower; #else typedef struct stat Stat; Stat file_stat = Stat(); if (FMT_POSIX_CALL(fstat(fd_, &file_stat)) == -1) throw system_error(errno, "cannot get file attributes"); - FMT_STATIC_ASSERT(sizeof(fmt::long_long) >= sizeof(file_stat.st_size), + FMT_STATIC_ASSERT(sizeof(long long) >= sizeof(file_stat.st_size), "return type of File::size is not large enough"); return file_stat.st_size; #endif diff --git a/fmt/posix.h b/fmt/posix.h index c0cb2b62..90aba316 100644 --- a/fmt/posix.h +++ b/fmt/posix.h @@ -322,7 +322,7 @@ class File { // Returns the file size. The size has signed type for consistency with // stat::st_size. - long_long size() const; + long long size() const; // Attempts to read count bytes from the file into the specified buffer. std::size_t read(void *buffer, std::size_t count); diff --git a/fmt/printf.h b/fmt/printf.h index f02f8e41..272da034 100644 --- a/fmt/printf.h +++ b/fmt/printf.h @@ -119,7 +119,7 @@ class ArgConverter { // glibc's printf doesn't sign extend arguments of smaller types: // std::printf("%lld", -42); // prints "4294967254" // but we don't have to do the same because it's a UB. - arg_ = internal::make_arg(static_cast(value)); + arg_ = internal::make_arg(static_cast(value)); } else { arg_ = internal::make_arg( static_cast::type>(value)); @@ -486,7 +486,7 @@ void printf_context::format( break; case 'l': if (*it == 'l') - convert_arg(arg, *++it); + convert_arg(arg, *++it); else convert_arg(arg, *it); break; diff --git a/test/format-impl-test.cc b/test/format-impl-test.cc index 637f6225..11bdacc0 100644 --- a/test/format-impl-test.cc +++ b/test/format-impl-test.cc @@ -56,11 +56,10 @@ struct ValueExtractor { }; TEST(FormatTest, ArgConverter) { - fmt::long_long value = std::numeric_limits::max(); + long long value = std::numeric_limits::max(); auto arg = fmt::internal::make_arg(value); - visit(fmt::internal::ArgConverter< - fmt::long_long, fmt::context>(arg, 'd'), arg); - EXPECT_EQ(value, visit(ValueExtractor(), arg)); + visit(fmt::internal::ArgConverter(arg, 'd'), arg); + EXPECT_EQ(value, visit(ValueExtractor(), arg)); } TEST(FormatTest, FormatNegativeNaN) { diff --git a/test/posix-mock-test.cc b/test/posix-mock-test.cc index f960b60f..ece17e8d 100644 --- a/test/posix-mock-test.cc +++ b/test/posix-mock-test.cc @@ -277,7 +277,7 @@ TEST(FileTest, Size) { write_file("test", content); File f("test", File::RDONLY); EXPECT_GE(f.size(), 0); - EXPECT_EQ(content.size(), static_cast(f.size())); + EXPECT_EQ(content.size(), static_cast(f.size())); #ifdef _WIN32 fmt::memory_buffer message; fmt::internal::format_windows_error( diff --git a/test/printf-test.cc b/test/printf-test.cc index 312f714f..aeeac1f3 100644 --- a/test/printf-test.cc +++ b/test/printf-test.cc @@ -269,8 +269,8 @@ TEST(PrintfTest, DynamicPrecision) { "argument index out of range"); EXPECT_THROW_MSG(fmt::sprintf("%.*d", BIG_NUM, 42), format_error, "number is too big"); - if (sizeof(fmt::long_long) != sizeof(int)) { - fmt::long_long prec = static_cast(INT_MIN) - 1; + if (sizeof(long long) != sizeof(int)) { + long long prec = static_cast(INT_MIN) - 1; EXPECT_THROW_MSG(fmt::sprintf("%.*d", prec, 42), format_error, "number is too big"); } @@ -288,16 +288,16 @@ SPECIALIZE_MAKE_SIGNED(unsigned char, signed char); SPECIALIZE_MAKE_SIGNED(unsigned short, short); SPECIALIZE_MAKE_SIGNED(unsigned, int); SPECIALIZE_MAKE_SIGNED(unsigned long, long); -SPECIALIZE_MAKE_SIGNED(fmt::ulong_long, fmt::long_long); +SPECIALIZE_MAKE_SIGNED(unsigned long long, long long); // Test length format specifier ``length_spec``. template void TestLength(const char *length_spec, U value) { - fmt::long_long signed_value = 0; - fmt::ulong_long unsigned_value = 0; + long long signed_value = 0; + unsigned long long unsigned_value = 0; // Apply integer promotion to the argument. using std::numeric_limits; - fmt::ulong_long max = numeric_limits::max(); + unsigned long long max = numeric_limits::max(); using fmt::internal::const_check; if (const_check(max <= static_cast(numeric_limits::max()))) { signed_value = static_cast(value); @@ -308,7 +308,7 @@ void TestLength(const char *length_spec, U value) { } using fmt::internal::make_unsigned; if (sizeof(U) <= sizeof(int) && sizeof(int) < sizeof(T)) { - signed_value = static_cast(value); + signed_value = static_cast(value); unsigned_value = static_cast::type>(value); } else { signed_value = static_cast::type>(value); @@ -339,20 +339,20 @@ void TestLength(const char *length_spec) { TestLength(length_spec, -42); TestLength(length_spec, min); TestLength(length_spec, max); - TestLength(length_spec, fmt::long_long(min) - 1); - fmt::ulong_long long_long_max = std::numeric_limits::max(); - if (static_cast(max) < long_long_max) - TestLength(length_spec, fmt::long_long(max) + 1); + TestLength(length_spec, static_cast(min) - 1); + unsigned long long long_long_max = std::numeric_limits::max(); + if (static_cast(max) < long_long_max) + TestLength(length_spec, static_cast(max) + 1); TestLength(length_spec, std::numeric_limits::min()); TestLength(length_spec, std::numeric_limits::max()); TestLength(length_spec, std::numeric_limits::min()); TestLength(length_spec, std::numeric_limits::max()); TestLength(length_spec, std::numeric_limits::min()); TestLength(length_spec, std::numeric_limits::max()); - TestLength(length_spec, std::numeric_limits::min()); - TestLength(length_spec, std::numeric_limits::max()); - TestLength(length_spec, std::numeric_limits::min()); - TestLength(length_spec, std::numeric_limits::max()); + TestLength(length_spec, std::numeric_limits::min()); + TestLength(length_spec, std::numeric_limits::max()); + TestLength(length_spec, std::numeric_limits::min()); + TestLength(length_spec, std::numeric_limits::max()); } TEST(PrintfTest, Length) { @@ -363,8 +363,8 @@ TEST(PrintfTest, Length) { TestLength("h"); TestLength("l"); TestLength("l"); - TestLength("ll"); - TestLength("ll"); + TestLength("ll"); + TestLength("ll"); TestLength("j"); TestLength("z"); TestLength("t"); @@ -391,7 +391,7 @@ TEST(PrintfTest, Int) { TEST(PrintfTest, long_long) { // fmt::printf allows passing long long arguments to %d without length // specifiers. - fmt::long_long max = std::numeric_limits::max(); + long long max = std::numeric_limits::max(); EXPECT_PRINTF(fmt::format("{}", max), "%d", max); } diff --git a/test/util-test.cc b/test/util-test.cc index 6bae0439..b61d12f3 100644 --- a/test/util-test.cc +++ b/test/util-test.cc @@ -510,8 +510,8 @@ VISIT_TYPE(unsigned short, unsigned); VISIT_TYPE(long, int); VISIT_TYPE(unsigned long, unsigned); #else -VISIT_TYPE(long, fmt::long_long); -VISIT_TYPE(unsigned long, fmt::ulong_long); +VISIT_TYPE(long, long long); +VISIT_TYPE(unsigned long, unsigned long long); #endif VISIT_TYPE(float, double); @@ -533,7 +533,7 @@ class NumericArgTest : public testing::Test {}; typedef ::testing::Types< bool, signed char, unsigned char, signed, unsigned short, - int, unsigned, long, unsigned long, fmt::long_long, fmt::ulong_long, + int, unsigned, long, unsigned long, long long, unsigned long long, float, double, long double> Types; TYPED_TEST_CASE(NumericArgTest, Types);