[amarok] /: AudioCdCollection: don't create a reference out of temporary var (crashfix)

Kevin Funk krf at gmx.de
Tue May 8 10:14:53 UTC 2012


On Tuesday 08 May 2012, 09:10, Bart Cerneels wrote:
> The temporary QString returned by url() should remain valid until the
> end of the local scope. At least that is what I think, but it's a
> tricky one. I hope I'm proven wrong by the bug being fixed.
> 
> On Mon, May 7, 2012 at 11:42 PM, Matěj Laitl <matej at laitl.cz> wrote:
> (snip)

This is indeed a tricky one, interesting.

But Matej is right, the url.url() creates a temporary (rvalue) which is 
destroyed right after the end of the expression that uses it (so *not* at the 
end of the local scope).

The interesting thing is that there is no compiler warning about this.
In any case I'd recommend doing the QString::remove() after a new line to make 
this even more clear.

Relevant: http://stackoverflow.com/questions/584824/guaranteed-lifetime-of-
temporary-in-c

Greets

-- 
Kevin Funk


More information about the Amarok-devel mailing list