Patch: check formats in C++ as C94
Joseph S. Myers
jsm28@cam.ac.uk
Sun Jun 3 09:19:00 GMT 2001
This patch fixes the pedantic format checking for C++ to check
according to C94 - i.e., to accept %lc, %ls, %l[.
Bootstrapped with no regressions on i686-pc-linux-gnu. I believe this
is the correct standard version, and if so this is a regression since
2.95 accepted %ls in C++ (and C) with -pedantic, but could someone
from the C++ side review this?
2001-06-03 Joseph S. Myers <jsm28@cam.ac.uk>
* c-format.c (CPLUSPLUS_STD_VER): Define to STD_C94.
2001-06-03 Joseph S. Myers <jsm28@cam.ac.uk>
* g++.old-deja/g++.warn/format1.C: New test.
--- c-format.c.orig Sat Mar 3 12:29:29 2001
+++ c-format.c Sun Jun 3 12:28:32 2001
@@ -474,7 +474,7 @@
/* The C standard version C++ is treated as equivalent to
or inheriting from, for the purpose of format features supported. */
-#define CPLUSPLUS_STD_VER STD_C89
+#define CPLUSPLUS_STD_VER STD_C94
/* The C standard version we are checking formats against when pedantic. */
#define C_STD_VER ((int)(c_language == clk_cplusplus \
? CPLUSPLUS_STD_VER \
--- testsuite/g++.old-deja/g++.warn/format1.C.orig Mon Mar 26 23:57:02 2001
+++ testsuite/g++.old-deja/g++.warn/format1.C Sun Jun 3 11:35:31 2001
@@ -0,0 +1,15 @@
+// Test that formats get checked according to C94.
+// Origin: Joseph Myers <jsm28@cam.ac.uk>.
+// Build don't link:
+// Special g++ Options: -ansi -pedantic -Wformat
+
+#include <cstdio>
+
+void
+foo (int i, int *ip, __WINT_TYPE__ lc, wchar_t *ls)
+{
+ std::printf ("%d%ls%lc\n", i, ls, lc);
+ std::printf ("%d", ls); // WARNING - format
+ std::scanf ("%d%lc%ls%l[abc]", ip, ls, ls, ls);
+ std::scanf ("%hd", ip); // WARNING - format
+}
--
Joseph S. Myers
jsm28@cam.ac.uk
More information about the Gcc-patches
mailing list