summaryrefslogtreecommitdiffstats
path: root/clang/test/Sema/format-strings-scanf.c
diff options
context:
space:
mode:
authorHans Wennborg <hans@hanshq.net>2012-07-31 16:37:47 +0000
committerHans Wennborg <hans@hanshq.net>2012-07-31 16:37:47 +0000
commit16250c7c1847184f543d8a837512765cd6eb4bda (patch)
tree4a296ac236ec9a95e1252490ad4cfd47f91d7ba9 /clang/test/Sema/format-strings-scanf.c
parente8a21b73ac5b4d84981fc813db9d8254a45ae477 (diff)
downloadbcm5719-llvm-16250c7c1847184f543d8a837512765cd6eb4bda.tar.gz
bcm5719-llvm-16250c7c1847184f543d8a837512765cd6eb4bda.zip
-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. llvm-svn: 161052
Diffstat (limited to 'clang/test/Sema/format-strings-scanf.c')
-rw-r--r--clang/test/Sema/format-strings-scanf.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/clang/test/Sema/format-strings-scanf.c b/clang/test/Sema/format-strings-scanf.c
index 2ce94840a6f..6f6cb10eb38 100644
--- a/clang/test/Sema/format-strings-scanf.c
+++ b/clang/test/Sema/format-strings-scanf.c
@@ -126,3 +126,21 @@ void test_writeback(int *x) {
scanf("%n", (void*)0); // expected-warning{{format specifies type 'int *' but the argument has type 'void *'}}
scanf("%n %c", x, x); // expected-warning{{format specifies type 'char *' but the argument has type 'int *'}}
}
+
+void test_qualifiers(const int *cip, volatile int* vip,
+ const char *ccp, volatile char* vcp,
+ const volatile int *cvip) {
+ scanf("%d", cip); // expected-warning{{format specifies type 'int *' but the argument has type 'const int *'}}
+ scanf("%n", cip); // expected-warning{{format specifies type 'int *' but the argument has type 'const int *'}}
+ scanf("%s", ccp); // expected-warning{{format specifies type 'char *' but the argument has type 'const char *'}}
+ scanf("%d", cvip); // expected-warning{{format specifies type 'int *' but the argument has type 'const volatile int *'}}
+
+ scanf("%d", vip); // No warning.
+ scanf("%n", vip); // No warning.
+ scanf("%c", vcp); // No warning.
+
+ typedef int* ip_t;
+ typedef const int* cip_t;
+ scanf("%d", (ip_t)0); // No warning.
+ scanf("%d", (cip_t)0); // expected-warning{{format specifies type 'int *' but the argument has type 'cip_t' (aka 'const int *')}}
+}
OpenPOWER on IntegriCloud