Thanks!<br><div class="gmail_quote"><div dir="ltr">On Fri, Dec 16, 2016 at 5:42 PM Evgenii Stepanov <<a href="mailto:eugeni.stepanov@gmail.com">eugeni.stepanov@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">fixed in r290029<br class="gmail_msg">
<br class="gmail_msg">
On Fri, Dec 16, 2016 at 5:38 PM, Evgenii Stepanov<br class="gmail_msg">
<<a href="mailto:eugeni.stepanov@gmail.com" class="gmail_msg" target="_blank">eugeni.stepanov@gmail.com</a>> wrote:<br class="gmail_msg">
> /code/llvm/unittests/ADT/TwineTest.cpp:106:38: error: field 'Count'<br class="gmail_msg">
> will be initialized after base 'llvm::FormatAdapter<int>'<br class="gmail_msg">
> [-Werror,-Wreorder]<br class="gmail_msg">
><br class="gmail_msg">
> On Fri, Dec 16, 2016 at 4:38 PM, Zachary Turner via llvm-commits<br class="gmail_msg">
> <<a href="mailto:llvm-commits@lists.llvm.org" class="gmail_msg" target="_blank">llvm-commits@lists.llvm.org</a>> wrote:<br class="gmail_msg">
>> Author: zturner<br class="gmail_msg">
>> Date: Fri Dec 16 18:38:15 2016<br class="gmail_msg">
>> New Revision: 290020<br class="gmail_msg">
>><br class="gmail_msg">
>> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=290020&view=rev" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project?rev=290020&view=rev</a><br class="gmail_msg">
>> Log:<br class="gmail_msg">
>> Add support for formatv to llvm::Twine.<br class="gmail_msg">
>><br class="gmail_msg">
>> Differential Revision: <a href="https://reviews.llvm.org/D27835" rel="noreferrer" class="gmail_msg" target="_blank">https://reviews.llvm.org/D27835</a><br class="gmail_msg">
>><br class="gmail_msg">
>> Modified:<br class="gmail_msg">
>> llvm/trunk/include/llvm/ADT/Twine.h<br class="gmail_msg">
>> llvm/trunk/lib/Support/Twine.cpp<br class="gmail_msg">
>> llvm/trunk/unittests/ADT/TwineTest.cpp<br class="gmail_msg">
>><br class="gmail_msg">
>> Modified: llvm/trunk/include/llvm/ADT/Twine.h<br class="gmail_msg">
>> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/Twine.h?rev=290020&r1=290019&r2=290020&view=diff" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/Twine.h?rev=290020&r1=290019&r2=290020&view=diff</a><br class="gmail_msg">
>> ==============================================================================<br class="gmail_msg">
>> --- llvm/trunk/include/llvm/ADT/Twine.h (original)<br class="gmail_msg">
>> +++ llvm/trunk/include/llvm/ADT/Twine.h Fri Dec 16 18:38:15 2016<br class="gmail_msg">
>> @@ -19,6 +19,7 @@<br class="gmail_msg">
>><br class="gmail_msg">
>> namespace llvm {<br class="gmail_msg">
>><br class="gmail_msg">
>> + class formatv_object_base;<br class="gmail_msg">
>> class raw_ostream;<br class="gmail_msg">
>><br class="gmail_msg">
>> /// Twine - A lightweight data structure for efficiently representing the<br class="gmail_msg">
>> @@ -102,6 +103,9 @@ namespace llvm {<br class="gmail_msg">
>> /// A pointer to a SmallString instance.<br class="gmail_msg">
>> SmallStringKind,<br class="gmail_msg">
>><br class="gmail_msg">
>> + /// A pointer to a formatv_object_base instance.<br class="gmail_msg">
>> + FormatvObjectKind,<br class="gmail_msg">
>> +<br class="gmail_msg">
>> /// A char value, to render as a character.<br class="gmail_msg">
>> CharKind,<br class="gmail_msg">
>><br class="gmail_msg">
>> @@ -137,6 +141,7 @@ namespace llvm {<br class="gmail_msg">
>> const std::string *stdString;<br class="gmail_msg">
>> const StringRef *stringRef;<br class="gmail_msg">
>> const SmallVectorImpl<char> *smallString;<br class="gmail_msg">
>> + const formatv_object_base *formatvObject;<br class="gmail_msg">
>> char character;<br class="gmail_msg">
>> unsigned int decUI;<br class="gmail_msg">
>> int decI;<br class="gmail_msg">
>> @@ -290,6 +295,13 @@ namespace llvm {<br class="gmail_msg">
>> assert(isValid() && "Invalid twine!");<br class="gmail_msg">
>> }<br class="gmail_msg">
>><br class="gmail_msg">
>> + /// Construct from a formatv_object_base.<br class="gmail_msg">
>> + /*implicit*/ Twine(const formatv_object_base &Fmt)<br class="gmail_msg">
>> + : LHSKind(FormatvObjectKind), RHSKind(EmptyKind) {<br class="gmail_msg">
>> + LHS.formatvObject = &Fmt;<br class="gmail_msg">
>> + assert(isValid() && "Invalid twine!");<br class="gmail_msg">
>> + }<br class="gmail_msg">
>> +<br class="gmail_msg">
>> /// Construct from a char.<br class="gmail_msg">
>> explicit Twine(char Val)<br class="gmail_msg">
>> : LHSKind(CharKind), RHSKind(EmptyKind) {<br class="gmail_msg">
>><br class="gmail_msg">
>> Modified: llvm/trunk/lib/Support/Twine.cpp<br class="gmail_msg">
>> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Twine.cpp?rev=290020&r1=290019&r2=290020&view=diff" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Twine.cpp?rev=290020&r1=290019&r2=290020&view=diff</a><br class="gmail_msg">
>> ==============================================================================<br class="gmail_msg">
>> --- llvm/trunk/lib/Support/Twine.cpp (original)<br class="gmail_msg">
>> +++ llvm/trunk/lib/Support/Twine.cpp Fri Dec 16 18:38:15 2016<br class="gmail_msg">
>> @@ -10,6 +10,7 @@<br class="gmail_msg">
>> #include "llvm/ADT/Twine.h"<br class="gmail_msg">
>> #include "llvm/ADT/SmallString.h"<br class="gmail_msg">
>> #include "llvm/Support/Debug.h"<br class="gmail_msg">
>> +#include "llvm/Support/FormatVariadic.h"<br class="gmail_msg">
>> #include "llvm/Support/raw_ostream.h"<br class="gmail_msg">
>> using namespace llvm;<br class="gmail_msg">
>><br class="gmail_msg">
>> @@ -18,6 +19,11 @@ std::string Twine::str() const {<br class="gmail_msg">
>> if (LHSKind == StdStringKind && RHSKind == EmptyKind)<br class="gmail_msg">
>> return *LHS.stdString;<br class="gmail_msg">
>><br class="gmail_msg">
>> + // If we're storing a formatv_object, we can avoid an extra copy by formatting<br class="gmail_msg">
>> + // it immediately and returning the result.<br class="gmail_msg">
>> + if (LHSKind == FormatvObjectKind && RHSKind == EmptyKind)<br class="gmail_msg">
>> + return LHS.formatvObject->str();<br class="gmail_msg">
>> +<br class="gmail_msg">
>> // Otherwise, flatten and copy the contents first.<br class="gmail_msg">
>> SmallString<256> Vec;<br class="gmail_msg">
>> return toStringRef(Vec).str();<br class="gmail_msg">
>> @@ -68,6 +74,9 @@ void Twine::printOneChild(raw_ostream &O<br class="gmail_msg">
>> case Twine::SmallStringKind:<br class="gmail_msg">
>> OS << *Ptr.smallString;<br class="gmail_msg">
>> break;<br class="gmail_msg">
>> + case Twine::FormatvObjectKind:<br class="gmail_msg">
>> + OS << *Ptr.formatvObject;<br class="gmail_msg">
>> + break;<br class="gmail_msg">
>> case Twine::CharKind:<br class="gmail_msg">
>> OS << Ptr.character;<br class="gmail_msg">
>> break;<br class="gmail_msg">
>> @@ -121,6 +130,9 @@ void Twine::printOneChildRepr(raw_ostrea<br class="gmail_msg">
>> case Twine::SmallStringKind:<br class="gmail_msg">
>> OS << "smallstring:\"" << *Ptr.smallString << "\"";<br class="gmail_msg">
>> break;<br class="gmail_msg">
>> + case Twine::FormatvObjectKind:<br class="gmail_msg">
>> + OS << "formatv:\"" << *Ptr.formatvObject << "\"";<br class="gmail_msg">
>> + break;<br class="gmail_msg">
>> case Twine::CharKind:<br class="gmail_msg">
>> OS << "char:\"" << Ptr.character << "\"";<br class="gmail_msg">
>> break;<br class="gmail_msg">
>><br class="gmail_msg">
>> Modified: llvm/trunk/unittests/ADT/TwineTest.cpp<br class="gmail_msg">
>> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ADT/TwineTest.cpp?rev=290020&r1=290019&r2=290020&view=diff" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ADT/TwineTest.cpp?rev=290020&r1=290019&r2=290020&view=diff</a><br class="gmail_msg">
>> ==============================================================================<br class="gmail_msg">
>> --- llvm/trunk/unittests/ADT/TwineTest.cpp (original)<br class="gmail_msg">
>> +++ llvm/trunk/unittests/ADT/TwineTest.cpp Fri Dec 16 18:38:15 2016<br class="gmail_msg">
>> @@ -7,8 +7,10 @@<br class="gmail_msg">
>> //<br class="gmail_msg">
>> //===----------------------------------------------------------------------===//<br class="gmail_msg">
>><br class="gmail_msg">
>> -#include "llvm/ADT/Twine.h"<br class="gmail_msg">
>> #include "llvm/ADT/SmallString.h"<br class="gmail_msg">
>> +#include "llvm/ADT/Twine.h"<br class="gmail_msg">
>> +#include "llvm/Support/FormatAdapters.h"<br class="gmail_msg">
>> +#include "llvm/Support/FormatVariadic.h"<br class="gmail_msg">
>> #include "llvm/Support/raw_ostream.h"<br class="gmail_msg">
>> #include "gtest/gtest.h"<br class="gmail_msg">
>> using namespace llvm;<br class="gmail_msg">
>> @@ -30,6 +32,7 @@ TEST(TwineTest, Construction) {<br class="gmail_msg">
>> EXPECT_EQ("hi", Twine(StringRef(std::string("hi"))).str());<br class="gmail_msg">
>> EXPECT_EQ("hi", Twine(StringRef("hithere", 2)).str());<br class="gmail_msg">
>> EXPECT_EQ("hi", Twine(SmallString<4>("hi")).str());<br class="gmail_msg">
>> + EXPECT_EQ("hi", Twine(formatv("{0}", "hi")).str());<br class="gmail_msg">
>> }<br class="gmail_msg">
>><br class="gmail_msg">
>> TEST(TwineTest, Numbers) {<br class="gmail_msg">
>> @@ -65,6 +68,10 @@ TEST(TwineTest, Concat) {<br class="gmail_msg">
>> repr(Twine().concat(Twine("hi"))));<br class="gmail_msg">
>> EXPECT_EQ("(Twine smallstring:\"hi\" empty)",<br class="gmail_msg">
>> repr(Twine().concat(Twine(SmallString<5>("hi")))));<br class="gmail_msg">
>> + EXPECT_EQ("(Twine formatv:\"howdy\" empty)",<br class="gmail_msg">
>> + repr(Twine(formatv("howdy")).concat(Twine())));<br class="gmail_msg">
>> + EXPECT_EQ("(Twine formatv:\"howdy\" empty)",<br class="gmail_msg">
>> + repr(Twine().concat(Twine(formatv("howdy")))));<br class="gmail_msg">
>> EXPECT_EQ("(Twine smallstring:\"hey\" cstring:\"there\")",<br class="gmail_msg">
>> repr(Twine(SmallString<7>("hey")).concat(Twine("there"))));<br class="gmail_msg">
>><br class="gmail_msg">
>> @@ -89,6 +96,25 @@ TEST(TwineTest, toNullTerminatedStringRe<br class="gmail_msg">
>> EXPECT_EQ(0, *Twine(SmallString<11>("hello"))<br class="gmail_msg">
>> .toNullTerminatedStringRef(storage)<br class="gmail_msg">
>> .end());<br class="gmail_msg">
>> + EXPECT_EQ(0, *Twine(formatv("{0}{1}", "how", "dy"))<br class="gmail_msg">
>> + .toNullTerminatedStringRef(storage)<br class="gmail_msg">
>> + .end());<br class="gmail_msg">
>> +}<br class="gmail_msg">
>> +<br class="gmail_msg">
>> +TEST(TwineTest, LazyEvaluation) {<br class="gmail_msg">
>> + struct formatter : FormatAdapter<int> {<br class="gmail_msg">
>> + explicit formatter(int &Count) : Count(Count), FormatAdapter(0) {}<br class="gmail_msg">
>> + int &Count;<br class="gmail_msg">
>> +<br class="gmail_msg">
>> + void format(raw_ostream &OS, StringRef Style) { ++Count; }<br class="gmail_msg">
>> + };<br class="gmail_msg">
>> +<br class="gmail_msg">
>> + int Count = 0;<br class="gmail_msg">
>> + formatter Formatter(Count);<br class="gmail_msg">
>> + (void)Twine(formatv("{0}", Formatter));<br class="gmail_msg">
>> + EXPECT_EQ(0, Count);<br class="gmail_msg">
>> + (void)Twine(formatv("{0}", Formatter)).str();<br class="gmail_msg">
>> + EXPECT_EQ(1, Count);<br class="gmail_msg">
>> }<br class="gmail_msg">
>><br class="gmail_msg">
>> // I suppose linking in the entire code generator to add a unit test to check<br class="gmail_msg">
>><br class="gmail_msg">
>><br class="gmail_msg">
>> _______________________________________________<br class="gmail_msg">
>> llvm-commits mailing list<br class="gmail_msg">
>> <a href="mailto:llvm-commits@lists.llvm.org" class="gmail_msg" target="_blank">llvm-commits@lists.llvm.org</a><br class="gmail_msg">
>> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" class="gmail_msg" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br class="gmail_msg">
</blockquote></div>