This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: Add a __nowarn__ keyword
On 09/08/07, Daniel Jacobowitz <drow@false.org> wrote:
> On Thu, Aug 09, 2007 at 10:19:27AM -0400, Kaveh R. GHAZI wrote:
> > Maybe I don't understand your question, but the keyword vs pragma styles
> > clearly do not work in the same set of cases. At least, if by "cases" you
> > mean: locations in code where they can be placed and affect. If by
> > "cases" you mean: which warnings they can effectively silence, that I
> > don't know. I think both mechanisms have holes in warning coverage that
> > don't necessarily overlap.
> >
> > Which interpretation did you mean?
>
> All of those. There shouldn't be anywhere you could put __nowarn__
> that you couldn't put a _Pragma, since that is a preprocessing
> directive, not part of the C grammar. Nor can I see why one would
> work for some warning that the other did not work for. The natural
> usage style is somewhat different, depending on how the pragma is
> defined... and obviously the implementation would be very different.
>
There is a fundamental difference with the current implementations:
__nowarn__ does an implicit push/pop of settings around the element
(declaration, statement, etc) that follows it, while the _Pragma does
not: changed settings will keep their values until the end of the file
or next _Pragma.
Another difference is that _Pragma has no "restore" or "default"
method to restore the command-line settings. But I think that would be
easier to implement. Full push/pop capabilities, on the other hand,
would be hard (as DJ has explained above).
Also, in principle there is no reason why one would work for some
warning that the other did not work for. However, the __nowarn__ patch
is modifying inhibit_warnings which affects all warnings while _Pragma
implementation modifies the status of each named warning and it cannot
affect those messages emitted by warn(0, "whatever"). Yet,
given the current implementation, #pragma GCC diagnostics warning "-w"
should do the trick, although once you do that, you cannot disable it.
Is it any clearer now?
Cheers,
Manuel.