From 8ca99100ba26d534a0cda05028afb41b0ed49647 Mon Sep 17 00:00:00 2001 From: Sam McCall Date: Fri, 6 Jul 2018 05:45:45 +0000 Subject: [Support] Make support types more easily printable. Summary: Error's new operator<< is the first way to print an error without consuming it. formatv() can now print objects with an operator<< that works with raw_ostream. Reviewers: bkramer Subscribers: mgorny, llvm-commits Differential Revision: https://reviews.llvm.org/D48966 llvm-svn: 336412 --- llvm/unittests/Support/FormatVariadicTest.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'llvm/unittests/Support/FormatVariadicTest.cpp') diff --git a/llvm/unittests/Support/FormatVariadicTest.cpp b/llvm/unittests/Support/FormatVariadicTest.cpp index 54373da51c4..6d621464c0e 100644 --- a/llvm/unittests/Support/FormatVariadicTest.cpp +++ b/llvm/unittests/Support/FormatVariadicTest.cpp @@ -671,3 +671,12 @@ TEST(FormatVariadicTest, CopiesAndMoves) { EXPECT_EQ(0, R.Copied); EXPECT_EQ(0, R.Moved); } + +namespace adl { +struct X {}; +raw_ostream &operator<<(raw_ostream &OS, const X &) { return OS << "X"; } +} // namespace adl +TEST(FormatVariadicTest, FormatStreamable) { + adl::X X; + EXPECT_EQ("X", formatv("{0}", X).str()); +} -- cgit v1.2.3