diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/Sema/format-strings-scanf.c | 18 | ||||
-rw-r--r-- | test/Sema/format-strings.c | 16 |
2 files changed, 34 insertions, 0 deletions
diff --git a/test/Sema/format-strings-scanf.c b/test/Sema/format-strings-scanf.c index 2ce94840a6..6f6cb10eb3 100644 --- a/test/Sema/format-strings-scanf.c +++ b/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 *')}} +} 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 *')}} +} |