<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On 15 May 2018 at 16:01, John McCall via cfe-dev <span dir="ltr"><<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word;line-break:after-white-space"><div><span class=""><blockquote type="cite"><div>On May 15, 2018, at 6:05 PM, George Karpenkov via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>> wrote:</div><br class="m_-1182803303795108697Apple-interchange-newline"><div><div style="word-wrap:break-word;line-break:after-white-space">+cfe-dev<div><br></div><div>Hi Andrea,</div><div><br></div><div>I think you might get more luck asking on the cfe-dev mailing list.</div></div></div></blockquote><blockquote type="cite"><div><div style="word-wrap:break-word;line-break:after-white-space"><div><br></div><div>George</div><div><div><br><blockquote type="cite"><div>On May 15, 2018, at 1:15 PM, Andrea Arteaga via cfe-users <<a href="mailto:cfe-users@lists.llvm.org" target="_blank">cfe-users@lists.llvm.org</a>> wrote:</div><br class="m_-1182803303795108697Apple-interchange-newline"><div><div dir="ltr">Dear all,<br><div class="gmail_quote"><div dir="ltr"><div>Recently, my team suffered from a bug due to a double bad usage of C++.<br><br></div><div>We have a function returning a reference to an object:<br><br></div><div> Object& GetObject();<br><br></div><div>Sometimes we use this function like this:<br><br></div><div> auto obj = GetObject();<br><br></div><div>This triggers a copy of the object, which we really don't mean. The two problems are:<br></div><div>1. Object does not delete the copy constructor, nor does it declare one. We have a policy of never using implicitly-declared constructors, we either use `=delete` or `=default`. Nevertheless we missed this class.<br></div></div></div></div></div></blockquote></div></div></div></div></blockquote><div><br></div></span>Implicitly-defined copy constructors are ubiquitous in idiomatic C++. Maybe that's not true in your project, but still, this seems too special-case for the compiler. Maybe a linter that has a more sophisticated model of what code is yours vs. the standard library.</div><span class=""><div><br><blockquote type="cite"><div><div style="word-wrap:break-word;line-break:after-white-space"><div><div><blockquote type="cite"><div><div dir="ltr"><div class="gmail_quote"><div dir="ltr"><div>2. A reference is demoted to a rvalue due to the usage of `auto` instead of `auto&`.<br></div></div></div></div></div></blockquote></div></div></div></div></blockquote><div><br></div></div></span>This is a more reasonable thing to try to warn about. I have two concerns:<div> - I don't know a reasonable way to suppress the warning if you really do want to load from the l-value.</div><div><div><div> - I have a non-specific worry that it'll disrupt some important idiom that I'm just not thinking of.</div></div></div></div></blockquote><div><br></div><div>How about:</div><div><br></div><div> vector<some_complex_type> v = get_vector();</div><div> auto x = v.front();</div><div><br></div><div>or, worse:</div><div><br></div><div> auto y = get_vector().front();</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word;line-break:after-white-space"><div><div>But those are concerns that we could explore during iterative design and implementation.</div><div><div><br></div><div>John.</div></div></div></div><br>______________________________<wbr>_________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/cfe-dev</a><br>
<br></blockquote></div><br></div></div>