复合文字并通过GCC在C ++中通过引用传递?

compound literal and pass by reference in C++ with GCC?

In C++, a compound literal designates a temporary object, which only lives until the end of its full-expression. As a result, well-defined C code that takes the address of a subobject of a compound literal can be undefined in C++. https://gcc.gnu.org/onlinedocs/gcc/Compound-Literals.html

这也适用于传递引用吗?

是的。未定义的行为来自于在对象销毁后尝试访问该对象,无论是通过悬空指针还是悬空引用完成的。