https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109470
--- Comment #2 from Xi Ruoyao <xry111 at gcc dot gnu.org> ---
With "-Wall -O1" this is diagnosed properly, but with a spurious
maybe-uninitialized warning:
In file included from /usr/include/c++/12.2.0/cassert:44,
from t.c:2:
t.c: In function 'int main()':
t.c:17:11: warning: dangling pointer 'dst' to an unnamed temporary may be used
[-Wdangling-pointer=]
17 | assert(dst <= MAX);
| ^~~
t.c:16:24: note: unnamed temporary defined here
16 | const int& dst = Min(MAX, (int)lenght);
| ~~~^~~~~~~~~~~~~~~~~~
t.c:16:24: warning: '<anonymous>' may be used uninitialized
[-Wmaybe-uninitialized]
With "-Wall -O2" only the spurious maybe-uninitialized warning is emitted,
which is not very helpful.
With "-Wall -O0" no warning at all (diagnosing this issue at least needs some
IPA).