This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/50662] New: Incorrect diagnostic returning non-const array pointer
- From: "Keith.S.Thompson at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 07 Oct 2011 23:36:38 +0000
- Subject: [Bug c/50662] New: Incorrect diagnostic returning non-const array pointer
- Auto-submitted: auto-generated
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50662
Bug #: 50662
Summary: Incorrect diagnostic returning non-const array pointer
Classification: Unclassified
Product: gcc
Version: 4.5.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: Keith.S.Thompson@gmail.com
Compiling the following program:
==========
typedef int this_type;
typedef int that_type[8];
static this_type this;
static that_type that;
static const this_type *this_func(void) {
return &this;
}
static const that_type *that_func(void) {
return &that; /* line 12 */
}
==========
produces the following error:
==========
$ gcc -c -std=c99 -pedantic-errors const_pointer.c
const_pointer.c: In function âthat_funcâ:
const_pointer.c:12:5: error: return from incompatible pointer type
==========
I believe that the return statement is valid. The return statement returns a
"that_type*" result in a function returning "const that_type*". There is no
potential violation of const-correctness.
Note that "this_func" does not trigger a diagnostic. I don't believe that the
fact that "this_type" is an integer type and "that_type" is an array type
should matter. In particular, there is no array-to-pointer decay.
This showed up in a question on stackoverflow.com:
http://stackoverflow.com/questions/7691295/return-from-incompatible-pointer-type-const-vs-non-const-c-gcc