<html><head><meta http-equiv="Content-Type" content="text/html; charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div><blockquote type="cite" class=""><div class="">On May 15, 2018, at 7:23 PM, Richard Smith <<a href="mailto:richard@metafoo.co.uk" class="">richard@metafoo.co.uk</a>> wrote:</div><div class=""><div dir="ltr" class=""><div class="gmail_extra"><div class="gmail_quote">On 15 May 2018 at 16:01, John McCall via cfe-dev <span dir="ltr" class=""><<a href="mailto:cfe-dev@lists.llvm.org" target="_blank" class="">cfe-dev@lists.llvm.org</a>></span> wrote:<br class=""><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" class=""><div class=""><span class=""><blockquote type="cite" class=""><div class="">On May 15, 2018, at 6:05 PM, George Karpenkov via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org" target="_blank" class="">cfe-dev@lists.llvm.org</a>> wrote:</div><br class="m_-1182803303795108697Apple-interchange-newline"><div class=""><div style="word-wrap:break-word;line-break:after-white-space" class="">+cfe-dev<div class=""><br class=""></div><div class="">Hi Andrea,</div><div class=""><br class=""></div><div class="">I think you might get more luck asking on the cfe-dev mailing list.</div></div></div></blockquote><blockquote type="cite" class=""><div class=""><div style="word-wrap:break-word;line-break:after-white-space" class=""><div class=""><br class=""></div><div class="">George</div><div class=""><div class=""><br class=""><blockquote type="cite" class=""><div class="">On May 15, 2018, at 1:15 PM, Andrea Arteaga via cfe-users <<a href="mailto:cfe-users@lists.llvm.org" target="_blank" class="">cfe-users@lists.llvm.org</a>> wrote:</div><br class="m_-1182803303795108697Apple-interchange-newline"><div class=""><div dir="ltr" class="">Dear all,<br class=""><div class="gmail_quote"><div dir="ltr" class=""><div class="">Recently, my team suffered from a bug due to a double bad usage of C++.<br class=""><br class=""></div><div class="">We have a function returning a reference to an object:<br class=""><br class=""></div><div class=""> Object& GetObject();<br class=""><br class=""></div><div class="">Sometimes we use this function like this:<br class=""><br class=""></div><div class=""> auto obj = GetObject();<br class=""><br class=""></div><div class="">This triggers a copy of the object, which we really don't mean. The two problems are:<br class=""></div><div class="">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 class=""></div></div></div></div></div></blockquote></div></div></div></div></blockquote><div class=""><br class=""></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 class=""><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap:break-word;line-break:after-white-space" class=""><div class=""><div class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="gmail_quote"><div dir="ltr" class=""><div class="">2. A reference is demoted to a rvalue due to the usage of `auto` instead of `auto&`.<br class=""></div></div></div></div></div></blockquote></div></div></div></div></blockquote><div class=""><br class=""></div></div></span>This is a more reasonable thing to try to warn about. I have two concerns:<div class=""> - I don't know a reasonable way to suppress the warning if you really do want to load from the l-value.</div><div class=""><div class=""><div class=""> - 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 class=""><br class=""></div><div class="">How about:</div><div class=""><br class=""></div><div class=""> vector<some_complex_type> v = get_vector();</div><div class=""> auto x = v.front();</div><div class=""><br class=""></div><div class="">or, worse:</div><div class=""><br class=""></div><div class=""> auto y = get_vector().front();</div></div></div></div></div></blockquote><div><br class=""></div>Yep, good example.</div><div><br class=""></div><div>John.</div></body></html>