diff options
author | 2022-10-17 15:40:12 -0700 | |
---|---|---|
committer | 2022-10-17 15:41:03 -0700 | |
commit | 94433ef0615616b1ccb8b2193bde777c10406ac0 (patch) | |
tree | 9e1f282cc0ff5603929431774320db3fe2fdeb21 /absl/log/internal/log_format.cc | |
parent | 6b2d248d3e9fb5f07ea4a65a6d0923726854d446 (diff) |
Fix various warnings for _WIN32.
Bug: chromium:1292951
PiperOrigin-RevId: 481757795
Change-Id: I03c808222c6c4d3d7052576ab4b36141e5f1ebbc
Diffstat (limited to 'absl/log/internal/log_format.cc')
-rw-r--r-- | absl/log/internal/log_format.cc | 33 |
1 files changed, 26 insertions, 7 deletions
diff --git a/absl/log/internal/log_format.cc b/absl/log/internal/log_format.cc index 5d40d253..5b280a2d 100644 --- a/absl/log/internal/log_format.cc +++ b/absl/log/internal/log_format.cc @@ -46,6 +46,31 @@ ABSL_NAMESPACE_BEGIN namespace log_internal { namespace { +// This templated function avoids compiler warnings about tautological +// comparisons when log_internal::Tid is unsigned. It can be replaced with a +// constexpr if once the minimum C++ version Abseil suppports is C++17. +template <typename T> +inline std::enable_if_t<!std::is_signed<T>::value> +PutLeadingWhitespace(T tid, char*& p) { + if (tid < 10) *p++ = ' '; + if (tid < 100) *p++ = ' '; + if (tid < 1000) *p++ = ' '; + if (tid < 10000) *p++ = ' '; + if (tid < 100000) *p++ = ' '; + if (tid < 1000000) *p++ = ' '; +} + +template <typename T> +inline std::enable_if_t<std::is_signed<T>::value> +PutLeadingWhitespace(T tid, char*& p) { + if (tid >= 0 && tid < 10) *p++ = ' '; + if (tid > -10 && tid < 100) *p++ = ' '; + if (tid > -100 && tid < 1000) *p++ = ' '; + if (tid > -1000 && tid < 10000) *p++ = ' '; + if (tid > -10000 && tid < 100000) *p++ = ' '; + if (tid > -100000 && tid < 1000000) *p++ = ' '; +} + // The fields before the filename are all fixed-width except for the thread ID, // which is of bounded width. size_t FormatBoundedFields(absl::LogSeverity severity, absl::Time timestamp, @@ -110,13 +135,7 @@ size_t FormatBoundedFields(absl::LogSeverity severity, absl::Time timestamp, absl::numbers_internal::PutTwoDigits(static_cast<size_t>(usecs % 100), p); p += 2; *p++ = ' '; - constexpr bool unsigned_tid_t = !std::is_signed<log_internal::Tid>::value; - if ((unsigned_tid_t || tid >= 0) && tid < 10) *p++ = ' '; - if ((unsigned_tid_t || tid > -10) && tid < 100) *p++ = ' '; - if ((unsigned_tid_t || tid > -100) && tid < 1000) *p++ = ' '; - if ((unsigned_tid_t || tid > -1000) && tid < 10000) *p++ = ' '; - if ((unsigned_tid_t || tid > -10000) && tid < 100000) *p++ = ' '; - if ((unsigned_tid_t || tid > -100000) && tid < 1000000) *p++ = ' '; + PutLeadingWhitespace(tid, p); p = absl::numbers_internal::FastIntToBuffer(tid, p); *p++ = ' '; const size_t bytes_formatted = static_cast<size_t>(p - buf.data()); |