<div dir="ltr"><div><div>Thanks for your reply, John.<br><br></div>I fully understand your points, I actually had the same concern that a reference-to-rvalue warning would be issued for perfectly reasonable and intended code. It's still one of those warnings I would like to see when writing code in an IDE, not when compiling the full project (we would setup builds with different warning options for these two cases).<br><br></div><div>For the default constructor warning, I did not mean to be warned when a default copy constructor exists, just when one is used.<br><br></div><div>In any case, it does not seem like clang currently implements warnings like those, right?<br><br></div><div>Thank you.<br></div><div>Andrea<br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, May 16, 2018 at 1:55 AM, John McCall <span dir="ltr"><<a href="mailto:rjmccall@apple.com" target="_blank">rjmccall@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="overflow-wrap: break-word;"><div><div><div class="gmail-h5"><blockquote type="cite"><div>On May 15, 2018, at 7:23 PM, Richard Smith <<a href="mailto:richard@metafoo.co.uk" target="_blank">richard@metafoo.co.uk</a>> wrote:</div><div><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:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="overflow-wrap: break-word;"><div><span><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="gmail-m_5496477439218302464m_-1182803303795108697Apple-interchange-newline"><div><div style="overflow-wrap: break-word;">+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="overflow-wrap: break-word;"><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="gmail-m_5496477439218302464m_-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><div><br><blockquote type="cite"><div><div style="overflow-wrap: break-word;"><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></div></div></div></blockquote><div><br></div></div></div>Yep, good example.</div><span class="gmail-HOEnZb"><font color="#888888"><div><br></div><div>John.</div></font></span></div></blockquote></div><br></div>