-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
diff --git a/test/Sema/format-strings-scanf.c b/test/Sema/format-strings-scanf.c
index 2ce9484..6f6cb10 100644
--- a/test/Sema/format-strings-scanf.c
+++ b/test/Sema/format-strings-scanf.c
@@ -126,3 +126,21 @@
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 *')}}
+}