88f387e17c917d274e6bc0dabef63b2e3e53a382
[gcc.git] / gcc / testsuite / g++.dg / ubsan / null-2.C
1 // Limit this to known non-strict alignment targets.
2 // { dg-do run { target { i?86-*-linux* x86_64-*-linux* } } }
3 // { dg-options "-fsanitize=null -Wall -Wno-unused-variable -std=c++11" }
4
5 #include <new>
6
7 struct U
8 {
9 int a;
10 void foo () {}
11 };
12 struct V
13 {
14 V () {};
15 ~V () {};
16 int a;
17 void foo () {}
18 static void bar () {}
19 };
20 struct S { long int l; char buf[1 + sizeof (U) + 2 * sizeof (V)]; } s;
21
22 int
23 main (void)
24 {
25 U *p = 0;
26 p->foo ();
27 char *q = 0;
28 V *u = new (q) V;
29 u->~V ();
30 V *v = new (q) V;
31 v->foo ();
32 v->bar (); // We don't instrument this right now.
33 v->~V ();
34 }
35
36 // { dg-output "\.C:26:\[0-9]*:\[\^\n\r]*member call on null pointer of type 'struct U'.*" }
37 // { dg-output "\.C:29:\[0-9]*:\[\^\n\r]*member call on null pointer of type 'struct V'.*" }
38 // { dg-output "\.C:31:\[0-9]*:\[\^\n\r]*member call on null pointer of type 'struct V'.*" }
39 // { dg-output "\.C:33:\[0-9]*:\[\^\n\r]*member call on null pointer of type 'struct V'" }