<table><tr><td style="">kossebau added inline comments.
</td><a style="text-decoration: none; padding: 4px 8px; margin: 0 8px 8px; float: right; color: #464C5C; font-weight: bold; border-radius: 3px; background-color: #F7F7F9; background-image: linear-gradient(to bottom,#fff,#f1f0f1); display: inline-block; border: 1px solid rgba(71,87,120,.2);" href="https://phabricator.kde.org/D25039">View Revision</a></tr></table><br /><div><strong>INLINE COMMENTS</strong><div><div style="margin: 6px 0 12px 0;"><div style="border: 1px solid #C7CCD9; border-radius: 3px;"><div style="padding: 0; background: #F7F7F7; border-color: #e3e4e8; border-style: solid; border-width: 0 0 1px 0; margin: 0;"><div style="color: #74777d; background: #eff2f4; padding: 6px 8px; overflow: hidden;"><a style="float: right; text-decoration: none;" href="https://phabricator.kde.org/D25039#inline-141643">View Inline</a><span style="color: #4b4d51; font-weight: bold;">ahmadsamir</span> wrote in <span style="color: #4b4d51; font-weight: bold;">ftp.cpp:1376</span></div>
<div style="margin: 8px 0; padding: 0 12px; color: #74777D;"><p style="padding: 0; margin: 8px;">IIUC, the compiler will use a temporary object to hold the return of tempurl.fileName().</p>

<p style="padding: 0; margin: 8px;">The temporary is used to initialize filename, and then it's gone:<br />
const QString filename = tempurl.filename();</p>

<p style="padding: 0; margin: 8px;">filename here is a reference-to-const to the temporary object and the temporary will have the same lifetime as the reference (for objects on the stack), so until the end of the scope:<br />
const QString &filename = tempurl.fileName();<br />
c.f. <a href="https://herbsutter.com/2008/01/01/gotw-88-a-candidate-for-the-most-important-const/" class="remarkup-link" target="_blank" rel="noreferrer">https://herbsutter.com/2008/01/01/gotw-88-a-candidate-for-the-most-important-const/</a></p>

<p style="padding: 0; margin: 8px;">In my mind it kind of makes more sense to use a reference-to-const when the rvalue (tempurl.fileName()) is not a temporary object, because I am saving nothing by using a reference here since the compiler will create the temporary object and hold it until the end of the scope anyway.</p>

<p style="padding: 0; margin: 8px;">In this particular case, it's probably exactly the same whether the temporary is used to initialize a const non-reference object and then (the temporary) is dropped/gone or the object being initialized is a reference to const to the temporary until the end of the scope...</p>

<p style="padding: 0; margin: 8px;">job->statResult() and job->url() are different because both of them return a reference to const.</p></div></div>
<div style="margin: 8px 0; padding: 0 12px;"><p style="padding: 0; margin: 8px;">Thanks for the reference :) to some docs about it. So my memory about this being a chance to limit scope of lifetime of that temporary object was wrong then, so it's simply the same scope as the reference variable, not limited to the last line where the variable is actually used, did I get it right from reading that? (perhaps was some limit in some compiler, it's a decade ago that I was hinted to that, by accident remember the occasion, but less the content :) ).<br />
If so, for the rest, seems we align in not using a const ref for the variable type, instead just making it the official variable holding the object/value, not just a reference. No gain with a const reference, and just confusing by being non-standard code.</p></div></div></div></div></div><br /><div><strong>REPOSITORY</strong><div><div>R241 KIO</div></div></div><br /><div><strong>REVISION DETAIL</strong><div><a href="https://phabricator.kde.org/D25039">https://phabricator.kde.org/D25039</a></div></div><br /><div><strong>To: </strong>meven, Frameworks, dfaure<br /><strong>Cc: </strong>ahmadsamir, anthonyfieroni, kossebau, kde-frameworks-devel, LeGast00n, GB_2, michaelh, ngraham, bruns<br /></div>