[llvm] r295064 - [Support] Add formatv support for StringLiteral
Pavel Labath via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 14 08:35:57 PST 2017
Author: labath
Date: Tue Feb 14 10:35:56 2017
New Revision: 295064
URL: http://llvm.org/viewvc/llvm-project?rev=295064&view=rev
Log:
[Support] Add formatv support for StringLiteral
Summary:
This is achieved by generalizing the expression selecting the StringRef
format_provider. Now, anything that can be converted to a StringRef will
use it's formatter.
Reviewers: zturner
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D29898
Modified:
llvm/trunk/include/llvm/Support/FormatProviders.h
llvm/trunk/unittests/Support/FormatVariadicTest.cpp
Modified: llvm/trunk/include/llvm/Support/FormatProviders.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/FormatProviders.h?rev=295064&r1=295063&r2=295064&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/FormatProviders.h (original)
+++ llvm/trunk/include/llvm/Support/FormatProviders.h Tue Feb 14 10:35:56 2017
@@ -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);
}
};
Modified: llvm/trunk/unittests/Support/FormatVariadicTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Support/FormatVariadicTest.cpp?rev=295064&r1=295063&r2=295064&view=diff
==============================================================================
--- llvm/trunk/unittests/Support/FormatVariadicTest.cpp (original)
+++ llvm/trunk/unittests/Support/FormatVariadicTest.cpp Tue Feb 14 10:35:56 2017
@@ -324,11 +324,13 @@ TEST(FormatVariadicTest, StringFormattin
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
More information about the llvm-commits
mailing list