diff --git a/format.cc b/format.cc index 0a839223..bcb660a9 100644 --- a/format.cc +++ b/format.cc @@ -109,6 +109,12 @@ inline int safe_printf(char *buffer, size_t size, const char *format, ...) { #endif // _MSC_VER +template +struct IsLongDouble { enum {VALUE = 0}; }; + +template <> +struct IsLongDouble { enum {VALUE = 1}; }; + const char RESET_COLOR[] = "\x1b[0m"; typedef void (*FormatFunc)(fmt::Writer &, int , fmt::StringRef); @@ -260,8 +266,6 @@ inline Arg::StringValue ignore_incompatible_str( Arg::StringValue s) { return s; } } // namespace -int fmt::internal::signbit_noinline(double value) { return getsign(value); } - void fmt::SystemError::init( int error_code, StringRef format_str, const ArgList &args) { error_code_ = error_code; @@ -645,7 +649,7 @@ void fmt::BasicWriter::write_double(T value, const FormatSpec &spec) { *format_ptr++ = '.'; *format_ptr++ = '*'; } - if (internal::IsLongDouble::VALUE) + if (IsLongDouble::VALUE) *format_ptr++ = 'L'; *format_ptr++ = type; *format_ptr = '\0'; diff --git a/format.h b/format.h index 9a2f75c6..8d251a63 100644 --- a/format.h +++ b/format.h @@ -410,8 +410,6 @@ inline bool is_negative(T value) { return SignChecker::is_signed>::is_negative(value); } -int signbit_noinline(double value); - template struct IntTraits { // Smallest of uint32_t and uint64_t that is large enough to represent @@ -435,12 +433,6 @@ FMT_SPECIALIZE_MAKE_UNSIGNED(int, unsigned); FMT_SPECIALIZE_MAKE_UNSIGNED(long, unsigned long); FMT_SPECIALIZE_MAKE_UNSIGNED(LongLong, ULongLong); -template -struct IsLongDouble { enum {VALUE = 0}; }; - -template <> -struct IsLongDouble { enum {VALUE = 1}; }; - void report_unknown_type(char code, const char *type); extern const uint32_t POWERS_OF_10_32[]; @@ -452,7 +444,7 @@ extern const uint64_t POWERS_OF_10_64[]; inline unsigned count_digits(uint64_t n) { // Based on http://graphics.stanford.edu/~seander/bithacks.html#IntegerLog10 // and the benchmark https://github.com/localvoid/cxx-benchmark-count-digits. - uint64_t t = (64 - __builtin_clzll(n | 1)) * 1233 >> 12; + unsigned t = (64 - __builtin_clzll(n | 1)) * 1233 >> 12; return t - (n < POWERS_OF_10_64[t]) + 1; } # if FMT_GCC_VERSION >= 400 || FMT_HAS_BUILTIN(__builtin_clz) @@ -1862,10 +1854,10 @@ class FormatInt { } void FormatSigned(LongLong value) { - ULongLong abs_value = value; + ULongLong abs_value = static_cast(value); bool negative = value < 0; if (negative) - abs_value = 0 - value; + abs_value = 0 - abs_value; str_ = format_decimal(abs_value); if (negative) *--str_ = '-'; diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 31b1e455..f30ca70a 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,17 +1,21 @@ set(TEST_MAIN_SRC test-main.cc gtest-extra.cc gtest-extra.h util.cc) add_library(test-main ${TEST_MAIN_SRC}) -target_link_libraries(test-main gtest format) +target_link_libraries(test-main gtest) # Adds a test. # Usage: add_fmt_test(name libs srcs...) function(add_fmt_test name libs) - add_executable(${name} ${name}.cc ${ARGN}) + cmake_parse_arguments(add_fmt_test CUSTOM_LINK "" "" ${ARGN}) + add_executable(${name} ${name}.cc ${add_fmt_test_UNPARSED_ARGUMENTS}) target_link_libraries(${name} ${libs}) + if (NOT add_fmt_test_CUSTOM_LINK) + target_link_libraries(${name} format) + endif () add_test(${name} ${name}) endfunction() add_fmt_test(gtest-extra-test test-main) -add_fmt_test(format-test test-main) +add_fmt_test(format-test test-main CUSTOM_LINK ../posix.cc ../posix.h) add_fmt_test(printf-test test-main) foreach (target format-test printf-test) if (CMAKE_COMPILER_IS_GNUCXX) diff --git a/test/format-test.cc b/test/format-test.cc index d69fce55..8e87911b 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -35,6 +35,13 @@ #include #include +// Include format.cc instead of format.h to test implementation-specific stuff. +#include "format.cc" +#include "util.h" +#include "gtest-extra.h" + +#include + #if defined(_WIN32) && !defined(__MINGW32__) // Fix MSVC warning about "unsafe" fopen. FILE *safe_fopen(const char *filename, const char *mode) { @@ -45,12 +52,6 @@ FILE *safe_fopen(const char *filename, const char *mode) { #define fopen safe_fopen #endif -#include "format.h" -#include "util.h" -#include "gtest-extra.h" - -#include - #undef min #undef max @@ -1230,7 +1231,7 @@ TEST(FormatterTest, FormatNaN) { double nan = std::numeric_limits::quiet_NaN(); EXPECT_EQ("nan", format("{}", nan)); EXPECT_EQ("+nan", format("{:+}", nan)); - if (fmt::internal::signbit_noinline(-nan)) + if (getsign(-nan)) EXPECT_EQ("-nan", format("{}", -nan)); else fmt::print("Warning: compiler doesn't handle negative NaN correctly");