| Chandler Carruth | 1c8383d | 2010-11-16 08:49:43 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -Wformat-nonliteral -verify %s | 
| Anders Carlsson | be96bc9 | 2009-08-25 14:12:34 +0000 | [diff] [blame] | 2 | struct S { | 
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3 | static void f(const char*, ...) __attribute__((format(printf, 1, 2))); | 
| Chandler Carruth | 743682b | 2010-11-16 08:35:43 +0000 | [diff] [blame] | 4 | static const char* f2(const char*) __attribute__((format_arg(1))); | 
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5 |  | 
|  | 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 Carruth | 743682b | 2010-11-16 08:35:43 +0000 | [diff] [blame] | 9 | 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}} | 
| Eli Friedman | 726d11c | 2012-10-11 00:30:58 +0000 | [diff] [blame] | 17 |  | 
|  | 18 | void operator() (const char*, ...) __attribute__((format(printf, 2, 3))); | 
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 19 | }; | 
| Chandler Carruth | 743682b | 2010-11-16 08:35:43 +0000 | [diff] [blame] | 20 |  | 
|  | 21 | // PR5521 | 
|  | 22 | struct A { void a(const char*,...) __attribute((format(printf,2,3))); }; | 
|  | 23 | void b(A x) { | 
|  | 24 | x.a("%d", 3); | 
|  | 25 | } | 
| Chandler Carruth | 1c8383d | 2010-11-16 08:49:43 +0000 | [diff] [blame] | 26 |  | 
|  | 27 | // PR8625: correctly interpret static member calls as not having an implicit | 
|  | 28 | // 'this' argument. | 
|  | 29 | namespace PR8625 { | 
|  | 30 | struct S { | 
|  | 31 | static void f(const char*, const char*, ...) | 
|  | 32 | __attribute__((format(printf, 2, 3))); | 
|  | 33 | }; | 
|  | 34 | void test(S s, const char* str) { | 
|  | 35 | s.f(str, "%s", str); | 
|  | 36 | } | 
|  | 37 | } | 
| Eli Friedman | 726d11c | 2012-10-11 00:30:58 +0000 | [diff] [blame] | 38 |  | 
|  | 39 | // Make sure we interpret member operator calls as having an implicit | 
|  | 40 | // this argument. | 
|  | 41 | void test_operator_call(S s, const char* str) { | 
|  | 42 | s("%s", str); | 
|  | 43 | } |