Bug 11234 - -pedantic accepts function pointer <-> void*
Summary: -pedantic accepts function pointer <-> void*
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 3.3
: P3 normal
Target Milestone: 3.4.0
Assignee: Not yet assigned to anyone
URL:
Keywords: accepts-invalid, diagnostic
: 83584 (view as bug list)
Depends on:
Blocks:
 
Reported: 2003-06-18 13:20 UTC by Hallvard B Furuseth
Modified: 2017-12-26 23:57 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2003-10-24 18:11:31


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Hallvard B Furuseth 2003-06-18 13:20:25 UTC
	gcc -ansi -pedantic accepts some instances of conversion between
	function pointers and object pointers:

		void *v = function;
		(function_type) char_ptr;
		(char *) function;

	That's not valid ANSI C, even with casts.  ANSI 3.2.2.3
	(Pointers), 3.3.4 (Cast operators) and 3.3.16.1 (Simple
	assignment) all explicitly talk about conversion to/from
	pointers to an 'object or incomplete type'; that explicitly
	excludes pointers to functions.

	(Note, the assignment void_ptr = function; does get a warning,
	but the corresponding initialization does not.)

Environment:
System: SunOS bombur.uio.no 5.8 Generic_108528-21 sun4u sparc SUNW,Ultra-5_10
Architecture: sun4

	
host: sparc-sun-solaris2.8
build: sparc-sun-solaris2.8
target: sparc-sun-solaris2.8
configured with: ../gcc-3.3/configure --enable-languages=c,c++,f77 --disable-shared --disable-multilib --prefix=/bombur/tmp/gcc --enable-version-specific-runtime-libs --enable-threads

How-To-Repeat:
bash$ gcc -ansi -pedantic -S a.c
a.c: In function `function':
a.c:5: warning: ISO C forbids initialization between function pointer and `void *'
a.c:6: warning: initialization from incompatible pointer type
a.c:12: warning: assignment from incompatible pointer type
a.c:13: warning: ISO C forbids assignment between function pointer and `void *'
bash$ cat a.c
typedef void (*function_type)(void);

void function(void *void_ptr, char *char_ptr)
{
    function_type func_ptr = void_ptr;  /* warning (ISO C) */
    char *s = function;                 /* warning */

    void *v = function;                 /* should warn */
    (function_type) char_ptr;           /* should warn */
    (char *) function;                  /* should warn */

    char_ptr = function;                /* warning */
    void_ptr = function;                /* warning (ISO C) */
    func_ptr = (void *)0;               /* OK - null pointer constant */
}
Comment 1 Nathanael C. Nerode 2003-07-05 21:20:10 UTC
Present in mainline.
Comment 2 Eric Botcazou 2003-09-08 07:28:01 UTC
Generic C front-end problem.
Comment 3 Dara Hazeghi 2003-10-24 18:11:31 UTC
Still present
Comment 4 CVS Commits 2004-01-09 20:04:03 UTC
Subject: Bug 11234

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	jsm28@gcc.gnu.org	2004-01-09 20:03:58

Modified files:
	gcc            : ChangeLog c-typeck.c except.c recog.h final.c 
	                 genoutput.c 
	gcc/testsuite  : ChangeLog 
	gcc/testsuite/gcc.dg/weak: weak-6.c weak-7.c 
Added files:
	gcc/testsuite/gcc.dg: func-ptr-conv-1.c 

Log message:
	PR c/11234
	* c-typeck.c (build_c_cast): If pedantic, warn for conversions
	between function and object pointers.
	(digest_init): When comparing a pointer to function type to the
	target type, only apply TREE_TYPE once to the pointer to function
	type.
	* except.c (for_each_eh_label_1): Treat data as a pointer to a
	function pointer rather than casting it to a function pointer.
	(for_each_eh_label): Update caller.
	* recog.h (struct insn_data): Use a struct or union for output.
	* genoutput.c (output_insn_data): Update.
	* final.c (get_insn_template): Update.
	
	testsuite:
	* gcc.dg/func-ptr-conv-1.c: New test.
	* gcc.dg/weak/weak-6.c, gcc.dg/weak/weak-7.c: Update.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.2202&r2=2.2203
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/c-typeck.c.diff?cvsroot=gcc&r1=1.270&r2=1.271
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/except.c.diff?cvsroot=gcc&r1=1.254&r2=1.255
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/recog.h.diff?cvsroot=gcc&r1=1.47&r2=1.48
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/final.c.diff?cvsroot=gcc&r1=1.303&r2=1.304
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/genoutput.c.diff?cvsroot=gcc&r1=1.79&r2=1.80
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.3351&r2=1.3352
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/func-ptr-conv-1.c.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/weak/weak-6.c.diff?cvsroot=gcc&r1=1.2&r2=1.3
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/weak/weak-7.c.diff?cvsroot=gcc&r1=1.2&r2=1.3

Comment 5 Andrew Pinski 2004-01-10 04:01:56 UTC
Fixed for 3.4.
Comment 6 Andrew Pinski 2017-12-26 20:12:47 UTC
*** Bug 83584 has been marked as a duplicate of this bug. ***
Comment 7 Andrew Pinski 2017-12-26 20:13:39 UTC
Reopening based on the duplicated bug says our reading of the standard is incorrect.  But I will let someone else decide if that is really true or not.
Comment 9 Andrew Pinski 2017-12-26 20:22:58 UTC
https://gcc.gnu.org/ml/gcc-patches/2004-01/msg00599.html

This patch fixes PR c/11234 (nondiagnosis of certain invalid
conversions between function and object pointers). 

So fixed.
Comment 10 Hallvard B Furuseth 2017-12-26 23:57:19 UTC
On 26/12/17 21:13, pinskia at gcc dot gnu.org wrote:
> Reopening based on the duplicated bug says our reading of the standard is
> incorrect.  But I will let someone else decide if that is really true or not.

Er, yes.  I wrote the bug report that caused that warning, and I think I
was wrong.  The warning should go away, or move to -Wextra or something.

Hallvard