1// Test for format attributes: test applying them to types in C++.
2// Origin: Joseph Myers <jsm28@cam.ac.uk>
3// { dg-do compile }
4// { dg-options "-Wformat" }
5
6__attribute__((format(printf, 1, 2))) void (*tformatprintf0) (const char *, ...);
7void (*tformatprintf1) (const char *, ...) __attribute__((format(printf, 1, 2)));
8void (__attribute__((format(printf, 1, 2))) *tformatprintf2) (const char *, ...);
9void (__attribute__((format(printf, 1, 2))) ****tformatprintf3) (const char *, ...);
10
11char * (__attribute__((format_arg(1))) *tformat_arg) (const char *);
12
13void
14baz (int i)
15{
16  (*tformatprintf0) ("%d", i);
17  (*tformatprintf0) ((*tformat_arg) ("%d"), i);
18  (*tformatprintf0) ("%"); // { dg-warning "format" "prefix" }
19  (*tformatprintf0) ((*tformat_arg) ("%")); // { dg-warning "format" "prefix" }
20  (*tformatprintf1) ("%d", i);
21  (*tformatprintf1) ((*tformat_arg) ("%d"), i);
22  (*tformatprintf1) ("%"); // { dg-warning "format" "postfix" }
23  (*tformatprintf1) ((*tformat_arg) ("%")); // { dg-warning "format" "postfix" }
24  (*tformatprintf2) ("%d", i);
25  (*tformatprintf2) ((*tformat_arg) ("%d"), i);
26  (*tformatprintf2) ("%"); // { dg-warning "format" "nested" }
27  (*tformatprintf2) ((*tformat_arg) ("%")); // { dg-warning "format" "nested" }
28  (****tformatprintf3) ("%d", i);
29  (****tformatprintf3) ((*tformat_arg) ("%d"), i);
30  (****tformatprintf3) ("%"); // { dg-warning "format" "nested 2" }
31  (****tformatprintf3) ((*tformat_arg) ("%")); // { dg-warning "format" "nested 2" }
32}
33