xref: /minix3/external/bsd/llvm/dist/clang/test/SemaCXX/printf-block.cpp (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -fblocks -Wformat -verify %s -Wno-error=non-pod-varargs
2*f4a2713aSLionel Sambuc 
3*f4a2713aSLionel Sambuc int (^block) (int, const char *,...) __attribute__((__format__(__printf__,2,3))) = ^ __attribute__((__format__(__printf__,2,3))) (int arg, const char *format,...) {return 5;};
4*f4a2713aSLionel Sambuc 
5*f4a2713aSLionel Sambuc class HasNoCStr {
6*f4a2713aSLionel Sambuc   const char *str;
7*f4a2713aSLionel Sambuc  public:
HasNoCStr(const char * s)8*f4a2713aSLionel Sambuc   HasNoCStr(const char *s): str(s) { }
not_c_str()9*f4a2713aSLionel Sambuc   const char *not_c_str() {return str;}
10*f4a2713aSLionel Sambuc };
11*f4a2713aSLionel Sambuc 
test_block()12*f4a2713aSLionel Sambuc void test_block() {
13*f4a2713aSLionel Sambuc   const char str[] = "test";
14*f4a2713aSLionel Sambuc   HasNoCStr hncs(str);
15*f4a2713aSLionel Sambuc   int n = 4;
16*f4a2713aSLionel Sambuc   block(n, "%s %d", str, n); // no-warning
17*f4a2713aSLionel Sambuc   block(n, "%s %s", hncs, n); // expected-warning{{cannot pass non-POD object of type 'HasNoCStr' to variadic block; expected type from format string was 'char *'}} expected-warning{{format specifies type 'char *' but the argument has type 'int'}}
18*f4a2713aSLionel Sambuc }
19