This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: cpplib and a couple others: squelch -pedantic warnings
I also find this a little confusing.
Since we want something like the c++ const_cast<type>, perhaps we should
using something like:
__const_cast__(type)
Russ Allbery wrote:
>
> Kaveh R Ghazi <ghazi@caip.rutgers.edu> writes:
>
> > Let's please not give up so easily.
>
> > Both Mark and Gabriel mentioned they'd like the ability to explicitly
> > cast away const-ness without any warnings. The following tiny patch
> > allows you to write:
>
> >> const char *foo;
> >> free (__extension__ (char *) foo);
>
> > without any warnings, even from -Wcast-qual.
>
> I'm just an observer here, so feel free to ignore this comment (and I
> certainly don't know as much about gcc's philosophy or internals as most
> other people on this mailing list), but as a user of gcc I would find the
> above extremely confusing.
>
> It seems to be saying that casting a const char * to a char * is a gcc
> extension, and hence tagged with __extension__. I would expect
> __extension__ to be used primarily for those C constructs which may not be
> portable (and hence warrant a warning) but which the programmer knows may
> not be portable and doesn't care.
>
> Casting a const char * to a char * is quite portable, and doing so is not
> a gcc extension. It's just bad programming style under some rules of
> style and error checking, and there is therefore a warning in gcc for
> doing this that can be turned on. It does make some sense to me to have
> some way of tagging this as "yes, I know what I'm doing, don't warn about
> this" similar to the old lint annotations, given that gcc with warnings
> turned on is generally used as lint for free software projects, but I find
> __extension__ a very confusing way of doing that.
>
> --
> Russ Allbery (rra@stanford.edu) <http://www.eyrie.org/~eagle/>