This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Patch to restore format checking of warning(), error(), etc.
- From: "Joseph S. Myers" <jsm at polyomino dot org dot uk>
- To: gcc-patches at gcc dot gnu dot org
- Date: Thu, 24 Jun 2004 19:06:00 +0000 (UTC)
- Subject: Patch to restore format checking of warning(), error(), etc.
The format attributes were removed from warning, pedwarn, error and
sorry some time ago because of questions over the use of %D (a
front-end format, but implemented in multiple front-ends) in
non-front-end code. As toplev.h knows from whether GCC_DIAG_STYLE is
defined whether it is being included in a front end file, it's easy to
re-enable these attributes for front end code, where this problem
doesn't arise, while leaving them disabled for other code where the
formally unsafe %D formats are being used. This patch does so, fixing
a format warning in the C++ front end this shows up in the process.
Bootstrapped with no regressions on i686-pc-linux-gnu. OK to commit?
2004-06-24 Joseph S. Myers <jsm@polyomino.org.uk>
* toplev.h (NO_FRONT_END_DIAG, ATTRIBUTE_GCC_FE_DIAG): Define.
(warning, error, pedwarn, sorry): Use ATTRIBUTE_GCC_FE_DIAG.
cp:
2004-06-24 Joseph S. Myers <jsm@polyomino.org.uk>
* decl.c (check_tag_decl): Name redeclared type in diagnostic.
--
Joseph S. Myers http://www.srcf.ucam.org/~jsm28/gcc/
jsm@polyomino.org.uk (personal mail)
jsm28@gcc.gnu.org (Bugzilla assignments and CCs)
diff -rupN gcc.orig/cp/decl.c gcc/cp/decl.c
--- gcc.orig/cp/decl.c 2004-06-24 08:28:42.000000000 +0000
+++ gcc/cp/decl.c 2004-06-24 14:51:26.000000000 +0000
@@ -3420,7 +3420,7 @@ check_tag_decl (cp_decl_specifier_seq *d
else if (declspecs->redefined_builtin_type)
{
if (!in_system_header)
- pedwarn ("redeclaration of C++ built-in type",
+ pedwarn ("redeclaration of C++ built-in type %qT",
declspecs->redefined_builtin_type);
return NULL_TREE;
}
diff -rupN gcc.orig/toplev.h gcc/toplev.h
--- gcc.orig/toplev.h 2004-06-16 08:10:42.000000000 +0000
+++ gcc/toplev.h 2004-06-22 17:22:03.000000000 +0000
@@ -45,23 +45,32 @@ extern void _fatal_insn (const char *, r
style, use the generic one. */
#ifndef GCC_DIAG_STYLE
#define GCC_DIAG_STYLE __gcc_diag__
+#define NO_FRONT_END_DIAG
#endif
/* None of these functions are suitable for ATTRIBUTE_PRINTF, because
each language front end can extend them with its own set of format
- specifiers. We must use custom format checks. */
+ specifiers. We must use custom format checks. Note that at present
+ the front-end %D specifier is used in non-front-end code with some
+ functions, and those formats can only be checked in front-end code. */
#if GCC_VERSION >= 3005
#define ATTRIBUTE_GCC_DIAG(m, n) __attribute__ ((__format__ (GCC_DIAG_STYLE, m, n))) ATTRIBUTE_NONNULL(m)
+#ifdef NO_FRONT_END_DIAG
+#define ATTRIBUTE_GCC_FE_DIAG(m, n) ATTRIBUTE_NONNULL(m)
+#else
+#define ATTRIBUTE_GCC_FE_DIAG(m, n) __attribute__ ((__format__ (GCC_DIAG_STYLE, m, n))) ATTRIBUTE_NONNULL(m)
+#endif
#else
#define ATTRIBUTE_GCC_DIAG(m, n) ATTRIBUTE_NONNULL(m)
+#define ATTRIBUTE_GCC_FE_DIAG(m, n) ATTRIBUTE_NONNULL(m)
#endif
extern void internal_error (const char *, ...) ATTRIBUTE_GCC_DIAG(1,2)
ATTRIBUTE_NORETURN;
-extern void warning (const char *, ...);
-extern void error (const char *, ...);
+extern void warning (const char *, ...) ATTRIBUTE_GCC_FE_DIAG(1,2);
+extern void error (const char *, ...) ATTRIBUTE_GCC_FE_DIAG(1,2);
extern void fatal_error (const char *, ...) ATTRIBUTE_GCC_DIAG(1,2)
ATTRIBUTE_NORETURN;
-extern void pedwarn (const char *, ...);
-extern void sorry (const char *, ...);
+extern void pedwarn (const char *, ...) ATTRIBUTE_GCC_FE_DIAG(1,2);
+extern void sorry (const char *, ...) ATTRIBUTE_GCC_FE_DIAG(1,2);
extern void inform (const char *, ...) ATTRIBUTE_GCC_DIAG(1,2);
extern void rest_of_decl_compilation (tree, const char *, int, int);