diff options
author | Hans Wennborg <hans@hanshq.net> | 2012-07-31 16:37:47 +0000 |
---|---|---|
committer | Hans Wennborg <hans@hanshq.net> | 2012-07-31 16:37:47 +0000 |
commit | 5deddafd3ef51e94b4ac4d80e38271d3768b1af6 (patch) | |
tree | 7f4e06763ba091274905164494f32c5484b32363 /test/Sema/format-strings.c | |
parent | 6b4be2ef4ce49717ff972434975ce3c34c9a1c4c (diff) |
-Wformat: better handling of qualifiers on pointer arguments
Warn about using pointers to const-qualified types as arguments to
scanf. Ignore the volatile qualifier when checking if types match.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@161052 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/Sema/format-strings.c')
-rw-r--r-- | test/Sema/format-strings.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/test/Sema/format-strings.c b/test/Sema/format-strings.c index d35125833c..aff996fed3 100644 --- a/test/Sema/format-strings.c +++ b/test/Sema/format-strings.c @@ -555,3 +555,19 @@ void test14_zed(int *p) { test14_foo("%", "%d", p); // expected-warning{{incomplete format specifier}} test14_bar("%", "%d", p); // expected-warning{{incomplete format specifier}} } + +void test_qualifiers(volatile int *vip, const int *cip, + const volatile int *cvip) { + printf("%n", cip); // expected-warning{{format specifies type 'int *' but the argument has type 'const int *'}} + printf("%n", cvip); // expected-warning{{format specifies type 'int *' but the argument has type 'const volatile int *'}} + + printf("%n", vip); // No warning. + printf("%p", cip); // No warning. + printf("%p", cvip); // No warning. + + + typedef int* ip_t; + typedef const int* cip_t; + printf("%n", (ip_t)0); // No warning. + printf("%n", (cip_t)0); // expected-warning{{format specifies type 'int *' but the argument has type 'cip_t' (aka 'const int *')}} +} |