[PATCH] D94769: [Support] Format provider improvements
Vladislav Vinogradov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 19 05:44:31 PST 2021
vinograd47 updated this revision to Diff 317539.
vinograd47 edited the summary of this revision.
vinograd47 added a comment.
Herald added subscribers: stephenneuendorffer, rriddle.
Added a test for the case, which this change fixes.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D94769/new/
https://reviews.llvm.org/D94769
Files:
llvm/include/llvm/Support/FormatProviders.h
llvm/include/llvm/Support/FormatVariadicDetails.h
llvm/unittests/Support/FormatVariadicTest.cpp
Index: llvm/unittests/Support/FormatVariadicTest.cpp
===================================================================
--- llvm/unittests/Support/FormatVariadicTest.cpp
+++ llvm/unittests/Support/FormatVariadicTest.cpp
@@ -698,3 +698,23 @@
EXPECT_EQ("X", formatv("{0}", fmt_consume(std::move(E1))).str());
EXPECT_FALSE(E1.isA<StringError>()); // consumed
}
+
+namespace {
+
+class PassByRef {
+public:
+ int a = 0;
+ PassByRef(int val) : a(val) {}
+};
+
+raw_ostream &operator<<(raw_ostream &OS, PassByRef &obj) { return OS << obj.a; }
+
+static_assert(detail::has_StreamOperator<PassByRef &>::value, "");
+static_assert(detail::uses_stream_operator<PassByRef &>::value, "");
+
+TEST(FormatVariadicTest, StreamOperatorPassByRef) {
+ PassByRef obj(10);
+ EXPECT_EQ("10", formatv("{0}", obj).str());
+}
+
+} // namespace
Index: llvm/include/llvm/Support/FormatVariadicDetails.h
===================================================================
--- llvm/include/llvm/Support/FormatVariadicDetails.h
+++ llvm/include/llvm/Support/FormatVariadicDetails.h
@@ -75,8 +75,6 @@
// Test if raw_ostream& << T -> raw_ostream& is findable via ADL.
template <class T> class has_StreamOperator {
public:
- using ConstRefT = const std::decay_t<T> &;
-
template <typename U>
static char test(
std::enable_if_t<std::is_same<decltype(std::declval<llvm::raw_ostream &>()
@@ -86,7 +84,8 @@
template <typename U> static double test(...);
- static bool const value = (sizeof(test<ConstRefT>(nullptr)) == 1);
+ // NOLINTNEXTLINE(readability-identifier-naming)
+ static bool const value = (sizeof(test<T>(nullptr)) == 1);
};
// Simple template that decides whether a type T should use the member-function
Index: llvm/include/llvm/Support/FormatProviders.h
===================================================================
--- llvm/include/llvm/Support/FormatProviders.h
+++ llvm/include/llvm/Support/FormatProviders.h
@@ -355,7 +355,6 @@
template <typename IterT> class format_provider<llvm::iterator_range<IterT>> {
using value = typename std::iterator_traits<IterT>::value_type;
- using reference = typename std::iterator_traits<IterT>::reference;
static StringRef consumeOneOption(StringRef &Style, char Indicator,
StringRef Default) {
@@ -403,15 +402,13 @@
auto Begin = V.begin();
auto End = V.end();
if (Begin != End) {
- auto Adapter =
- detail::build_format_adapter(std::forward<reference>(*Begin));
+ auto Adapter = detail::build_format_adapter(*Begin);
Adapter.format(Stream, ArgStyle);
++Begin;
}
while (Begin != End) {
Stream << Sep;
- auto Adapter =
- detail::build_format_adapter(std::forward<reference>(*Begin));
+ auto Adapter = detail::build_format_adapter(*Begin);
Adapter.format(Stream, ArgStyle);
++Begin;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D94769.317539.patch
Type: text/x-patch
Size: 2901 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210119/d34df8cb/attachment.bin>
More information about the llvm-commits
mailing list