You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// The warning still fires, because it checks the underlying type.
33
33
printf("%jd", (intmax_t)42); // expected-warning {{format specifies type 'intmax_t' (aka 'long long') but the argument has type 'intmax_t' (aka 'void *')}}
34
34
printf("%ju", (uintmax_t)42); // expected-warning {{format specifies type 'uintmax_t' (aka 'unsigned long long') but the argument has type 'uintmax_t' (aka 'void *')}}
35
-
printf("%zu", (size_t)42); // expected-warning {{format specifies type 'size_t' (aka '__size_t') but the argument has type 'size_t' (aka 'void *')}}
36
-
printf("%td", (ptrdiff_t)42); // expected-warning {{format specifies type 'ptrdiff_t' (aka '__ptrdiff_t') but the argument has type 'ptrdiff_t' (aka 'void *')}}
35
+
printf("%zu", (size_t)42); // expected-warning {{format specifies type 'size_t' (aka 'unsigned long') but the argument has type 'size_t' (aka 'void *')}}
36
+
printf("%td", (ptrdiff_t)42); // expected-warning {{format specifies type 'ptrdiff_t' (aka 'int') but the argument has type 'ptrdiff_t' (aka 'void *')}}
printf("%zu", (double)42); // expected-warning {{format specifies type 'size_t' (aka 'unsigned long') but the argument has type 'double'}}
9
13
// intmax_t / uintmax_t
10
14
printf("%jd", (double)42); // expected-warning {{format specifies type 'intmax_t' (aka 'long') but the argument has type 'double'}}
11
15
printf("%ju", (double)42); // expected-warning {{format specifies type 'uintmax_t' (aka 'unsigned long') but the argument has type 'double'}}
12
16
13
17
// ptrdiff_t
14
-
printf("%td", (double)42); // expected-warning {{format specifies type 'ptrdiff_t' (aka '__ptrdiff_t') but the argument has type 'double'}}
18
+
printf("%td", (double)42); // expected-warning {{format specifies type 'ptrdiff_t' (aka 'long') but the argument has type 'double'}}
15
19
}
16
20
17
21
voidtest_writeback(void) {
18
22
printf("%jn", (long*)0); // no-warning
19
23
printf("%jn", (unsigned long*)0); // no-warning
20
24
printf("%jn", (int*)0); // expected-warning{{format specifies type 'intmax_t *' (aka 'long *') but the argument has type 'int *'}}
21
25
22
-
printf("%zn", (int*)0); // expected-warning{{format specifies type 'signed size_t *' (aka '__signed_size_t *') but the argument has type 'int *'}}
26
+
printf("%zn", (long*)0); // no-warning
27
+
// FIXME: Warn about %zn with non-ssize_t argument.
23
28
24
-
printf("%tn", (long*)0); // expected-warning{{format specifies type 'ptrdiff_t *' (aka '__ptrdiff_t *') but the argument has type 'long *'}}
25
-
printf("%tn", (unsigned long*)0); // expected-warning{{format specifies type 'ptrdiff_t *' (aka '__ptrdiff_t *') but the argument has type 'unsigned long *'}}
26
-
printf("%tn", (int*)0); // expected-warning{{format specifies type 'ptrdiff_t *' (aka '__ptrdiff_t *') but the argument has type 'int *'}}
29
+
printf("%tn", (long*)0); // no-warning
30
+
printf("%tn", (unsigned long*)0); // no-warning
31
+
printf("%tn", (int*)0); // expected-warning{{format specifies type 'ptrdiff_t *' (aka 'long *') but the argument has type 'int *'}}
// expected-warning@-2 {{values of type 'NSInteger' should not be used as format arguments; add an explicit cast to 'long' instead}}
36
+
// expected-warning@-4 {{values of type 'NSInteger' should not be used as format arguments; add an explicit cast to 'long' instead}}
37
+
// expected-warning@-4 {{values of type 'NSUInteger' should not be used as format arguments; add an explicit cast to 'unsigned long' instead}}
31
38
#endif
32
-
NSLog(@"max NSUinteger = %zu", j); // expected-warning {{values of type 'NSUInteger' should not be used as format arguments; add an explicit cast to 'unsigned long' instead}}
33
39
}
34
40
35
41
voidtestPtrdiffSpecifier(ptrdiff_t x) {
36
42
NSInteger i = 0;
37
43
NSUInteger j = 0;
38
44
39
45
NSLog(@"ptrdiff_t NSUinteger: %tu", j);
46
+
NSLog(@"ptrdiff_t NSInteger: %td", i);
47
+
NSLog(@"ptrdiff_t %tu, %td", x, x);
40
48
#if __is_target_os(watchos) && defined(PEDANTIC)
41
-
// expected-warning@-2 {{values of type 'NSUInteger' should not be used as format arguments; add an explicit cast to 'unsigned long' instead}}
49
+
// expected-warning@-4 {{values of type 'NSUInteger' should not be used as format arguments; add an explicit cast to 'unsigned long' instead}}
50
+
// expected-warning@-4 {{values of type 'NSInteger' should not be used as format arguments; add an explicit cast to 'long' instead}}
42
51
#endif
43
-
NSLog(@"ptrdiff_t NSInteger: %td", i); // expected-warning {{values of type 'NSInteger' should not be used as format arguments; add an explicit cast to 'long' instead}}
0 commit comments