Add a __nowarn__ keyword
Kaveh R. GHAZI
ghazi@caip.rutgers.edu
Wed Aug 8 19:31:00 GMT 2007
On Wed, 8 Aug 2007, Paolo Bonzini wrote:
> > The warnings (messages!) that are not modifiable are those that don't
> > have the first argument of warn() appropriately set. So if that
> > message is emitted by warn(0, "cast discards...") instead of
> > warn(OPT_Wcast_qual, "cast discards...") that is a bug and it will be
> > really good to fix it.
>
> I believe these were preapproved, weren't they?
>
> >> In addition to what he said,
> >> you also can't use #pragma in a macro definition.
>
> You can, it's _Pragma("foo").
> Paolo
(Ok, imagine I just had a head-smacking "Doh!" moment.)
So this is encouraging, I added OPT_Wcast_qual to the warning statement
and now it obeys the #pragma (or _Pragma). However I'm still having one
last problem. The pragma interface is still on/off, not push/pop. I.e.:
#pragma GCC diagnostic ignored "-Wcast-qual"
extern __inline void *CONST_CAST(const void *cv)
{
return (void *)cv;
}
//#pragma GCC diagnostic error "-Wcast-qual"
void foo (const void *cv)
{
void *v = CONST_CAST(cv); // WARNING1
void *v2 = (void *)cv; // WARNING2
}
Assuming you've corrected the missing OPT_Wcast_qual in c-typeck.c, if you
compile the above with -Wcast-qual -Werror, the code correctly avoids the
warnings on the line marked WARNING1. However we should still get a
warning for WARNING2 but we don't. I believe the pragma has changed the
behavior of gcc for the rest of the entire file. There is no "pop" at the
end of the inline function CONST_CAST.
In order to see WARNING2, I have to uncomment the second pragma. But this
is bad IMHO because it overrides the command line. Assuming the inline
CONST_CAST function is defined in say system.h every file that includes it
will get -Wcast-qual hardcoded on. I don't think this is desirable for
gcc or other project that start to use this mechanism.
--Kaveh
--
Kaveh R. Ghazi ghazi@caip.rutgers.edu
More information about the Gcc-patches
mailing list