1 // RUN: %clang_cc1 -fsyntax-only -Wformat-nonliteral -verify %s
4 int printf(const char *fmt
, ...) __attribute__((format(printf
, 1, 2)));
7 static void f(const char *, ...) __attribute__((format(printf
, 1, 2)));
8 static const char *f2(const char *) __attribute__((format_arg(1)));
10 // GCC has a hidden 'this' argument in member functions which is why
11 // the format argument is argument 2 here.
12 void g(const char*, ...) __attribute__((format(printf
, 2, 3)));
13 const char* g2(const char*) __attribute__((format_arg(2)));
15 void h(const char*, ...) __attribute__((format(printf
, 1, 4))); // \
16 expected
-error
{{implicit
this argument as the format string
}}
17 void h2(const char*, ...) __attribute__((format(printf
, 2, 1))); // \
18 expected
-error
{{out of bounds
}}
19 const char* h3(const char*) __attribute__((format_arg(1))); // \
20 expected
-error
{{invalid
for the implicit
this argument
}}
22 void operator() (const char*, ...) __attribute__((format(printf
, 2, 3)));
26 struct A
{ void a(const char*,...) __attribute((format(printf
,2,3))); };
31 // PR8625: correctly interpret static member calls as not having an implicit
35 static void f(const char*, const char*, ...)
36 __attribute__((format(printf
, 2, 3)));
38 void test(S s
, const char* str
) {
43 // Make sure we interpret member operator calls as having an implicit
45 void test_operator_call(S s
, const char *str
) {
49 template <typename
... Args
>
50 void format(const char *fmt
, Args
&&...args
) // expected-warning{{GCC requires a function with the 'format' attribute to be variadic}}
51 __attribute__((format(printf
, 1, 2)));
53 template <typename Arg
>
54 Arg
&expand(Arg
&a
) { return a
; }
61 template <typename
... Args
>
62 void format(const char *const fmt
, Args
&&...args
) // expected-warning{{GCC requires a function with the 'format' attribute to be variadic}}
63 __attribute__((format(printf
, 2, 3))) {
64 printf(fmt
, expand(args
)...);
68 void format_invalid_nonpod(const char *fmt
, struct foo f
) // expected-warning{{GCC requires a function with the 'format' attribute to be variadic}}
69 __attribute__((format(printf
, 1, 2)));
74 const char *s
= "world";
75 format("bare string");
76 format("%s", 123); // expected-warning{{format specifies type 'char *' but the argument has type 'int'}}
77 format("%s %s %u %d %i %p\n", "hello", s
, 10u, x
, y
, &do_format
);
78 format("%s %s %u %d %i %p\n", "hello", s
, 10u, x
, y
, do_format
);
79 format("bad format %s"); // expected-warning{{more '%' conversions than data arguments}}
82 format_invalid_nonpod("hello %i", f
); // expected-warning{{format specifies type 'int' but the argument has type 'struct foo'}}
84 f
.format("%s", 123); // expected-warning{{format specifies type 'char *' but the argument has type 'int'}}
85 f
.format("%s %s %u %d %i %p\n", "hello", s
, 10u, x
, y
, &do_format
);
86 f
.format("%s %s %u %d %i %p\n", "hello", s
, 10u, x
, y
, do_format
);
87 f
.format("bad format %s"); // expected-warning{{more '%' conversions than data arguments}}