llvm-project/clang/test/SemaCXX/printf-block.cpp
Charles Li 542f04cc4d [Lit Test] Updated 26 Lit tests to be C++11 compatible.
Expected diagnostics have been expanded to vary by C++ dialect.
RUN line has also been expanded to: default, C++98/03 and C++11.

llvm-svn: 252785
2015-11-11 19:34:47 +00:00

27 lines
1.1 KiB
C++

// RUN: %clang_cc1 -fsyntax-only -fblocks -Wformat -verify %s -Wno-error=non-pod-varargs
// RUN: %clang_cc1 -fsyntax-only -fblocks -Wformat -verify %s -Wno-error=non-pod-varargs -std=c++98
// RUN: %clang_cc1 -fsyntax-only -fblocks -Wformat -verify %s -Wno-error=non-pod-varargs -std=c++11
int (^block) (int, const char *,...) __attribute__((__format__(__printf__,2,3))) = ^ __attribute__((__format__(__printf__,2,3))) (int arg, const char *format,...) {return 5;};
class HasNoCStr {
const char *str;
public:
HasNoCStr(const char *s): str(s) { }
const char *not_c_str() {return str;}
};
void test_block() {
const char str[] = "test";
HasNoCStr hncs(str);
int n = 4;
block(n, "%s %d", str, n); // no-warning
block(n, "%s %s", hncs, n);
#if __cplusplus <= 199711L // C++03 or earlier modes
// expected-warning@-2{{cannot pass non-POD object of type 'HasNoCStr' to variadic block; expected type from format string was 'char *'}}
#else
// expected-warning@-4{{format specifies type 'char *' but the argument has type 'HasNoCStr'}}
#endif
// expected-warning@-6{{format specifies type 'char *' but the argument has type 'int'}}
}