2012-02-08 03:01:42 +08:00
|
|
|
// RUN: %clang_cc1 -fsyntax-only -verify -Wformat-nonliteral -pedantic %s
|
2011-12-28 21:10:50 +08:00
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
extern int scanf(const char *restrict, ...);
|
|
|
|
extern int printf(const char *restrict, ...);
|
|
|
|
}
|
|
|
|
|
|
|
|
void f(char **sp, float *fp) {
|
|
|
|
// TODO: Warn that the 'a' length modifier is an extension.
|
|
|
|
scanf("%as", sp);
|
|
|
|
|
|
|
|
// TODO: Warn that the 'a' conversion specifier is a C++11 feature.
|
|
|
|
printf("%a", 1.0);
|
|
|
|
scanf("%afoobar", fp);
|
|
|
|
}
|
2012-01-31 22:59:59 +08:00
|
|
|
|
|
|
|
void g() {
|
|
|
|
printf("%ls", "foo"); // expected-warning{{format specifies type 'wchar_t *' but the argument has type 'const char *'}}
|
|
|
|
}
|
2012-02-08 03:01:42 +08:00
|
|
|
|
|
|
|
// Test that we properly handle format_idx on C++ members.
|
|
|
|
class Foo {
|
|
|
|
public:
|
|
|
|
const char *gettext(const char *fmt) __attribute__((format_arg(2)));
|
|
|
|
|
|
|
|
int scanf(const char *restrict, ...) __attribute__((format(scanf, 2, 3)));
|
|
|
|
int printf(const char *restrict, ...) __attribute__((format(printf, 2, 3)));
|
|
|
|
|
|
|
|
static const char *gettext_static(const char *fmt) __attribute__((format_arg(1)));
|
|
|
|
static int printf_static(const char *restrict, ...) __attribute__((format(printf, 1, 2)));
|
|
|
|
};
|
|
|
|
|
|
|
|
void h(int *i) {
|
|
|
|
Foo foo;
|
|
|
|
foo.scanf("%d"); // expected-warning{{more '%' conversions than data arguments}}
|
|
|
|
foo.printf("%d", i); // expected-warning{{format specifies type 'int' but the argument has type 'int *'}}
|
|
|
|
Foo::printf_static("%d", i); // expected-warning{{format specifies type 'int' but the argument has type 'int *'}}
|
|
|
|
|
|
|
|
printf(foo.gettext("%d"), i); // expected-warning{{format specifies type 'int' but the argument has type 'int *'}}
|
|
|
|
printf(Foo::gettext_static("%d"), i); // expected-warning{{format specifies type 'int' but the argument has type 'int *'}}
|
|
|
|
}
|
2012-02-11 03:13:51 +08:00
|
|
|
|
|
|
|
// Test handling __null for format string literal checking.
|
|
|
|
extern "C" {
|
|
|
|
int test_null_format(const char *format, ...) __attribute__((__format__ (__printf__, 1, 2)));
|
|
|
|
}
|
|
|
|
|
|
|
|
void rdar8269537(const char *f)
|
|
|
|
{
|
|
|
|
test_null_format(__null); // no-warning
|
|
|
|
test_null_format(f); // expected-warning {{not a string literal}}
|
|
|
|
}
|