Newer gcc silently accepts mixing C Code and Declarations
Michael Culbertson
Michael.J.Culbertson at wheaton.edu
Sun Jul 6 03:28:35 CDT 2003
> Date: Wed, 2 Jul 2003 23:25:35 +0200
> From: Christian Stimming <stimming at tuhh.de>
> Subject: Newer gcc silently accepts mixing C Code and Declarations
> So what do we do? First of all, if anybody happens to run a non-gcc3.3 and
> discovers such a syntax error, then please don't start flaming the gcc3.3
> folks but please simply go ahead and fix that. Second, does anyone know some
> secret gcc switch that might enable again the detection of that problem? If
> there is none, then, well, what do people think about making gnucash
> - -pedantic proof... or do we simply live with those errors every now and then?
Below is a gcc 3.3 patch that adds a -Wmixed_declarations switch to spit
out a warning for mixed declarations and code in C89 mode. I haven't
tested it thoroughly, but it should generate the warning anywhere
-pedantic would, and it works in a simple test case.
Enjoy,
Michael Culbertson
-------------- Begin GCC 3.3 Patch --------------------
--- c-parse.c-orig Sat Jul 5 18:00:17 2003
+++ c-parse.c Sat Jul 5 18:01:00 2003
@@ -3991,7 +3991,7 @@
break;}
case 431:
#line 1929 "c-parse.y"
-{ if (pedantic && !flag_isoc99)
+{ if ((pedantic || warn_mixed_declarations) && !flag_isoc99)
pedwarn ("ISO C89 forbids mixed declarations and code"); ;
break;}
case 446:
--- c-parse.in-orig Sat Jul 5 17:59:49 2003
+++ c-parse.in Sat Jul 5 18:00:11 2003
@@ -2032,7 +2032,7 @@
lineno_stmt_decl_or_labels_ending_decl:
lineno_decl
| lineno_stmt_decl_or_labels_ending_stmt lineno_decl
- { if (pedantic && !flag_isoc99)
+ { if ((pedantic || warn_mixed_declarations) && !flag_isoc99)
pedwarn ("ISO C89 forbids mixed declarations and code"); }
| lineno_stmt_decl_or_labels_ending_decl lineno_decl
| lineno_stmt_decl_or_labels_ending_error lineno_decl
--- c-parse.y-orig Sat Jul 5 17:59:08 2003
+++ c-parse.y Sat Jul 5 17:59:40 2003
@@ -1926,7 +1926,7 @@
lineno_stmt_decl_or_labels_ending_decl:
lineno_decl
| lineno_stmt_decl_or_labels_ending_stmt lineno_decl
- { if (pedantic && !flag_isoc99)
+ { if ((pedantic || warn_mixed_declarations) && !flag_isoc99)
pedwarn ("ISO C89 forbids mixed declarations and code"); }
| lineno_stmt_decl_or_labels_ending_decl lineno_decl
| lineno_stmt_decl_or_labels_ending_error lineno_decl
--- flags.h-orig Sat Jul 5 17:58:30 2003
+++ flags.h Sat Jul 5 17:58:56 2003
@@ -189,6 +189,10 @@
extern int warn_strict_aliasing;
+/* Nonzero means warn about mixed declarations and code in C89 mode */
+
+extern int warn_mixed_declarations;
+
/* Nonzero if generating code to do profiling. */
extern int profile_flag;
--- toplev.c-orig Sat Jul 5 17:55:14 2003
+++ toplev.c Sun Jul 6 02:15:11 2003
@@ -1500,6 +1500,10 @@
int warn_strict_aliasing;
+/* Nonzero means warn about mixed declarations and code in C89 mode */
+
+int warn_mixed_declarations;
+
/* Likewise for -W. */
static const lang_independent_options W_options[] =
@@ -1547,7 +1551,9 @@
{"missing-noreturn", &warn_missing_noreturn, 1,
N_("Warn about functions which might be candidates for attribute noreturn") },
{"strict-aliasing", &warn_strict_aliasing, 1,
- N_ ("Warn about code which might break the strict aliasing rules") }
+ N_ ("Warn about code which might break the strict aliasing rules") },
+ {"mixed-declarations", &warn_mixed_declarations, 1,
+ N_("Warn about mixed declarations and code in C89 mode") }
};
void
More information about the gnucash-devel
mailing list