aboutsummaryrefslogtreecommitdiff
path: root/test/Sema/format-strings-fixit.c
diff options
context:
space:
mode:
authorTom Care <tcare@apple.com>2010-06-09 04:11:11 +0000
committerTom Care <tcare@apple.com>2010-06-09 04:11:11 +0000
commit3bfc5f49e0e37e235bb0d33bcbcb36af9d1f84ab (patch)
tree960b5940e2de8f95be43445f90a38040dcb0eb00 /test/Sema/format-strings-fixit.c
parent5a57efd7bf88a4a13018e0471ded8063a4abe8af (diff)
Added FixIt support to printf format string checking.
- Refactored LengthModifier to be a class. - Added toString methods in all member classes of FormatSpecifier. - FixIt suggestions keep user specified flags unless incorrect. Limitations: - The suggestions are not conversion specifier sensitive. For example, if we have a 'pad with zeroes' flag, and the correction is a string conversion specifier, we do not remove the flag. Clang will warn us on the next compilation. A test/Sema/format-strings-fixit.c M include/clang/Analysis/Analyses/PrintfFormatString.h M lib/Analysis/PrintfFormatString.cpp M lib/Sema/SemaChecking.cpp git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@105680 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/Sema/format-strings-fixit.c')
-rw-r--r--test/Sema/format-strings-fixit.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/test/Sema/format-strings-fixit.c b/test/Sema/format-strings-fixit.c
new file mode 100644
index 0000000000..ba38973049
--- /dev/null
+++ b/test/Sema/format-strings-fixit.c
@@ -0,0 +1,20 @@
+// RUN: cp %s %t
+// RUN: %clang_cc1 -pedantic -Wall -fixit %t || true
+// RUN: %clang_cc1 -fsyntax-only -pedantic -Wall -Werror %t
+
+/* 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() {
+ printf("%0s", (int) 123);
+ printf("abc%f", "testing testing 123");
+ printf("%u", (long) -12);
+ printf("%+.2d", (unsigned long long) 123456);
+ printf("%1d", (long double) 1.23);
+ printf("%Ld", (long double) -4.56);
+ printf("%1$f:%2$.*3$f:%4$.*3$f\n", 1, 2, 3, 4);
+}