https://gcc.gnu.org/bugzilla/show_bug.cgi?id=38354

--- Comment #4 from Adam Warner <adam at consulting dot net.nz> ---
Why can a compile-time array of 32-bit function pointers (compatible with the
non-large code model) be compiled using g++ but not gcc?


$ g++ -fpermissive computable_at_load_time.c
computable_at_load_time.c:9:41: warning: invalid conversion from ‘void (*)()’
to ‘uint32_t {aka unsigned int}’ [-fpermissive]
 uint32_t computable_at_load_time_a[]={fn};
                                         ^
[No errors and line 10 compiles without warning]


$ gcc -fpermissive computable_at_load_time.c
cc1: warning: command line option ‘-fpermissive’ is valid for C++/ObjC++ but
not for C
computable_at_load_time.c:9:1: warning: initialization makes integer from
pointer without a cast
 uint32_t computable_at_load_time_a[]={fn};
 ^
computable_at_load_time.c:9:1: warning: (near initialization for
‘computable_at_load_time_a[0]’)
computable_at_load_time.c:9:1: error: initializer element is not computable at
load time
computable_at_load_time.c:9:1: error: (near initialization for
‘computable_at_load_time_a[0]’)
computable_at_load_time.c:10:1: error: initializer element is not constant
 uint32_t computable_at_load_time_b[]={(uint32_t) (ptrdiff_t) fn};
 ^
computable_at_load_time.c:10:1: error: (near initialization for
‘computable_at_load_time_b[0]’)


The claim that the initializer element is not computable at load time is
spurious.

Permitting this code to compile when the -fpermissive flag is supplied seems
reasonable: "-fpermissive: Downgrade some diagnostics about nonconformant code
from errors to warnings. Thus, using -fpermissive allows some nonconforming
code to compile."

Reply via email to