This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: c/9070: Improper warning when casting from pointer to non-constarray to const
- From: "Joseph S. Myers" <jsm28 at cam dot ac dot uk>
- To: <126411 at bugs dot debian dot org>
- Cc: <gcc-gnats at gcc dot gnu dot org>, <debian-gcc at lists dot debian dot org>, <gcc-bugs at gcc dot gnu dot org>, <agthorr at barsoom dot org>
- Date: Fri, 27 Dec 2002 22:38:40 +0000 (GMT)
- Subject: Re: c/9070: Improper warning when casting from pointer to non-constarray to const
On Fri, 27 Dec 2002, Matthias Klose wrote:
> gcc generates a warning for the following test program, that I believe
> is inappropriate. The warning is that it cannot implicitly cast from
> (foo *) to (const foo *). This occurs when foo is an array type. The
> sample program compiles without warnings if you remove the "const"
> keyword, or if you remove the [16] making foo an array.
It is an assignment from "pointer to array[16] of char" to "pointer to
array[16] of const char" rather than to "pointer to const array[16] of
char", by virtue of the requirement (6.7.3#8 in C99) that a type qualifier
applied to an array type applies instead to the element type. Thus the
case of 6.5.16.1#1 that would be matched in the case of pointers to
nonarray types adding qualifiers is not matched, thus the warning.
--
Joseph S. Myers
jsm28@cam.ac.uk