diff options
| -rw-r--r-- | llvm/include/llvm/Support/FormatProviders.h | 7 | ||||
| -rw-r--r-- | llvm/unittests/Support/FormatVariadicTest.cpp | 2 |
2 files changed, 5 insertions, 4 deletions
diff --git a/llvm/include/llvm/Support/FormatProviders.h b/llvm/include/llvm/Support/FormatProviders.h index 1f0768c3ab0..54a37169d3a 100644 --- a/llvm/include/llvm/Support/FormatProviders.h +++ b/llvm/include/llvm/Support/FormatProviders.h @@ -45,9 +45,8 @@ struct is_cstring template <typename T> struct use_string_formatter - : public std::integral_constant< - bool, is_one_of<T, llvm::StringRef, std::string>::value || - is_cstring<T>::value> {}; + : public std::integral_constant<bool, + std::is_convertible<T, llvm::StringRef>::value> {}; template <typename T> struct use_pointer_formatter @@ -205,7 +204,7 @@ struct format_provider< if (!Style.empty() && Style.getAsInteger(10, N)) { assert(false && "Style is not a valid integer"); } - llvm::StringRef S(V); + llvm::StringRef S = V; Stream << S.substr(0, N); } }; diff --git a/llvm/unittests/Support/FormatVariadicTest.cpp b/llvm/unittests/Support/FormatVariadicTest.cpp index 9307c6d8e09..b0c843870af 100644 --- a/llvm/unittests/Support/FormatVariadicTest.cpp +++ b/llvm/unittests/Support/FormatVariadicTest.cpp @@ -324,11 +324,13 @@ TEST(FormatVariadicTest, StringFormatting) { const char FooArray[] = "FooArray"; const char *FooPtr = "FooPtr"; llvm::StringRef FooRef("FooRef"); + constexpr StringLiteral FooLiteral("FooLiteral"); std::string FooString("FooString"); // 1. Test that we can print various types of strings. EXPECT_EQ(FooArray, formatv("{0}", FooArray).str()); EXPECT_EQ(FooPtr, formatv("{0}", FooPtr).str()); EXPECT_EQ(FooRef, formatv("{0}", FooRef).str()); + EXPECT_EQ(FooLiteral, formatv("{0}", FooLiteral).str()); EXPECT_EQ(FooString, formatv("{0}", FooString).str()); // 2. Test that the precision specifier prints the correct number of |

