This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/83584] New: "ISO C forbids conversion of object pointer to function pointer type" -- no, not really
- 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: Mon, 25 Dec 2017 00:24:04 +0000
- Subject: [Bug c/83584] New: "ISO C forbids conversion of object pointer to function pointer type" -- no, not really
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83584
Bug ID: 83584
Summary: "ISO C forbids conversion of object pointer to
function pointer type" -- no, not really
Product: gcc
Version: 7.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: Keith.S.Thompson at gmail dot com
Target Milestone: ---
$ gcc --version
gcc (GCC) 7.1.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ cat c.c
int main(void) {
typedef void (func)(void);
void *ptr = 0;
func *fptr = (func*)ptr;
}
$ gcc -std=c11 -pedantic-errors -c c.c
c.c: In function ‘main’:
c.c:4:18: error: ISO C forbids conversion of object pointer to function pointer
type [-Wpedantic]
func *fptr = (func*)ptr;
^
$
In fact the conversion does not violate any syntax rule or constraint,
though its behavior is undefined.
N1570 6.5.4 p2-4 specifies the constraints on the cast operator. It
permits conversions between scalar types (which include pointer types). p4
specifically forbids conversions between pointer types and floating-point
types. There's nothing about pointer-to-function types.
6.3.2.3 defines the semantics of pointer conversions. It says nothing
about conversions between void* and pointer-to-function types -- which
means the behavior is undefined by omission.
The diagnostic should be a non-fatal warning when "-pedantic-errors"
is used, and it should be rephrased.
- Follow-Ups:
- [Bug c/83584] "ISO C forbids conversion of object pointer to function pointer type" -- no, not really
- From: Keith.S.Thompson at gmail dot com
- [Bug c/83584] "ISO C forbids conversion of object pointer to function pointer type" -- no, not really
- From: pinskia at gcc dot gnu.org
- [Bug c/83584] "ISO C forbids conversion of object pointer to function pointer type" -- no, not really
- From: pinskia at gcc dot gnu.org
- [Bug c/83584] "ISO C forbids conversion of object pointer to function pointer type" -- no, not really
- From: Keith.S.Thompson at gmail dot com
- [Bug c/83584] "ISO C forbids conversion of object pointer to function pointer type" -- no, not really
- From: schwab at linux-m68k dot org
- [Bug c/83584] "ISO C forbids conversion of object pointer to function pointer type" -- no, not really
- From: Keith.S.Thompson at gmail dot com
- [Bug c/83584] "ISO C forbids conversion of object pointer to function pointer type" -- no, not really
- From: Keith.S.Thompson at gmail dot com
- [Bug c/83584] "ISO C forbids conversion of object pointer to function pointer type" -- no, not really
- From: manu at gcc dot gnu.org
- [Bug c/83584] "ISO C forbids conversion of object pointer to function pointer type" -- no, not really
- From: Keith.S.Thompson at gmail dot com
- [Bug c/83584] "ISO C forbids conversion of object pointer to function pointer type" -- no, not really
- From: pinskia at gcc dot gnu.org
- [Bug c/83584] "ISO C forbids conversion of object pointer to function pointer type" -- no, not really
- From: pinskia at gcc dot gnu.org
- [Bug c/83584] "ISO C forbids conversion of object pointer to function pointer type" -- no, not really
- From: Keith.S.Thompson at gmail dot com
- [Bug c/83584] "ISO C forbids conversion of object pointer to function pointer type" -- no, not really
- From: txr at alumni dot caltech.edu
- [Bug c/83584] "ISO C forbids conversion of object pointer to function pointer type" -- no, not really
- From: schwab at linux-m68k dot org
- [Bug c/83584] "ISO C forbids conversion of object pointer to function pointer type" -- no, not really
- From: manu at gcc dot gnu.org
- [Bug c/83584] "ISO C forbids conversion of object pointer to function pointer type" -- no, not really
- From: txr at alumni dot caltech.edu