Issue 75716
Summary dereferencing a null pointer in a constant _expression_
Labels new issue
Assignees
Reporter twoscomplement
    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
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to