Tom Care | 3bfc5f4 | 2010-06-09 04:11:11 +0000 | [diff] [blame] | 1 | // RUN: cp %s %t |
| 2 | // RUN: %clang_cc1 -pedantic -Wall -fixit %t || true |
| 3 | // RUN: %clang_cc1 -fsyntax-only -pedantic -Wall -Werror %t |
| 4 | |
| 5 | /* This is a test of the various code modification hints that are |
| 6 | provided as part of warning or extension diagnostics. All of the |
| 7 | warnings will be fixed by -fixit, and the resulting file should |
| 8 | compile cleanly with -Werror -pedantic. */ |
| 9 | |
| 10 | int printf(char const *, ...); |
| 11 | |
| 12 | void test() { |
Tom Care | 876e994 | 2010-06-11 04:22:02 +0000 | [diff] [blame] | 13 | // Basic types |
| 14 | printf("%s", (int) 123); |
| 15 | printf("abc%0f", "testing testing 123"); |
Tom Care | 3bfc5f4 | 2010-06-09 04:11:11 +0000 | [diff] [blame] | 16 | printf("%u", (long) -12); |
Ted Kremenek | 13927a4 | 2010-06-16 21:23:04 +0000 | [diff] [blame] | 17 | printf("%p", 123); |
Ted Kremenek | 01cb1aa | 2010-06-17 01:12:20 +0000 | [diff] [blame] | 18 | printf("%c\n", "x"); |
| 19 | printf("%c\n", 1.23); |
Tom Care | 876e994 | 2010-06-11 04:22:02 +0000 | [diff] [blame] | 20 | |
| 21 | // Larger types |
Tom Care | 3bfc5f4 | 2010-06-09 04:11:11 +0000 | [diff] [blame] | 22 | printf("%+.2d", (unsigned long long) 123456); |
| 23 | printf("%1d", (long double) 1.23); |
Tom Care | 876e994 | 2010-06-11 04:22:02 +0000 | [diff] [blame] | 24 | |
| 25 | // Flag handling |
Tom Care | 45f9b7e | 2010-06-21 21:21:01 +0000 | [diff] [blame] | 26 | printf("%0+s", (unsigned) 31337); // 0 flag should stay |
Tom Care | 4c60219 | 2010-06-18 03:02:16 +0000 | [diff] [blame] | 27 | printf("%#p", (void *) 0); |
Tom Care | 45f9b7e | 2010-06-21 21:21:01 +0000 | [diff] [blame] | 28 | printf("% +f", 1.23); // + flag should stay |
| 29 | printf("%0-f", 1.23); // - flag should stay |
Tom Care | 876e994 | 2010-06-11 04:22:02 +0000 | [diff] [blame] | 30 | |
| 31 | // Positional arguments |
Tom Care | 3bfc5f4 | 2010-06-09 04:11:11 +0000 | [diff] [blame] | 32 | printf("%1$f:%2$.*3$f:%4$.*3$f\n", 1, 2, 3, 4); |
Tom Care | 4c60219 | 2010-06-18 03:02:16 +0000 | [diff] [blame] | 33 | |
| 34 | // Precision |
| 35 | printf("%10.5d", 1l); // (bug 7394) |
| 36 | printf("%.2c", 'a'); |
| 37 | |
| 38 | // Ignored flags |
| 39 | printf("%0-f", 1.23); |
| 40 | |
| 41 | // Bad length modifiers |
| 42 | printf("%hhs", "foo"); |
| 43 | printf("%1$zp", (void *)0); |
Tom Care | 3bfc5f4 | 2010-06-09 04:11:11 +0000 | [diff] [blame] | 44 | } |