gcc Warnings.

Sharoni, Rani rani.sharoni@intel.com
Thu Apr 27 03:46:00 GMT 2000


Hello.

I Want to report, for my understanding, a Warning report incompleteness.

Compiler -  gcc version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release).
Platform  - Linux 2.2.12-20smp GenuineIntel Pentium_III_599 i686

The problem regards to the Conditional Operator ?: Conversion.

According to ANSI-C:
  If one operand is a pointer to void or a qualified version of void, in
which case the result type is a
  pointer to an appropriately qualified version of void.

According to the GCC manual:
`-Wcast-qual'
     Warn whenever a pointer is cast so as to remove a type qualifier  from
the target type.
     For example, warn if a `const char *' is cast to an ordinary `char *'.


The problem: (When compiling with gcc -Wcast-qual -ansi -pedantic)
  If one of the second or third part of the ?: is of type void * and the
other is const type1 *
  And the assignment is to type2 *  (no const) - then no warning message is
generated.
  I believe That  "warning: cast discards `const' from pointer target type"
should be produced. 
  (type1 and type2 are some legal types - for example int and char)

Example:
  Compile the attached file (gcc -c Wcast-qual-bug.c -Wcast-qual -ansi
-pedantic).


 <<Wcast-qual-bug.c>> 
My compilation result output file:

 <<Wcast-qual-bug.Warn>> 

Rani Sharoni.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: Wcast-qual-bug.c
Type: text/x-c
Size: 290 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-bugs/attachments/20000427/c3dc29d6/attachment.bin>
-------------- next part --------------
#gcc -c Wcast-qual-bug.c -Wcast-qual -ansi -pedantic

Wcast-qual-bug.c: In function `main':
Wcast-qual-bug.c:11: warning: cast discards `const' from pointer target type


More information about the Gcc-bugs mailing list