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

Vlad Serebrennikov via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 2 07:05:43 PDT 2025


================
@@ -107,6 +107,8 @@ void f() {
   constexpr int p = &*a;
   // since-cxx11-error at -1 {{cannot initialize a variable of type 'const int' with an rvalue of type 'A *'}}
   constexpr A *p2 = &*a;
+  // since-cxx11-error at -1 {{constexpr variable 'p2' must be initialized by a constant expression}} \
+  // since-cxx11-note at -1 {{read of dereferenced null pointer is not allowed in a constant expression}}
----------------
Endilll wrote:

```suggestion
  //   since-cxx11-note at -2 {{read of dereferenced null pointer is not allowed in a constant expression}}
```
As a consequence, you need to remove the backslash on the previous line.

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


More information about the cfe-commits mailing list