This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: named warnings & individual warning control
> Note that you could get some of the same benefits by just adding the
> #pragmas for the current warning groups,
Partial patch (proof of concept, missing docs, changelog, etc), only
works for options with the Var() syntax... Comments?
I thought of extending this to call the handle_option langhook for
non-Var entries but it was difficult to determine if/when that's safe.
Also, -O[23] tends to confuse this as they defer the use of warning
flags until after the whole file is parsed, so pragmas between
function definitions don't do what you expect :-(
Index: c-pragma.c
===================================================================
RCS file: /greed/dj/gnu/gcc/repository/gcc/gcc/c-pragma.c,v
retrieving revision 1.71
diff -p -C2 -r1.71 c-pragma.c
*** c-pragma.c 22 Jun 2004 06:51:50 -0000 1.71
--- c-pragma.c 24 Jun 2004 22:04:58 -0000
*************** Software Foundation, 59 Temple Place - S
*** 36,39 ****
--- 36,40 ----
#include "tm_p.h"
#include "target.h"
+ #include "opts.h"
#define GCC_BAD(msgid) do { warning (msgid); return; } while (0)
*************** c_register_pragma (const char *space, co
*** 576,579 ****
--- 577,634 ----
}
+ static void
+ handle_pragma_gcc_warning (cpp_reader *dummy ATTRIBUTE_UNUSED)
+ {
+ tree type, x;
+ const char *ts;
+ char *ent;
+ int len, flag_val;
+ unsigned int i;
+ static int list_printed = 0;
+
+ if (c_lex (&type) != CPP_STRING)
+ {
+ warning ("malformed #pragma GCC warning, ignored");
+ return;
+ }
+ ts = TREE_STRING_POINTER (type);
+ if (c_lex (&x) != CPP_EOF)
+ warning ("junk at end of #pragma GCC warning");
+
+ len = strlen (ts);
+ ent = (char *) xmalloc (len + 3);
+ ent[0] = '-';
+ ent[1] = 'W';
+ if (strncmp (ts, "no-", 3) == 0)
+ {
+ flag_val = 0;
+ strcpy (ent+2, ts+3);
+ }
+ else
+ {
+ flag_val = 1;
+ strcpy (ent+2, ts);
+ }
+
+ for (i=0; i<cl_options_count; i++)
+ if (cl_options[i].flag_var
+ && strcmp (cl_options[i].opt_text, ent) == 0)
+ {
+ *cl_options[i].flag_var = flag_val;
+ return;
+ }
+ warning ("pragma GCC warning: `%s' not found, ignored", ent);
+
+ if (list_printed)
+ return;
+ list_printed = 1;
+
+ inform ("Available warnings are:");
+ for (i=0; i<cl_options_count; i++)
+ if (cl_options[i].flag_var
+ && strncmp (cl_options[i].opt_text, "-W", 2) == 0)
+ inform (" %s", cl_options[i].opt_text);
+ }
+
/* Set up front-end pragmas. */
void
*************** init_pragma (void)
*** 595,598 ****
--- 650,655 ----
REGISTER_TARGET_PRAGMAS ();
#endif
+
+ c_register_pragma ("GCC", "warning", handle_pragma_gcc_warning);
}