| 1 |
/* Test for format checking of constant arrays. */ |
| 2 |
/* Origin: Joseph Myers <[email protected]> */ |
| 3 |
/* { dg-do compile } */ |
| 4 |
/* { dg-options "-std=gnu99 -Wformat=2" } */ |
| 5 |
|
| 6 |
#include "format.h" |
| 7 |
|
| 8 |
const char a1[] = "foo"; |
| 9 |
const char a2[] = "foo%d"; |
| 10 |
const char b1[3] = "foo"; |
| 11 |
const char b2[1] = "1"; |
| 12 |
static const char c1[] = "foo"; |
| 13 |
static const char c2[] = "foo%d"; |
| 14 |
char d[] = "foo"; |
| 15 |
volatile const char e[] = "foo"; |
| 16 |
|
| 17 |
void |
| 18 |
foo (int i, long l) |
| 19 |
{ |
| 20 |
const char p1[] = "bar"; |
| 21 |
const char p2[] = "bar%d"; |
| 22 |
static const char q1[] = "bar"; |
| 23 |
static const char q2[] = "bar%d"; |
| 24 |
printf (a1); |
| 25 |
printf (a2, i); |
| 26 |
printf (a2, l); /* { dg-warning "11:format" "wrong type with array" } */ |
| 27 |
printf (b1); /* { dg-warning "11:unterminated" "unterminated array" } */ |
| 28 |
printf (b2); /* { dg-warning "11:unterminated" "unterminated array" } */ |
| 29 |
printf (c1); |
| 30 |
printf (c2, i); |
| 31 |
printf (c2, l); /* { dg-warning "11:format" "wrong type with array" } */ |
| 32 |
printf (p1); |
| 33 |
printf (p2, i); |
| 34 |
printf (p2, l); /* { dg-warning "11:format" "wrong type with array" } */ |
| 35 |
printf (q1); |
| 36 |
printf (q2, i); |
| 37 |
printf (q2, l); /* { dg-warning "11:format" "wrong type with array" } */ |
| 38 |
/* Volatile or non-constant arrays must not be checked. */ |
| 39 |
printf (d); /* { dg-warning "11:not a string literal" "non-const" } */ |
| 40 |
printf ((const char *)e); /* { dg-warning "25:not a string literal" "volatile" } */ |
| 41 |
} |