This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: -Wcast-qual and casting away
- From: Andreas Schwab <schwab at linux-m68k dot org>
- To: Ian Lance Taylor <iant at google dot com>
- Cc: gcc at gcc dot gnu dot org
- Date: Thu, 21 May 2009 13:50:18 +0200
- Subject: Re: -Wcast-qual and casting away
- References: <m3r5yjxcpw.fsf@google.com>
Ian Lance Taylor <iant@google.com> writes:
> Consider this C/C++ program:
>
> extern void **f1();
> void f2(const char *p) { *(const void **)f1() = p; }
>
> If I compile this program with g++ -Wcast-qual, I get this:
>
> foo2.cc:2: warning: cast from type âvoid**â to type âconst void**â casts away qualifiers
In a sense this warning is actually correct: this is storing a const
char * into a void * object, which is where the qualifier is lost. IMHO
having a warning for this questionable operation is a good thing.
Andreas.
--
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."