1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -Wformat-nonliteral -verify %s
2*f4a2713aSLionel Sambuc struct S {
3*f4a2713aSLionel Sambuc static void f(const char*, ...) __attribute__((format(printf, 1, 2)));
4*f4a2713aSLionel Sambuc static const char* f2(const char*) __attribute__((format_arg(1)));
5*f4a2713aSLionel Sambuc
6*f4a2713aSLionel Sambuc // GCC has a hidden 'this' argument in member functions which is why
7*f4a2713aSLionel Sambuc // the format argument is argument 2 here.
8*f4a2713aSLionel Sambuc void g(const char*, ...) __attribute__((format(printf, 2, 3)));
9*f4a2713aSLionel Sambuc const char* g2(const char*) __attribute__((format_arg(2)));
10*f4a2713aSLionel Sambuc
11*f4a2713aSLionel Sambuc void h(const char*, ...) __attribute__((format(printf, 1, 4))); // \
12*f4a2713aSLionel Sambuc expected-error{{implicit this argument as the format string}}
13*f4a2713aSLionel Sambuc void h2(const char*, ...) __attribute__((format(printf, 2, 1))); // \
14*f4a2713aSLionel Sambuc expected-error{{out of bounds}}
15*f4a2713aSLionel Sambuc const char* h3(const char*) __attribute__((format_arg(1))); // \
16*f4a2713aSLionel Sambuc expected-error{{invalid for the implicit this argument}}
17*f4a2713aSLionel Sambuc
18*f4a2713aSLionel Sambuc void operator() (const char*, ...) __attribute__((format(printf, 2, 3)));
19*f4a2713aSLionel Sambuc };
20*f4a2713aSLionel Sambuc
21*f4a2713aSLionel Sambuc // PR5521
22*f4a2713aSLionel Sambuc struct A { void a(const char*,...) __attribute((format(printf,2,3))); };
b(A x)23*f4a2713aSLionel Sambuc void b(A x) {
24*f4a2713aSLionel Sambuc x.a("%d", 3);
25*f4a2713aSLionel Sambuc }
26*f4a2713aSLionel Sambuc
27*f4a2713aSLionel Sambuc // PR8625: correctly interpret static member calls as not having an implicit
28*f4a2713aSLionel Sambuc // 'this' argument.
29*f4a2713aSLionel Sambuc namespace PR8625 {
30*f4a2713aSLionel Sambuc struct S {
31*f4a2713aSLionel Sambuc static void f(const char*, const char*, ...)
32*f4a2713aSLionel Sambuc __attribute__((format(printf, 2, 3)));
33*f4a2713aSLionel Sambuc };
test(S s,const char * str)34*f4a2713aSLionel Sambuc void test(S s, const char* str) {
35*f4a2713aSLionel Sambuc s.f(str, "%s", str);
36*f4a2713aSLionel Sambuc }
37*f4a2713aSLionel Sambuc }
38*f4a2713aSLionel Sambuc
39*f4a2713aSLionel Sambuc // Make sure we interpret member operator calls as having an implicit
40*f4a2713aSLionel Sambuc // this argument.
test_operator_call(S s,const char * str)41*f4a2713aSLionel Sambuc void test_operator_call(S s, const char* str) {
42*f4a2713aSLionel Sambuc s("%s", str);
43*f4a2713aSLionel Sambuc }
44