<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/75716>75716</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            dereferencing a null pointer in a constant expression
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          twoscomplement
      </td>
    </tr>
</table>

<pre>
    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

clang-17.0.1 produces errors and warning, by default.

By default, gcc-13.2 compiles without warning. -Wall yields a -Wnonnull warning.

msvc 19.38 compiles without warning.

Potentially relevant context:
[Accessing static data members via null pointer](https://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#2748)
[Implicit undefined behavior when dereferencing pointers](https://cplusplus.github.io/CWG/issues/2823.html)

I have submitted the same question for gcc: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113047
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyMVMGO4ygQ_RpyKcWycRx3Dj4knfVqLquVdqQ-jjBUbEYYPFDE0_31K5xkOmn1rFYiRMZFvcd7z4gQdG8RG1YdWHVciUiD8w3NLkg3TgZHtLTqnHpt_hlcNAo0QYcwuRB0ZxDIgUKPJ_RoJYIAG42ByWlL6EFbEPDM-IHxA89BOhtIWAL8OXkMQTvLypblR5bvL_Ozs0Er9ECDDiDvdipk5f6-lG3z61geA_koCb4Cqw-XFbjgJSzonDOgw1_RGMafGN_dlwF4pOgtMF4kXFbeXrH6eAWrj79WAwnS8psIAT0t3dL4yvie8V06_kSe8d2alX_cI6Zxa3GZ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