https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77875
--- Comment #3 from Lénárd Szolnoki <leni536 at gmail dot com> --- A more worrisome example presumably for this same bug, it's a miscompilation: template <typename T> decltype(auto) as_const(T& t) { using const_ref = const T&; return const_ref{t}; } int main() { int i = 42; return as_const(i); } $ g++ -std=c++17 -O0 -fsanitize=undefined -Wall -pedantic main.cpp && ./a.out main.cpp: In instantiation of 'decltype(auto) as_const(T&) [with T = int]': main.cpp:9:22: required from here main.cpp:4:23: warning: returning reference to temporary [-Wreturn-local-addr] return const_ref{t}; ^ main.cpp:4:23: runtime error: reference binding to null pointer of type 'const int' main.cpp:9:22: runtime error: load of null pointer of type 'const int' bash: line 7: 802 Segmentation fault (core dumped) ./a.out An UB is added where should be none.