blob: f74ce4e81acff6206721cd3516b9b20a4a46cc82 [file] [log] [blame]
Tom Care3bfc5f42010-06-09 04:11:11 +00001// RUN: cp %s %t
2// RUN: %clang_cc1 -pedantic -Wall -fixit %t || true
3// RUN: %clang_cc1 -fsyntax-only -pedantic -Wall -Werror %t
Tom Care4c602192010-06-18 03:02:16 +00004// XFAIL: *
5// FIXME: Some of these tests currently fail due to a bug in the HighlightRange
6// function in lib/Frontend/TextDiagnosticPrinter.cpp.
Tom Care3bfc5f42010-06-09 04:11:11 +00007
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
13int printf(char const *, ...);
14
15void test() {
Tom Care876e9942010-06-11 04:22:02 +000016 // Basic types
17 printf("%s", (int) 123);
18 printf("abc%0f", "testing testing 123");
Tom Care3bfc5f42010-06-09 04:11:11 +000019 printf("%u", (long) -12);
Ted Kremenek13927a42010-06-16 21:23:04 +000020 printf("%p", 123);
Ted Kremenek01cb1aa2010-06-17 01:12:20 +000021 printf("%c\n", "x");
22 printf("%c\n", 1.23);
Tom Care876e9942010-06-11 04:22:02 +000023
24 // Larger types
Tom Care3bfc5f42010-06-09 04:11:11 +000025 printf("%+.2d", (unsigned long long) 123456);
26 printf("%1d", (long double) 1.23);
Tom Care876e9942010-06-11 04:22:02 +000027
28 // Flag handling
29 printf("%0+s", (unsigned) 31337); // flags should stay
30 printf("%0f", "test"); // flag should be removed
Tom Care4c602192010-06-18 03:02:16 +000031 printf("%#p", (void *) 0);
Tom Care876e9942010-06-11 04:22:02 +000032
33 // Positional arguments
Tom Care3bfc5f42010-06-09 04:11:11 +000034 printf("%1$f:%2$.*3$f:%4$.*3$f\n", 1, 2, 3, 4);
Tom Care4c602192010-06-18 03:02:16 +000035
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 Care3bfc5f42010-06-09 04:11:11 +000046}