<div dir="ltr"><div dir="ltr"><div dir="ltr">I believe StringRef + const char* is overloaded at the bottom of Twine.h. And without those overloads it might try to implicitly convert both StringRef and const char* to Twine and then add them since StringRef + const char * wouldn't otherwise be defined.<div><br></div><div><div>  inline Twine operator+(const Twine &LHS, const Twine &RHS) {</div><div>    return LHS.concat(RHS);</div><div>  }</div></div><div><br></div><div>  /// Additional overload to guarantee simplified codegen; this is equivalent to<br></div><div><div>  /// concat().</div><div><br></div><div>  inline Twine operator+(const char *LHS, const StringRef &RHS) {</div><div>    return Twine(LHS, RHS);</div><div>  }</div><div><br></div><div>  /// Additional overload to guarantee simplified codegen; this is equivalent to</div><div>  /// concat().</div><div><br></div><div>  inline Twine operator+(const StringRef &LHS, const char *RHS) {</div><div>    return Twine(LHS, RHS);</div><div>  }</div></div><div><br></div><div><br></div><div><br clear="all"><div><div dir="ltr" class="gmail_signature">~Craig</div></div><br></div></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Apr 29, 2019 at 3:18 PM Russell Wallace via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><div dir="ltr">I'm looking at the documentation on Twine at <a href="http://llvm.org/docs/ProgrammersManual.html#llvm-adt-twine-h" target="_blank">http://llvm.org/docs/ProgrammersManual.html#llvm-adt-twine-h</a> and it gives example code:</div><div dir="ltr"><br></div><div dir="ltr"><div dir="ltr">void foo(const Twine &T);</div><div dir="ltr">...</div><div dir="ltr">StringRef X = ...</div><div dir="ltr">unsigned i = ...</div><div dir="ltr">foo(X + "." + Twine(i));</div><div><br></div><div>How exactly does that last line work? Since addition is left associative, I would expect it to be parsed as (X + ".") ... so it's trying to add a StringRef and a const char* before Twine can come into the picture at all?<br></div><div><br></div></div></div></div>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div>