https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102603
Bug ID: 102603 Summary: Compile-time evaluation of indirection via dangling pointer is not rejected Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: fchelnokov at gmail dot com Target Milestone: --- The program as follows is ill-formed: ``` constexpr bool g() { int * p = nullptr; { int c = 0; p = &c; } return *p == 0; //indirection via dangling pointer }; int main() { static_assert( g() ); } ``` but GCC erroneously accepts it, demo: https://gcc.godbolt.org/z/8xE7csGKo The compiler must fail the program, see stackoverflow explanation: https://stackoverflow.com/a/69446660/7325599