https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109470
Xi Ruoyao <xry111 at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |xry111 at gcc dot gnu.org
Resolution|--- |INVALID
Status|UNCONFIRMED |RESOLVED
--- Comment #1 from Xi Ruoyao <xry111 at gcc dot gnu.org> ---
The standard says:
A temporary object bound to a reference parameter in a function call persists
until the completion of the full-expression containing the call.
So at the "assert" line the lifetime of the temporary object created by the
prvalue to glvalue materialization of (int)lenght has already ended. Any
reference to the temporary is dangling and it's undefined behavior to use such
a reference.