[docs] Add LICENSE.txt to the root of the mono-repo
[llvm-project.git] / clang / test / SemaCXX / printf-block.cpp
blobb9d06d6c4fe779cc944232ff24851779ae617bb3
1 // RUN: %clang_cc1 -fsyntax-only -fblocks -Wformat -verify %s -Wno-error=non-pod-varargs
2 // RUN: %clang_cc1 -fsyntax-only -fblocks -Wformat -verify %s -Wno-error=non-pod-varargs -std=c++98
3 // RUN: %clang_cc1 -fsyntax-only -fblocks -Wformat -verify %s -Wno-error=non-pod-varargs -std=c++11
5 int (^block) (int, const char *,...) __attribute__((__format__(__printf__,2,3))) = ^ __attribute__((__format__(__printf__,2,3))) (int arg, const char *format,...) {return 5;};
7 class HasNoCStr {
8 const char *str;
9 public:
10 HasNoCStr(const char *s): str(s) { }
11 const char *not_c_str() {return str;}
14 void test_block() {
15 const char str[] = "test";
16 HasNoCStr hncs(str);
17 int n = 4;
18 block(n, "%s %d", str, n); // no-warning
19 block(n, "%s %s", hncs, n);
20 #if __cplusplus <= 199711L // C++03 or earlier modes
21 // expected-warning@-2{{cannot pass non-POD object of type 'HasNoCStr' to variadic block; expected type from format string was 'char *'}}
22 #else
23 // expected-warning@-4{{format specifies type 'char *' but the argument has type 'HasNoCStr'}}
24 #endif
25 // expected-warning@-6{{format specifies type 'char *' but the argument has type 'int'}}