[clang] [Clang] Diagnose forming references to nullptr (PR #143667)
Shafik Yaghmour via cfe-commits
cfe-commits at lists.llvm.org
Wed Jun 11 18:57:28 PDT 2025
================
@@ -1321,3 +1321,24 @@ constexpr bool check = different_in_loop();
// expected-error at -1 {{}} expected-note at -1 {{in call}}
}
+
+namespace GH48665 {
+constexpr bool foo(int *i) {
----------------
shafik wrote:
Other tests: https://godbolt.org/z/o66Gr3fc8
```cpp
struct A {
int &r;
};
struct B {
constexpr B(int *p) : r{*p} {
}
int &r;
};
constexpr bool f(int *i) {
int *p = new int;
delete p;
int &r = *p;
A a{*i};
B b(i);
return true;
}
static_assert(f(nullptr), "");
```
https://github.com/llvm/llvm-project/pull/143667
More information about the cfe-commits
mailing list