Daily bump.
[official-gcc.git] / gcc / testsuite / gcc.dg / Wrestrict-20.c
bloba2d29887c37a6cfa138a4c53b0e29cc95985e4f1
1 /* PR c/84919 - bogus -Wrestrict on sprintf %p with destination as argument
2 { dg-do compile }
3 -O2 isn't strictly necessary but setting also verifies that the sprintf/
4 strlen pass doesn't warn with non-constant arguments.
5 { dg-options "-O2 -Wall" } */
7 extern int sprintf (char* restrict, const char* restrict, ...);
8 extern int snprintf (char* restrict, __SIZE_TYPE__, const char* restrict, ...);
10 char a[32];
12 void test_warn (char *p)
14 a[0] = 0;
15 sprintf (a, "a=%s", a); /* { dg-warning "-Wrestrict" } */
17 p = a;
18 char *q = p + 3;
19 sprintf (p, "a=%s", q); /* { dg-warning "-Wrestrict" } */
22 void test_nowarn_front_end (char *d)
24 sprintf (d, "%p", d);
25 snprintf (d, 32, "%p", d);
27 sprintf (a, "p=%p", a);
28 snprintf (a, sizeof a, "%p", a);
31 void test_nowarn_sprintf_pass (char *d)
33 char *q = d;
35 sprintf (d, "p=%p", q);
36 snprintf (d, 32, "p=%p", q);
38 q = a;
39 sprintf (a, "a=%p", q);
40 snprintf (a, sizeof a, "a=%p", q);