diff options
author | Hans Wennborg <hans@hanshq.net> | 2012-02-22 10:17:01 +0000 |
---|---|---|
committer | Hans Wennborg <hans@hanshq.net> | 2012-02-22 10:17:01 +0000 |
commit | c9dd94685283938a2d9227a0fa448f08d7b19ab4 (patch) | |
tree | 47b9bd818b08934e2c6acf387bcb84522b0ca6f0 /clang/test/Sema | |
parent | 8eb771d4ca343ae6baf884c9d9a77e09469052bb (diff) | |
download | bcm5719-llvm-c9dd94685283938a2d9227a0fa448f08d7b19ab4.tar.gz bcm5719-llvm-c9dd94685283938a2d9227a0fa448f08d7b19ab4.zip |
Warn about non-standard format strings (pr12017)
This adds the -Wformat-non-standard flag (off by default,
enabled by -pedantic), which warns about non-standard
things in format strings (such as the 'q' length modifier,
the 'S' conversion specifier, etc.)
llvm-svn: 151154
Diffstat (limited to 'clang/test/Sema')
-rw-r--r-- | clang/test/Sema/format-strings-c90.c | 15 | ||||
-rw-r--r-- | clang/test/Sema/format-strings-non-standard.c | 26 | ||||
-rw-r--r-- | clang/test/Sema/format-strings.c | 1 |
3 files changed, 35 insertions, 7 deletions
diff --git a/clang/test/Sema/format-strings-c90.c b/clang/test/Sema/format-strings-c90.c index 0b32e82d872..63d58532cb8 100644 --- a/clang/test/Sema/format-strings-c90.c +++ b/clang/test/Sema/format-strings-c90.c @@ -5,9 +5,8 @@ int scanf(const char * restrict, ...); int printf(const char *restrict, ...); void foo(char **sp, float *fp, int *ip) { - /* TODO: Warn that the 'a' length modifier is an extension. */ - scanf("%as", sp); - scanf("%a[abc]", sp); + scanf("%as", sp); /* expected-warning{{'a' is a non-standard length modifier}} */ + scanf("%a[abc]", sp); /* expected-warning{{'a' is a non-standard length modifier}} */ /* TODO: Warn that the 'a' conversion specifier is a C99 feature. */ scanf("%a", fp); @@ -21,7 +20,11 @@ void foo(char **sp, float *fp, int *ip) { scanf("%da", ip); /* Test argument type check for the 'a' length modifier. */ - scanf("%as", fp); /* expected-warning{{format specifies type 'char **' but the argument has type 'float *'}} */ - scanf("%aS", fp); /* expected-warning{{format specifies type 'wchar_t **' (aka 'int **') but the argument has type 'float *'}} */ - scanf("%a[abc]", fp); /* expected-warning{{format specifies type 'char **' but the argument has type 'float *'}} */ + scanf("%as", fp); /* expected-warning{{format specifies type 'char **' but the argument has type 'float *'}} + expected-warning{{'a' is a non-standard length modifier}} */ + scanf("%aS", fp); /* expected-warning{{format specifies type 'wchar_t **' (aka 'int **') but the argument has type 'float *'}} + expected-warning{{'a' is a non-standard length modifier}} + expected-warning{{'S' is a non-standard conversion specifier}} */ + scanf("%a[abc]", fp); /* expected-warning{{format specifies type 'char **' but the argument has type 'float *'}} + expected-warning{{'a' is a non-standard length modifier}} */ } diff --git a/clang/test/Sema/format-strings-non-standard.c b/clang/test/Sema/format-strings-non-standard.c new file mode 100644 index 00000000000..a24d43a6e1d --- /dev/null +++ b/clang/test/Sema/format-strings-non-standard.c @@ -0,0 +1,26 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -std=c99 -pedantic %s + +int printf(const char *restrict, ...); +int scanf(const char * restrict, ...); + +void f(void) { + char *cp; + + // The 'q' length modifier. + printf("%qd", (long long)42); // expected-warning{{'q' is a non-standard length modifier}} + scanf("%qd", (long long *)0); // expected-warning{{'q' is a non-standard length modifier}} + + // The 'm' length modifier. + scanf("%ms", &cp); // expected-warning{{'m' is a non-standard length modifier}} + + // The 'S' and 'C' conversion specifiers. + printf("%S", L"foo"); // expected-warning{{'S' is a non-standard conversion specifier}} + printf("%C", L'x'); // expected-warning{{'C' is a non-standard conversion specifier}} + + // Combining 'L' with an integer conversion specifier. + printf("%Li", (long long)42); // expected-warning{{using the length modifier 'L' with the conversion specifier 'i' is non-standard}} + printf("%Lo", (long long)42); // expected-warning{{using the length modifier 'L' with the conversion specifier 'o' is non-standard}} + printf("%Lu", (long long)42); // expected-warning{{using the length modifier 'L' with the conversion specifier 'u' is non-standard}} + printf("%Lx", (long long)42); // expected-warning{{using the length modifier 'L' with the conversion specifier 'x' is non-standard}} + printf("%LX", (long long)42); // expected-warning{{using the length modifier 'L' with the conversion specifier 'X' is non-standard}} +} diff --git a/clang/test/Sema/format-strings.c b/clang/test/Sema/format-strings.c index 55b8201fd39..086c5c6d6fe 100644 --- a/clang/test/Sema/format-strings.c +++ b/clang/test/Sema/format-strings.c @@ -268,7 +268,6 @@ void test_unicode_conversions(wchar_t *s) { // FIXME: This test reports inconsistent results. On Windows, '%C' expects // 'unsigned short'. // printf("%C", 10); - // FIXME: we report the expected type as 'int*' instead of 'wchar_t*' printf("%S", "hello"); // expected-warning{{but the argument has type 'char *'}} } |