1/* Test for multiple format attributes.  Test for printf and scanf attributes
2   together.  */
3/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
4/* { dg-do compile } */
5/* { dg-options "-std=gnu99 -Wformat" } */
6
7#define DONT_GNU_PROTOTYPE
8#include "format.h"
9
10/* If we specify multiple attributes for a single function, they should
11   all apply.  This should apply whether they are on the same declaration
12   or on different declarations.  */
13
14extern void my_vprintf_scanf (const char *, va_list, const char *, ...)
15     __attribute__((__format__(gnu_attr___printf__, 1, 0)))
16     __attribute__((__format__(gnu_attr___scanf__, 3, 4)));
17
18extern void my_vprintf_scanf2 (const char *, va_list, const char *, ...)
19     __attribute__((__format__(gnu_attr___scanf__, 3, 4)))
20     __attribute__((__format__(gnu_attr___printf__, 1, 0)));
21
22extern void my_vprintf_scanf3 (const char *, va_list, const char *, ...)
23     __attribute__((__format__(gnu_attr___printf__, 1, 0)));
24extern void my_vprintf_scanf3 (const char *, va_list, const char *, ...)
25     __attribute__((__format__(gnu_attr___scanf__, 3, 4)));
26
27extern void my_vprintf_scanf4 (const char *, va_list, const char *, ...)
28     __attribute__((__format__(gnu_attr___scanf__, 3, 4)));
29extern void my_vprintf_scanf4 (const char *, va_list, const char *, ...)
30     __attribute__((__format__(gnu_attr___printf__, 1, 0)));
31
32void
33foo (va_list ap, int *ip, long *lp)
34{
35  my_vprintf_scanf ("%d", ap, "%d", ip);
36  my_vprintf_scanf ("%d", ap, "%ld", lp);
37  my_vprintf_scanf ("%", ap, "%d", ip); /* { dg-warning "format" "printf" } */
38  my_vprintf_scanf ("%d", ap, "%ld", ip); /* { dg-warning "format" "scanf" } */
39  my_vprintf_scanf2 ("%d", ap, "%d", ip);
40  my_vprintf_scanf2 ("%d", ap, "%ld", lp);
41  my_vprintf_scanf2 ("%", ap, "%d", ip); /* { dg-warning "format" "printf" } */
42  my_vprintf_scanf2 ("%d", ap, "%ld", ip); /* { dg-warning "format" "scanf" } */
43  my_vprintf_scanf3 ("%d", ap, "%d", ip);
44  my_vprintf_scanf3 ("%d", ap, "%ld", lp);
45  my_vprintf_scanf3 ("%", ap, "%d", ip); /* { dg-warning "format" "printf" } */
46  my_vprintf_scanf3 ("%d", ap, "%ld", ip); /* { dg-warning "format" "scanf" } */
47  my_vprintf_scanf4 ("%d", ap, "%d", ip);
48  my_vprintf_scanf4 ("%d", ap, "%ld", lp);
49  my_vprintf_scanf4 ("%", ap, "%d", ip); /* { dg-warning "format" "printf" } */
50  my_vprintf_scanf4 ("%d", ap, "%ld", ip); /* { dg-warning "format" "scanf" } */
51}
52