https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113047
Bug ID: 113047 Summary: dereferencing a null pointer in a constant expression Product: gcc Version: 13.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: gcc_bz at brnz dot org Target Milestone: --- Should it be possible to dereference a null pointer in a C++20 constant expression? Consider this c++20 code: struct T { constexpr bool isNull() { return !this; } }; static_assert(((T*)nullptr)->isNull()); constexpr T* t = nullptr; static_assert((*t).isNull()); I would expect this to not compile due to the dereferencing of a null pointer in a constant expression. With reference to https://godbolt.org/z/q53rz5d69 By default, gcc-13.2 compiles without warning. -Wall yields a -Wnonnull warning. clang-17.0.1 produces errors and warning, by default. msvc 19.38 compiles without warning. Potentially relevant context: 2748. Accessing static data members via null pointer https://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#2748 2823. Implicit undefined behavior when dereferencing pointers https://cplusplus.github.io/CWG/issues/2823.html