================
@@ -41,3 +41,34 @@ int testRefToNullPtr2() {
   return *p2;         //expected-warning {{Dereference of null pointer}}
                       // expected-note@-1{{Dereference of null pointer}}
 }
+
+void testMemberNullPointerDeref() {
+  struct Wrapper {char c; int *ptr; };  
+  Wrapper w = {'a', nullptr};           // expected-note {{'w.ptr' initialized 
to a null pointer value}}
+  *w.ptr = 1;                           //expected-warning {{Dereference of 
null pointer}}
+                                        // expected-note@-1{{Dereference of 
null pointer}}
+}
+
+void testMemberNullReferenceDeref() {
+  struct Wrapper {char c; int &ref; };
+  Wrapper w = {.c = 'a', .ref = *(int *)0 }; // expected-note {{'w.ref' 
initialized to a null pointer value}}
+                                             // expected-warning@-1 {{binding 
dereferenced null pointer to reference has undefined behavior}}
+  w.ref = 1;                                 //expected-warning {{Dereference 
of null pointer}}
+                                             // expected-note@-1{{Dereference 
of null pointer}}
+}
+
+void testReferenceToPointerWithNullptr() {
+  int *i = nullptr;                   // expected-note {{'i' initialized to a 
null pointer value}}
+  struct Wrapper {char c; int *&a;};
+  Wrapper w {'c', i};                 // expected-note{{'w.a' initialized 
here}}
+  *(w.a) = 25;                        // expected-warning {{Dereference of 
null pointer}}
+                                      // expected-note@-1 {{Dereference of 
null pointer}}
+}
+
+void aaa() {
----------------
DonatNagyE wrote:

```suggestion
void testNullReferenceToPointer() {
```

https://github.com/llvm/llvm-project/pull/68691
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to