This is the mail archive of the
mailing list for the GCC project.
Re: Selective warnings
- To: Philipp Thomas <pthomas at suse dot de>
- Subject: Re: Selective warnings
- From: Geoff Keating <geoffk at cygnus dot com>
- Date: 21 Jun 2000 19:48:05 -0700
- CC: gcc at gcc dot gnu dot org
- References: <20000622041546.A16018@Jeffreys.suse.de>
Philipp Thomas <firstname.lastname@example.org> writes:
> And that's the reason Uniforum came up with a different proposal, which Sun
> implemented and which the FSF folowed when implementing the gettext
> interface. For gettext, the passed message is the unique id.
> Then the programmer could switch off a specific warning with #pragma.
> What I have to do now is to think about a way to implement this, foremost
> how to implement a warning map. My first guess would be a bitmap where the
> warning option is the index. Such a map would then also make it possible to
> implement pushing/poping warning 'states'.
As an alternative, why not simply keep a table of strings or regular
expressions, and just check each warning against the table before
printing it? pushing/popping the warning states could be done by just
keeping track of the earlier context of the table.
I would imagine something like
"#pragma" "gcc" "nowarn" [ "line" expression ] [ string ]
where, for instance,
#pragma gcc nowarn "`t' might be used uninitialized"
printf ("%d\n", t);
suppresses one of the two warnings in the program under -Wall, and
#pragma gcc nowarn line __LINE__+1
#pragma gcc nowarn line __LINE__+1 "implicit declaration"
printf ("%d\n", t);
suppresses them both individually (they are:
t.c: In function `main':
t.c:4: warning: implicit declaration of function `printf'
t.c:3: warning: `t' might be used uninitialized in this function
The only design decisions are:
- whether the #pragma should match against only the untranslated
message, or against both. (You certainly want to match against the
untranslated version so that programs don't have to have zillions of
#pragma commands one for each language).
- should the 'string' be matched explicitly, or should it be a regexp?
I think a regexp, but you could start by just doing a substring match.
You would want to keep a per-line table with a hashtable (and a
whole-program table for when the line is not specified) so that it
doesn't become too slow to match in programs with thousands of
This flows naturally into a toplevel option like
--nowarn "implicit declaration" .
- Geoffrey Keating <email@example.com>