This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/70665] New: Seemingly incorrect warning for being const correct with function pointers
- From: "psusi at ubuntu dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 14 Apr 2016 13:18:56 +0000
- Subject: [Bug c/70665] New: Seemingly incorrect warning for being const correct with function pointers
- Auto-submitted: auto-generated
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.