This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/62198] New: spurious warning - initialization discards qualifier from pointer target type for pointer to array
- From: "gary at intrepid dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 20 Aug 2014 05:42:31 +0000
- Subject: [Bug c/62198] New: spurious warning - initialization discards qualifier from pointer target type for pointer to array
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62198
Bug ID: 62198
Summary: spurious warning - initialization discards qualifier
from pointer target type for pointer to array
Product: gcc
Version: 5.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: gary at intrepid dot com
Although this bug is filed against the 5.0 trunk, it can be duplicated with at
least 4.8.3.
Given:
$ cat q.c
typedef unsigned long size_t;
extern const void *alloc (size_t);
int main()
{
const int (*X0)[10] = alloc (10 * sizeof (int));
return !X0;
}
When compiled with gcc 4.8.3 the following warning is issued:
$ gcc -fpreprocessed -c q.c
q.c: In function âmainâ:
q.c:7:25: warning: initialization discards âconstâ qualifier from pointer
target type [enabled by default]
const int (*X0)[10] = alloc (10 * sizeof (int));
^
Same thing for GCC 5.0 (trunk version 214178):
$ xgcc -fpreprocessed -c q.c
q.c: In function âmainâ:
q.c:7:25: warning: initialization discards âconstâ qualifier from pointer
target type [-Wdiscarded-qualifiers]
const int (*X0)[10] = alloc (10 * sizeof (int));
^
Clang 3.4 issues no warning:
$ clang -Wall -pedantic -Wextra -c q.c
<no output>
Given that the qualifier 'const' is associated with the array's element type,
it seems that the front end should derive the qualifier from the element type
when it is the target type of a declared pointer, before making the "discards
qualifier" check.