From the documentation for class path
:
Member functions described as returning
const string
are permitted to returnconst string&
So there's no guarantee that string()
actually returns a temporary string. It may be a reference to a string inside the temporary path
returned by extension()
; that will not have its lifetime extended, since it is not directly bound to a local reference.