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