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: unassig...@gcc.gnu.org
        ReportedBy: keith.s.thomp...@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

Reply via email to