summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Greg Falcon <gfalcon@google.com>2023-06-09 09:38:13 -0700
committerGravatar Copybara-Service <copybara-worker@google.com>2023-06-09 09:39:14 -0700
commit0f4133aacfa2ebc84c76f69e6ab02ce58603072f (patch)
treec544342eb77ba2112c31ec5b419468f476eab86c
parent163cade8645fad00682b6829b4eac92be9e71b89 (diff)
StrFormat() simplification: Treat %v unconditionally as %d when formatting integers.
This is a simplification but not a behavior change; we used to choose %u for unsigned ints, but %u and %d generate the same output for these types. PiperOrigin-RevId: 539104599 Change-Id: I9d7ff561b969a6287889f95063636d6b77a4a78b
-rw-r--r--absl/strings/internal/str_format/arg.cc23
1 files changed, 1 insertions, 22 deletions
diff --git a/absl/strings/internal/str_format/arg.cc b/absl/strings/internal/str_format/arg.cc
index 018dd052..6033a75a 100644
--- a/absl/strings/internal/str_format/arg.cc
+++ b/absl/strings/internal/str_format/arg.cc
@@ -278,24 +278,6 @@ bool ConvertIntImplInnerSlow(const IntDigits &as_digits,
return true;
}
-template <typename T,
- typename std::enable_if<(std::is_integral<T>::value &&
- std::is_signed<T>::value) ||
- std::is_same<T, int128>::value,
- int>::type = 0>
-constexpr auto ConvertV(T) {
- return FormatConversionCharInternal::d;
-}
-
-template <typename T,
- typename std::enable_if<(std::is_integral<T>::value &&
- std::is_unsigned<T>::value) ||
- std::is_same<T, uint128>::value,
- int>::type = 0>
-constexpr auto ConvertV(T) {
- return FormatConversionCharInternal::u;
-}
-
template <typename T>
bool ConvertFloatArg(T v, FormatConversionSpecImpl conv, FormatSinkImpl *sink) {
if (conv.conversion_char() == FormatConversionCharInternal::v) {
@@ -332,10 +314,6 @@ bool ConvertIntArg(T v, FormatConversionSpecImpl conv, FormatSinkImpl *sink) {
using U = typename MakeUnsigned<T>::type;
IntDigits as_digits;
- if (conv.conversion_char() == FormatConversionCharInternal::v) {
- conv.set_conversion_char(ConvertV(T{}));
- }
-
// This odd casting is due to a bug in -Wswitch behavior in gcc49 which causes
// it to complain about a switch/case type mismatch, even though both are
// FormatConverionChar. Likely this is because at this point
@@ -361,6 +339,7 @@ bool ConvertIntArg(T v, FormatConversionSpecImpl conv, FormatSinkImpl *sink) {
case static_cast<uint8_t>(FormatConversionCharInternal::d):
case static_cast<uint8_t>(FormatConversionCharInternal::i):
+ case static_cast<uint8_t>(FormatConversionCharInternal::v):
as_digits.PrintAsDec(v);
break;