2018-11-07 Richard Biener <rguenther@suse.de>
[official-gcc.git] / gcc / testsuite / g++.dg / ubsan / null-1.C
blob04e8490fc0856967e9fb43c0eae00dbe5ddc4b93
1 // { dg-do run }
2 // { dg-options "-fsanitize=null -Wall -Wno-unused-variable -std=c++11" }
4 typedef const long int L;
6 int
7 main (void)
9   int *p = 0;
10   L *l = 0;
12   int &r = *p;
13   auto &r2 = *p;
14   L &lr = *l;
16   // Try an rvalue reference.
17   auto &&r3 = *p;
19   // Don't evaluate the reference initializer twice.
20   int i = 1;
21   int *q = &i;
22   int &qr = ++*q;
23   if (i != 2)
24     __builtin_abort ();
27 // { dg-output "reference binding to null pointer of type 'int'(\n|\r\n|\r)" }
28 // { dg-output "\[^\n\r]*reference binding to null pointer of type 'int'(\n|\r\n|\r)" }
29 // { dg-output "\[^\n\r]*reference binding to null pointer of type 'const L'(\n|\r\n|\r)" }
30 // { dg-output "\[^\n\r]*reference binding to null pointer of type 'int'" }