https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71091
Bug ID: 71091 Summary: constexpr reference bound to a null pointer dereference accepted Product: gcc Version: 7.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: msebor at gcc dot gnu.org Target Milestone: --- All released versions of GCC fail to reject definitions of constexpr variables initialized by dereferencing a null pointer, creating a dangling reference. The initialization is invalid and should be rejected. $ cat xx.cpp && /build/gcc-trunk-svn/gcc/xgcc -B /build/gcc-trunk-svn/gcc -S -Wall -Wextra -Wpedantic -o/dev/null xx.cpp constexpr int *p = 0; constexpr int &r = *p; static_assert (&r != 0, ""); xx.cpp:3:19: warning: the compiler can assume that the address of ‘r’ will never be NULL [-Waddress] static_assert (&r != 0, ""); ~~~^~~~ xx.cpp:3:1: error: static assertion failed static_assert (&r != 0, ""); ^~~~~~~~~~~~~