2010-06-09 12:11:11 +08:00
|
|
|
// RUN: cp %s %t
|
2011-07-14 14:49:52 +08:00
|
|
|
// RUN: %clang_cc1 -triple x86_64-apple-macosx10.7.0 -pedantic -Wall -fixit %t || true
|
|
|
|
// RUN: %clang_cc1 -triple x86_64-apple-macosx10.7.0 -fsyntax-only -pedantic -Wall -Werror %t
|
|
|
|
// RUN: %clang_cc1 -triple x86_64-apple-macosx10.7.0 -E -o - %t | FileCheck %s
|
2010-06-09 12:11:11 +08:00
|
|
|
|
|
|
|
/* This is a test of the various code modification hints that are
|
|
|
|
provided as part of warning or extension diagnostics. All of the
|
|
|
|
warnings will be fixed by -fixit, and the resulting file should
|
|
|
|
compile cleanly with -Werror -pedantic. */
|
|
|
|
|
|
|
|
int printf(char const *, ...);
|
|
|
|
|
|
|
|
void test() {
|
2010-06-11 12:22:02 +08:00
|
|
|
// Basic types
|
|
|
|
printf("%s", (int) 123);
|
|
|
|
printf("abc%0f", "testing testing 123");
|
2010-06-09 12:11:11 +08:00
|
|
|
printf("%u", (long) -12);
|
2010-06-17 05:23:04 +08:00
|
|
|
printf("%p", 123);
|
2010-06-17 09:12:20 +08:00
|
|
|
printf("%c\n", "x");
|
|
|
|
printf("%c\n", 1.23);
|
2010-06-11 12:22:02 +08:00
|
|
|
|
|
|
|
// Larger types
|
2010-06-09 12:11:11 +08:00
|
|
|
printf("%+.2d", (unsigned long long) 123456);
|
|
|
|
printf("%1d", (long double) 1.23);
|
2010-06-11 12:22:02 +08:00
|
|
|
|
|
|
|
// Flag handling
|
2010-06-22 05:21:01 +08:00
|
|
|
printf("%0+s", (unsigned) 31337); // 0 flag should stay
|
2010-06-18 11:02:16 +08:00
|
|
|
printf("%#p", (void *) 0);
|
2010-06-22 05:21:01 +08:00
|
|
|
printf("% +f", 1.23); // + flag should stay
|
|
|
|
printf("%0-f", 1.23); // - flag should stay
|
2010-06-11 12:22:02 +08:00
|
|
|
|
|
|
|
// Positional arguments
|
2010-06-09 12:11:11 +08:00
|
|
|
printf("%1$f:%2$.*3$f:%4$.*3$f\n", 1, 2, 3, 4);
|
2010-06-18 11:02:16 +08:00
|
|
|
|
|
|
|
// Precision
|
|
|
|
printf("%10.5d", 1l); // (bug 7394)
|
|
|
|
printf("%.2c", 'a');
|
|
|
|
|
|
|
|
// Ignored flags
|
|
|
|
printf("%0-f", 1.23);
|
|
|
|
|
|
|
|
// Bad length modifiers
|
|
|
|
printf("%hhs", "foo");
|
|
|
|
printf("%1$zp", (void *)0);
|
2011-04-26 06:32:59 +08:00
|
|
|
|
|
|
|
// Perserve the original formatting for unsigned integers.
|
|
|
|
unsigned long val = 42;
|
|
|
|
printf("%X", val);
|
2010-06-09 12:11:11 +08:00
|
|
|
}
|
2011-04-26 06:32:59 +08:00
|
|
|
|
|
|
|
// Validate the fixes...
|
|
|
|
// CHECK: printf("%d", (int) 123);
|
|
|
|
// CHECK: printf("abc%s", "testing testing 123");
|
|
|
|
// CHECK: printf("%ld", (long) -12);
|
|
|
|
// CHECK: printf("%d", 123);
|
|
|
|
// CHECK: printf("%s\n", "x");
|
|
|
|
// CHECK: printf("%f\n", 1.23);
|
|
|
|
// CHECK: printf("%.2llu", (unsigned long long) 123456);
|
|
|
|
// CHECK: printf("%1Lf", (long double) 1.23);
|
|
|
|
// CHECK: printf("%0u", (unsigned) 31337);
|
|
|
|
// CHECK: printf("%p", (void *) 0);
|
|
|
|
// CHECK: printf("%+f", 1.23);
|
|
|
|
// CHECK: printf("%-f", 1.23);
|
|
|
|
// CHECK: printf("%1$d:%2$.*3$d:%4$.*3$d\n", 1, 2, 3, 4);
|
|
|
|
// CHECK: printf("%10.5ld", 1l);
|
|
|
|
// CHECK: printf("%c", 'a');
|
|
|
|
// CHECK: printf("%-f", 1.23);
|
|
|
|
// CHECK: printf("%s", "foo");
|
|
|
|
// CHECK: printf("%1$p", (void *)0);
|
|
|
|
// CHECK: printf("%lX", val);
|