Yes, it is not safe.
The return address of a local variable or temporary dereferencing results in Undefined Behavior.
How did you comment:
Yes, the lifetime of a time reference to a permalink extends to the lifetime of a constant. But this requires the caller to call the return value in a constant reference, so the function itself will not be safe.
From the C ++ standard:
C ++ 03 12.2 Temporary objects :
The second context is when the binding is tied to a temporary one. Temporary, to which the link is attached, or temporary, which is the complete object for the subobject, with which the temporary is attached , is stored for the life of the link , except as noted below ...
The temporary binding to the reference element in the ctor-initializer constructor (12.6.2) is maintained until the constructor exits. Temporal reference to the link parameter in the function call (5.2.2) is stored until the completion of the full expression containing the call. The temporary binding to the return value in the return statement of the function (6.6.3) is maintained until the function exits
source share