blob: da134a136d26d081300cbba67f7a6ac2cace3bc3 [file] [log] [blame]
Chandler Carruth9263a302010-11-16 08:49:43 +00001// RUN: %clang_cc1 -fsyntax-only -Wformat-nonliteral -verify %s
Anders Carlsson4fb77202009-08-25 14:12:34 +00002struct S {
Mike Stump1eb44332009-09-09 15:08:12 +00003 static void f(const char*, ...) __attribute__((format(printf, 1, 2)));
Chandler Carruth07d7e7a2010-11-16 08:35:43 +00004 static const char* f2(const char*) __attribute__((format_arg(1)));
Mike Stump1eb44332009-09-09 15:08:12 +00005
6 // GCC has a hidden 'this' argument in member functions which is why
7 // the format argument is argument 2 here.
8 void g(const char*, ...) __attribute__((format(printf, 2, 3)));
Chandler Carruth07d7e7a2010-11-16 08:35:43 +00009 const char* g2(const char*) __attribute__((format_arg(2)));
10
11 void h(const char*, ...) __attribute__((format(printf, 1, 4))); // \
12 expected-error{{implicit this argument as the format string}}
13 void h2(const char*, ...) __attribute__((format(printf, 2, 1))); // \
14 expected-error{{out of bounds}}
15 const char* h3(const char*) __attribute__((format_arg(1))); // \
16 expected-error{{invalid for the implicit this argument}}
Mike Stump1eb44332009-09-09 15:08:12 +000017};
Chandler Carruth07d7e7a2010-11-16 08:35:43 +000018
19// PR5521
20struct A { void a(const char*,...) __attribute((format(printf,2,3))); };
21void b(A x) {
22 x.a("%d", 3);
23}
Chandler Carruth9263a302010-11-16 08:49:43 +000024
25// PR8625: correctly interpret static member calls as not having an implicit
26// 'this' argument.
27namespace PR8625 {
28 struct S {
29 static void f(const char*, const char*, ...)
30 __attribute__((format(printf, 2, 3)));
31 };
32 void test(S s, const char* str) {
33 s.f(str, "%s", str);
34 }
35}