diff options
Diffstat (limited to 'absl/log/internal')
-rw-r--r-- | absl/log/internal/log_format.cc | 33 | ||||
-rw-r--r-- | absl/log/internal/test_helpers.cc | 2 |
2 files changed, 27 insertions, 8 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()); diff --git a/absl/log/internal/test_helpers.cc b/absl/log/internal/test_helpers.cc index bff5cc17..0de5b96b 100644 --- a/absl/log/internal/test_helpers.cc +++ b/absl/log/internal/test_helpers.cc @@ -46,7 +46,7 @@ bool DiedOfFatal(int exit_status) { // Depending on NDEBUG and (configuration?) MSVC's abort either results // in error code 3 (SIGABRT) or error code 0x80000003 (breakpoint // triggered). - return ::testing::ExitedWithCode(3)(exit_status & ~0x80000000); + return ::testing::ExitedWithCode(3)(exit_status & 0x7fffffff); #elif defined(__Fuchsia__) // The Fuchsia death test implementation kill()'s the process when it detects // an exception, so it should exit with the corresponding code. See |