https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70665
Bug ID: 70665
Summary: Seemingly incorrect warning for being const correct
with function pointers
Product: gcc
Version: 4.8.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: psusi at ubuntu dot com
Target Milestone: ---
void foo( const char *p );
void bar( char *p ) { foo( p ); }
This is perfectly acceptable and const correct since foo does not want write
access, but being given write access anyway is fine. I have run into a
seemingly incorrect warning though when calling such functions via pointer:
void foo( const char *p );
void bar( void (*fn)(char *p) );
bar( foo );
^^ generates warning about pointers not being compatible.
Apparently gcc thinks that when called via a pointer, it is not correct to pass
a writable pointer where only a read only one is needed.