<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Oct 1, 2020 at 2:08 AM George Rimar <<a href="mailto:grimar@accesssoftek.com">grimar@accesssoftek.com</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" style="font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255);font-family:Calibri,Arial,Helvetica,sans-serif">
<p>FWIW, <span style="font-size:12pt">I've performed an experiment with the code below at godbolt.</span></p>
<div>(used -O2, <a href="https://godbolt.org/z/nY95nh" target="_blank">https://godbolt.org/z/nY95nh</a>)<br>
</div>
<div><br>
</div>
<div>```</div>
<div>#include <vector></div>
<div>#include "llvm/Support/Error.h"</div>
<div><br>
</div>
<div>llvm::Expected<std::vector<int>> foo() {</div>
<div> std::vector<int> V;</div>
<div> V.push_back(0);</div>
<div> return V;</div>
<div>}</div>
<div>```<br></div></div></blockquote><div><br>I think the easiest and portable way to test this functionality would be more like:<br><br>#include <memory><br>struct base { virtual ~base(); };<br>struct derived : base { };<br>std::unique_ptr<base> f() {<br> std::unique_ptr<derived> d;<br> return d;<br>}<br><br>That shows whether the compiler's treating the return of a temporary as movable, even when the types aren't an exact match.<br><br>Clang 3.5 does not support this conversion: <a href="https://godbolt.org/z/5nsWM8">https://godbolt.org/z/5nsWM8</a><br>GCC 5.1 does support it: <a href="https://godbolt.org/z/cvd3d6">https://godbolt.org/z/cvd3d6</a><br>& I'm not sure which MSVC version on godbolt would be "MSVC 2017" that the LLVM docs refer to.<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" style="font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255);font-family:Calibri,Arial,Helvetica,sans-serif"><div>
</div>
<div><br>
</div>
<div>If I understand the produced output correctly, then results are:</div>
<div><br>
</div>
<div>gcc 7.5: creates a copy.</div>
<div>gcc 8.1: uses move.</div>
<div><br>
</div>
<div>clang < 6.0: doesn't compile.</div></div></blockquote><div><br>That's interesting - I wonder if LLVM's documentation is out of date, which claims the minimum required Clang is 3.5: <a href="https://llvm.org/docs/GettingStarted.html#host-c-toolchain-both-compiler-and-standard-library">https://llvm.org/docs/GettingStarted.html#host-c-toolchain-both-compiler-and-standard-library</a><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" style="font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255);font-family:Calibri,Arial,Helvetica,sans-serif">
<div>clang >= 6.0: uses move.</div>
<div><br>
</div>
<div>MSVS: was unable to compile, complains about "llvm/Support/Error.h" header.</div>
<div>I am using MSVS 2017 locally and it calls move constructor of Expected<> though,</div>
<div>so I think all MSVS >= 2017 (at least) should be fine.<br></div></div></blockquote><div><br></div><div>May be something to do with which compiler the llvm library provided by godbolt is compiled with? which might make the above results not quite right (& why testing with the non-llvm-specific example might be clearer)<br><br>Looks like we would need to bump the minimum Clang up from 3.5 to at least 3.9 to allow returns with implicit moves that include conversions.<br>- Dave <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" style="font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255);font-family:Calibri,Arial,Helvetica,sans-serif"><div>
</div>
<p><br>
</p>
<p><br>
</p>
<div id="gmail-m_7504072726545848816Signature">
<div name="divtagdefaultwrapper">
<div><font size="2">
<div>Best regards,<br>
George | Developer | <span style="background-color:rgb(255,255,255);color:rgb(33,33,33);font-family:Calibri,sans-serif;font-size:13.3333px">Access Softek, Inc</span></div>
</font></div>
</div>
</div>
<div style="color:rgb(33,33,33)">
<hr style="display:inline-block;width:98%">
<div id="gmail-m_7504072726545848816divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>От:</b> Alexander Shaposhnikov <<a href="mailto:alexander.v.shaposhnikov@gmail.com" target="_blank">alexander.v.shaposhnikov@gmail.com</a>><br>
<b>Отправлено:</b> 28 сентября 2020 г. 22:46<br>
<b>Кому:</b> David Blaikie<br>
<b>Копия:</b> Richard Smith; llvm-dev; Lang Hames; George Rimar; James Henderson; <a href="mailto:avl.lapshin@gmail.com" target="_blank">avl.lapshin@gmail.com</a><br>
<b>Тема:</b> [EXTERNAL] Re: [llvm-dev] preferred way to return expected values</font>
<div> </div>
</div>
<div>
<div style="font-size:9pt;font-family:Calibri,sans-serif">
<h3 style="background-color:rgb(255,255,255);font-size:10pt;border:1px dotted rgb(0,51,51);padding:0.8em">
<span style="color:rgb(255,102,0)">CAUTION:<strong> </strong></span>This email originated from outside of the organization. Do not click links or open attachments unless you recognize the sender and know the content is safe. If you suspect potential phishing or spam
email, report it to <a href="mailto:ReportSpam@accesssoftek.com" target="_blank">ReportSpam@accesssoftek.com</a></h3>
</div>
<div>
<div dir="ltr">Many thanks for the reply,
<div>right, this is what the discussion is about.</div>
<div><br>
</div>
</div>
<br>
<div class="gmail_quote">
<div dir="ltr" class="gmail_attr">On Mon, Sep 28, 2020 at 10:57 AM David Blaikie <<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</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">To clarify, this is a discussion around whether given some move-only type X, implicitly convertible to Y and the code "Y func() { X x; return x; }" is that valid in LLVM? (and, as a corollary, if the type isn't move-only, is that code efficient
(does it move rather than copying) - as in the vector example given)<br>
<br>
I /believe/ the answer is that it is not valid. I think the set of compilers supported includes those that do not implement this rule. (either due to the language version we compile with, or due to it being a DR that some supported compiler versions do not
implement). But that's just my rough guess.</div>
<br>
<div class="gmail_quote">
<div dir="ltr" class="gmail_attr">On Sat, Sep 26, 2020 at 3:17 PM Alexander Shaposhnikov via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">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">Hello everyone!
<div>
<div>
<div>It looks like in the LLVM codebase (including subprojects) there are some inconsistencies <br>
<div>in how values are returned from functions with the following (or similar) signature:</div>
<div> Expected<std::vector<int>> createVector() {</div>
<div> std::vector<int> V;</div>
<div> ... </div>
<div> }</div>
<div>It would be interesting to find out your opinion on this.</div>
<div>After some investigation I have found <a href="https://reviews.llvm.org/D70963" target="_blank">https://reviews.llvm.org/D70963</a> and
<a href="https://reviews.llvm.org/D43322" target="_blank">https://reviews.llvm.org/D43322</a> which have some additional context regarding </div>
</div>
<div>the problem. The aforementioned diffs (and the comments on them) contain a lot of</div>
</div>
</div>
<div>details and the history of the problem (whether one should use the cast or not).</div>
<div>If I am not mistaken a part of the problem is that compilers' behaviors have changed over time, and e.g. the latest versions would use a move constructor while the older ones could use a copy constructor. So the question is where we stand at the moment
/ what is the recommended approach for the new code.</div>
<div><br>
</div>
<div>Many thanks in advance,</div>
<div>Alexander Shaposhnikov</div>
<div><br>
</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>
</blockquote>
</div>
</div>
</div>
</div>
</div>
</blockquote></div></div>