[libcxx-commits] [clang] [libcxx] [Clang] Diagnose forming references to nullptr (PR #143667)

Corentin Jabot via libcxx-commits libcxx-commits at lists.llvm.org
Thu Jul 10 05:48:20 PDT 2025


================
@@ -265,7 +265,7 @@ namespace const_modify {
 
 namespace null {
   constexpr int test(int *p) {
-    return *p = 123; // expected-note {{assignment to dereferenced null pointer}}
+    return *p = 123; // expected-note {{read of dereferenced null pointer}}
----------------
cor3ntin wrote:

> Is there a reason we can't say assignment to like we did before? 

Yes, because we diagnose earlier, and trying to postpone the diagnostic would be messy, if at all possible

```cpp
*p = 123; // invalid
*p // also invalid
```

I changed to "dereferencing a null pointer is not allowed in a constant expression" which works everywhere

https://github.com/llvm/llvm-project/pull/143667


More information about the libcxx-commits mailing list