on-internet
← Community

Is dereferencing a null pointer undefined behavior in C++23?

Stack Overflow ·

"Everyone knows" that dereferencing a null pointer is undefined behavior in all versions of C and C++. However, I couldn't find any clause in the C++23 standard that says so. Where and how is it specified? For reference, C++23 specifies the unary * operator as follows: The unary * operator performs indirection. Its operand shall be a prvalue of type “pointer to T”, where T is an object or function type. The operator yields an lvalue of type T denoting the object or function to which the operand points. [Note 1 : Indirection through a pointer to an incomplete type (other than cv void) is valid.

Comments

Sign in or sign up to comment and upvote.

No comments yet.