diff options
Diffstat (limited to 'absl')
-rw-r--r-- | absl/strings/substitute.h | 3 | ||||
-rw-r--r-- | absl/strings/substitute_test.cc | 12 |
2 files changed, 14 insertions, 1 deletions
diff --git a/absl/strings/substitute.h b/absl/strings/substitute.h index 5c3f6eff..d6a5a690 100644 --- a/absl/strings/substitute.h +++ b/absl/strings/substitute.h @@ -203,7 +203,8 @@ class Arg { // This overload matches only scoped enums. template <typename T, typename = typename std::enable_if< - std::is_enum<T>{} && !std::is_convertible<T, int>{}>::type> + std::is_enum<T>{} && !std::is_convertible<T, int>{} && + !strings_internal::HasAbslStringify<T>::value>::type> Arg(T value) // NOLINT(google-explicit-constructor) : Arg(static_cast<typename std::underlying_type<T>::type>(value)) {} diff --git a/absl/strings/substitute_test.cc b/absl/strings/substitute_test.cc index 9f04545f..9cb37c39 100644 --- a/absl/strings/substitute_test.cc +++ b/absl/strings/substitute_test.cc @@ -253,6 +253,18 @@ TEST(SubstituteTest, Enums) { ScopedEnumUInt16::kEnum1)); } +enum class EnumWithStringify { Many = 0, Choices = 1 }; + +template <typename Sink> +void AbslStringify(Sink& sink, EnumWithStringify e) { + sink.Append(e == EnumWithStringify::Many ? "Many" : "Choices"); +} + +TEST(SubstituteTest, AbslStringifyWithEnum) { + const auto e = EnumWithStringify::Choices; + EXPECT_EQ(absl::Substitute("$0", e), "Choices"); +} + #ifdef GTEST_HAS_DEATH_TEST TEST(SubstituteDeathTest, SubstituteDeath) { |