c/9070: Improper warning when casting from pointer to non-const array to const
Joseph S. Myers
jsm28@cam.ac.uk
Fri Dec 27 14:46:00 GMT 2002
The following reply was made to PR c/9070; it has been noted by GNATS.
From: "Joseph S. Myers" <jsm28@cam.ac.uk>
To: <126411@bugs.debian.org>
Cc: <gcc-gnats@gcc.gnu.org>, <debian-gcc@lists.debian.org>,
<gcc-bugs@gcc.gnu.org>, <agthorr@barsoom.org>
Subject: Re: c/9070: Improper warning when casting from pointer to non-const
array to const
Date: Fri, 27 Dec 2002 22:38:40 +0000 (GMT)
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
More information about the Gcc-prs
mailing list