Yes, s2 is legal. s2 is tied to a temporary std :: string - an extension of the temporary lifetime. s1 is not temporary, it is a named variable.
See 12.2 / 5:
The second context is when the link is tied to a temporary one. Temporary to which the link is attached, or temporary, which is the full object to the subobject, is temporary associated with preserving the lifetime of the link, except as indicated below.
source share