<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=koi8-r">
<style type="text/css" style="display:none"><!-- p { margin-top: 0px; margin-bottom: 0px; }--></style>
</head>
<body dir="ltr" style="font-size:12pt;color:#000000;background-color:#FFFFFF;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, https://godbolt.org/z/nY95nh)<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><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>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>
<p><br>
</p>
<p><br>
</p>
<div id="Signature">
<div name="divtagdefaultwrapper" style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:; margin:0">
<div class="BodyFragment"><font size="2">
<div class="PlainText">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 tabindex="-1" style="display:inline-block; width:98%">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>От:</b> Alexander Shaposhnikov <alexander.v.shaposhnikov@gmail.com><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; avl.lapshin@gmail.com<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:#ffffff; font-size:10pt; border:1px dotted #003333; padding:.8em">
<span style="color:#ff6600">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 ReportSpam@accesssoftek.com</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">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>
</body>
</html>