blob: a1cd0b84b3769f47e13abb3bdfe2c94a66262cb6 [file] [log] [blame]
Ted Kremenekaa8f9762008-03-07 18:43:49 +00001//RUN: clang -fsyntax-only -verify %s
2
3#include <stdarg.h>
4
5void a(const char *a, ...) __attribute__((format(printf, 1,2))); // no-error
6void b(const char *a, ...) __attribute__((format(printf, 1,1))); // expected-error {{'format' attribute parameter 3 is out of bounds}}
7void c(const char *a, ...) __attribute__((format(printf, 0,2))); // expected-error {{'format' attribute parameter 2 is out of bounds}}
8void d(const char *a, int c) __attribute__((format(printf, 1,2))); // expected-error {{format attribute requires variadic function}}
9void e(char *str, int c, ...) __attribute__((format(printf, 2,3))); // expected-error {{format argument not a string type}}
10
11typedef const char* xpto;
12void f(xpto c, va_list list) __attribute__((format(printf, 1, 0))); // no-error
13void g(xpto c) __attribute__((format(printf, 1, 0))); // no-error
14
15void y(char *str) __attribute__((format(strftime, 1,0))); // no-error
16void z(char *str, int c, ...) __attribute__((format(strftime, 1,2))); // expected-error {{strftime format attribute requires 3rd parameter to be 0}}
Nuno Lopes8c1a9a82008-03-25 23:01:48 +000017
18int (*f_ptr)(char*,...) __attribute__((format(printf, 1,2))); // no-error
19int (*f2_ptr)(double,...) __attribute__((format(printf, 1, 2))); // expected-error {{format argument not a string type}}
Nuno Lopes59b6d5a2008-04-18 22:43:39 +000020
21struct _mystruct {
22 int (*printf)(const char *format, ...) __attribute__((__format__(printf, 1, 2))); // no-error
23 int (*printf2)(double format, ...) __attribute__((__format__(printf, 1, 2))); // expected-error {{format argument not a string type}}
24};
Ted Kremenek72786e02008-05-09 17:36:24 +000025
26typedef int (*f3_ptr)(char*,...) __attribute__((format(printf,1,0))); // no-error
Ted Kremenek3d692df2009-02-27 17:58:43 +000027
28// <rdar://problem/6623513>
29int rdar6623513(void *, const char*, const char*, ...)
30 __attribute__ ((format (printf, 3, 0)));
31
32int rdar6623513_aux(int len, const char* s) {
33 rdar6623513(0, "hello", "%.*s", len, s);
34}