While we still want to consider this a hard error (non-POD variadic args are normally a DefaultError warning), delaying the diagnostic allows us to give better error messages, which also match the usual non-POD errors more closely. In addition, this change improves the diagnostic messages for format string argument type mismatches by passing down the type of the callee, so we can say "variadic method" or "variadic function" appropriately. <rdar://problem/11825593> llvm-svn: 160517
19 lines
774 B
C++
19 lines
774 B
C++
// RUN: %clang_cc1 -fsyntax-only -fblocks -Wformat -verify %s -Wno-error=non-pod-varargs
|
|
|
|
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); // 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'}}
|
|
}
|