From b32339c7525ebb07f8fdb561a4b7b853a997782f Mon Sep 17 00:00:00 2001 From: Evgeny Safronov Date: Tue, 31 May 2016 22:42:27 +0300 Subject: [PATCH] fix: explicitly cast unspecified chrono rep type Blackhole can handle both signed int64 and unsigned integers, but std::chrono representation type is long long, which may vary depending on architecture where building occurs. Thus, it may lead to ambiguous integer promotion when it's time to format. This commit does explicit cast to resolve ambiguity. This should fix #126 and #129. --- src/formatter/json.cpp | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/formatter/json.cpp b/src/formatter/json.cpp index 3c049583..26004752 100644 --- a/src/formatter/json.cpp +++ b/src/formatter/json.cpp @@ -41,14 +41,19 @@ struct visitor_t { node.AddMember(rapidjson::StringRef(name.data(), name.size()), rapidjson::kNullType, allocator); } - // For `bool`, `std::int64_t`, `std::uint64_t` and `double` types. - template - auto operator()(T value) -> void { - static_assert( - std::is_same::value || - std::is_same::value || - std::is_same::value || - std::is_same::value, "type mismatch"); + auto operator()(bool value) -> void { + node.AddMember(rapidjson::StringRef(name.data(), name.size()), value, allocator); + } + + auto operator()(std::int64_t value) -> void { + node.AddMember(rapidjson::StringRef(name.data(), name.size()), value, allocator); + } + + auto operator()(std::uint64_t value) -> void { + node.AddMember(rapidjson::StringRef(name.data(), name.size()), value, allocator); + } + + auto operator()(double value) -> void { node.AddMember(rapidjson::StringRef(name.data(), name.size()), value, allocator); } @@ -219,9 +224,10 @@ class json_t::inner_t::builder { inner.timestamp(record.timestamp(), wr); apply("timestamp", wr.inner.data(), wr.inner.size()); } else { - apply("timestamp", std::chrono::duration_cast< + const auto timestamp = std::chrono::duration_cast< std::chrono::microseconds - >(record.timestamp().time_since_epoch()).count()); + >(record.timestamp().time_since_epoch()).count(); + apply("timestamp", static_cast(timestamp)); } }