Bug 4890 - inconsistent int-to-pointer warning
Summary: inconsistent int-to-pointer warning
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: preprocessor (show other bugs)
Version: 3.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: accepts-invalid
Depends on:
Blocks:
 
Reported: 2001-11-16 10:26 UTC by gsicherm
Modified: 2003-07-25 17:33 UTC (History)
3 users (show)

See Also:
Host: sparc-sun-solaris2.8
Target: sparc-sun-solaris2.8
Build: sparc-sun-solaris2.8
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description gsicherm 2001-11-16 10:26:00 UTC
	In the Solaris 2.8 stdio.h (and GCC's hack of it), the declaration
	of the function fdopen is suppressed in standard C unless a suitable
	macro such as POSIX is defined.  For classic C fdopen should probably
	be declared unconditionally, but Sun's conditional compilation logic
	still does not declare it without one of the special defines.  Hence
	for classic C (gcc -traditional) fdopen should be undeclared and
	treated as int, and gcc should complain if the result is assigned
	to a FILE *.

	Gcc does not consistently complain.  In fact, if I #include an
	empty header file after stdio.h, gcc complains correctly that
	an int is being assigned to a pointer.  But if I #include the
	empty header file *before* stdio.h, gcc does not complain!  Nor
	does it complain if I omit the empty header and include only
	stdio.h.  The output of gcc -E is the same in both cases except
	for the #line marks.

Release:
3.0

Environment:
System: SunOS sun01 5.8 Generic_108528-03 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: ../configure --disable-nls --disable-libgcj --enable-languages=c++,f77,objc

How-To-Repeat:
	1. Create an empty (or substantially empty) file empty.h.
	2. Create this C file as rip.c:

		#include <stdio.h>
		#include "empty.h"

		score()
		{
		    register FILE *outf;
		    outf = fdopen(6, "w");
		}

	3. Run "gcc -traditional -c rip.c".  You will see this warning:

		rip.c: In function `score':
		rip.c:7: warning: assignment makes pointer from integer\
		 without a cast

	4. Now interchange the two #include lines of rip.c and compile again.
	   No warning appears!

	Here are the preprocessor outputs, left-justified.
	First case 3:
--START--
# 1 "rip.c"
# 1 "/usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.0/include/stdio.h" 1 3













# 1 "/usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.0/include/stdarg.h" 1 3










































typedef __builtin_va_list __gnuc_va_list;




# 135 "/usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.0/include/stdarg.h" 3




# 15 "/usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.0/include/stdio.h" 2 3



















#pragma ident	"@(#)stdio.h	1.78	99/12/08 SMI"	

# 1 "/usr/include/iso/stdio_iso.h" 1 3































#pragma ident	"@(#)stdio_iso.h	1.2	99/10/25 SMI"


# 1 "/usr/include/sys/feature_tests.h" 1 3












#pragma ident	"@(#)feature_tests.h	1.18	99/07/26 SMI"

# 1 "/usr/include/sys/isa_defs.h" 1 3








#pragma ident	"@(#)isa_defs.h	1.20	99/05/04 SMI"






























































































































































# 267 "/usr/include/sys/isa_defs.h" 3














































































# 366 "/usr/include/sys/isa_defs.h" 3


















# 16 "/usr/include/sys/feature_tests.h" 2 3









































































































































































# 36 "/usr/include/iso/stdio_iso.h" 2 3
# 1 "/usr/include/sys/va_list.h" 1 3








#pragma ident	"@(#)va_list.h	1.12	99/05/04 SMI"


















typedef char *__va_list;







# 37 "/usr/include/iso/stdio_iso.h" 2 3
# 1 "/usr/include/stdio_tag.h" 1 3








#pragma ident	"@(#)stdio_tag.h	1.3	98/04/20 SMI"











typedef struct __FILE __FILE;







# 38 "/usr/include/iso/stdio_iso.h" 2 3
# 1 "/usr/include/stdio_impl.h" 1 3








#pragma ident	"@(#)stdio_impl.h	1.8	99/06/10 SMI"

# 1 "/usr/include/sys/isa_defs.h" 1 3





# 383 "/usr/include/sys/isa_defs.h" 3

# 12 "/usr/include/stdio_impl.h" 2 3










typedef int	ssize_t;		



# 36 "/usr/include/stdio_impl.h" 3


struct __FILE	
{




	ssize_t		_cnt;	
	unsigned char	*_ptr;	

	unsigned char	*_base;	
	unsigned char	_flag;	
	unsigned char	_file;	
	unsigned	__orientation:2; 
	unsigned	__ionolock:1;	
	unsigned	__filler:5;
};








# 39 "/usr/include/iso/stdio_iso.h" 2 3




















typedef	long long	__longlong_t;















typedef	__FILE FILE;







typedef unsigned int	size_t;		




typedef long		fpos_t;































































extern __FILE	_iob[20	];









# 226 "/usr/include/iso/stdio_iso.h" 3


extern int	remove();
extern int	rename();
extern FILE	*tmpfile();
extern char	*tmpnam();
extern int	fclose();
extern int	fflush();
extern FILE	*fopen();
extern FILE	*freopen();
extern void	setbuf();
extern int	setvbuf();
extern int	fprintf();
extern int	fscanf();
extern int	printf();
extern int	scanf();
extern int	sprintf();
extern int	sscanf();
extern int	vfprintf();
extern int	vprintf();
extern int	vsprintf();
extern int	fgetc();
extern char	*fgets();
extern int	fputc();
extern int	fputs();
extern int	getc();
extern int	getchar();
extern char	*gets();
extern int	putc();
extern int	putchar();
extern int	puts();
extern int	ungetc();
extern size_t	fread();
extern size_t	fwrite();
extern int	fgetpos();
extern int	fseek();
extern int	fsetpos();
extern long	ftell();
extern void	rewind();
extern void	clearerr();
extern int	feof();
extern int	ferror();
extern void	perror();


extern int	_filbuf();
extern int	_flsbuf();













# 300 "/usr/include/iso/stdio_iso.h" 3








































# 37 "/usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.0/include/stdio.h" 2 3













# 95 "/usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.0/include/stdio.h" 3










typedef long		off_t;







typedef __longlong_t	off64_t;









typedef __longlong_t	fpos64_t;



























extern unsigned char	 _sibuf[], _sobuf[];



# 190 "/usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.0/include/stdio.h" 3



extern unsigned char	*_bufendtab[];
extern FILE		*_lastbuf;



# 220 "/usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.0/include/stdio.h" 3


# 314 "/usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.0/include/stdio.h" 3













extern void setbuffer();
extern int setlinebuf();









# 347 "/usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.0/include/stdio.h" 3


# 362 "/usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.0/include/stdio.h" 3



extern int	fseeko();
extern off_t	ftello();




extern FILE	*fopen64();
extern FILE	*freopen64();
extern FILE	*tmpfile64();
extern int	fgetpos64();
extern int	fsetpos64();
extern int	fseeko64();
extern off64_t	ftello64();






# 407 "/usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.0/include/stdio.h" 3











# 2 "rip.c" 2 3
# 1 "empty.h" 1
# 3 "rip.c" 2

score()
{
    register FILE *outf;

    outf = fdopen(6, "w");
}
--END--

	Then case 4:
--START--
# 1 "rip.c"
# 1 "empty.h" 1
# 2 "rip.c" 2
# 1 "/usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.0/include/stdio.h" 1 3













# 1 "/usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.0/include/stdarg.h" 1 3










































typedef __builtin_va_list __gnuc_va_list;




# 135 "/usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.0/include/stdarg.h" 3




# 15 "/usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.0/include/stdio.h" 2 3



















#pragma ident	"@(#)stdio.h	1.78	99/12/08 SMI"	

# 1 "/usr/include/iso/stdio_iso.h" 1 3































#pragma ident	"@(#)stdio_iso.h	1.2	99/10/25 SMI"


# 1 "/usr/include/sys/feature_tests.h" 1 3












#pragma ident	"@(#)feature_tests.h	1.18	99/07/26 SMI"

# 1 "/usr/include/sys/isa_defs.h" 1 3








#pragma ident	"@(#)isa_defs.h	1.20	99/05/04 SMI"






























































































































































# 267 "/usr/include/sys/isa_defs.h" 3














































































# 366 "/usr/include/sys/isa_defs.h" 3


















# 16 "/usr/include/sys/feature_tests.h" 2 3









































































































































































# 36 "/usr/include/iso/stdio_iso.h" 2 3
# 1 "/usr/include/sys/va_list.h" 1 3








#pragma ident	"@(#)va_list.h	1.12	99/05/04 SMI"


















typedef char *__va_list;







# 37 "/usr/include/iso/stdio_iso.h" 2 3
# 1 "/usr/include/stdio_tag.h" 1 3








#pragma ident	"@(#)stdio_tag.h	1.3	98/04/20 SMI"











typedef struct __FILE __FILE;







# 38 "/usr/include/iso/stdio_iso.h" 2 3
# 1 "/usr/include/stdio_impl.h" 1 3








#pragma ident	"@(#)stdio_impl.h	1.8	99/06/10 SMI"

# 1 "/usr/include/sys/isa_defs.h" 1 3





# 383 "/usr/include/sys/isa_defs.h" 3

# 12 "/usr/include/stdio_impl.h" 2 3










typedef int	ssize_t;		



# 36 "/usr/include/stdio_impl.h" 3


struct __FILE	
{




	ssize_t		_cnt;	
	unsigned char	*_ptr;	

	unsigned char	*_base;	
	unsigned char	_flag;	
	unsigned char	_file;	
	unsigned	__orientation:2; 
	unsigned	__ionolock:1;	
	unsigned	__filler:5;
};








# 39 "/usr/include/iso/stdio_iso.h" 2 3




















typedef	long long	__longlong_t;















typedef	__FILE FILE;







typedef unsigned int	size_t;		




typedef long		fpos_t;































































extern __FILE	_iob[20	];









# 226 "/usr/include/iso/stdio_iso.h" 3


extern int	remove();
extern int	rename();
extern FILE	*tmpfile();
extern char	*tmpnam();
extern int	fclose();
extern int	fflush();
extern FILE	*fopen();
extern FILE	*freopen();
extern void	setbuf();
extern int	setvbuf();
extern int	fprintf();
extern int	fscanf();
extern int	printf();
extern int	scanf();
extern int	sprintf();
extern int	sscanf();
extern int	vfprintf();
extern int	vprintf();
extern int	vsprintf();
extern int	fgetc();
extern char	*fgets();
extern int	fputc();
extern int	fputs();
extern int	getc();
extern int	getchar();
extern char	*gets();
extern int	putc();
extern int	putchar();
extern int	puts();
extern int	ungetc();
extern size_t	fread();
extern size_t	fwrite();
extern int	fgetpos();
extern int	fseek();
extern int	fsetpos();
extern long	ftell();
extern void	rewind();
extern void	clearerr();
extern int	feof();
extern int	ferror();
extern void	perror();


extern int	_filbuf();
extern int	_flsbuf();













# 300 "/usr/include/iso/stdio_iso.h" 3








































# 37 "/usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.0/include/stdio.h" 2 3













# 95 "/usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.0/include/stdio.h" 3










typedef long		off_t;







typedef __longlong_t	off64_t;









typedef __longlong_t	fpos64_t;



























extern unsigned char	 _sibuf[], _sobuf[];



# 190 "/usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.0/include/stdio.h" 3



extern unsigned char	*_bufendtab[];
extern FILE		*_lastbuf;



# 220 "/usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.0/include/stdio.h" 3


# 314 "/usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.0/include/stdio.h" 3













extern void setbuffer();
extern int setlinebuf();









# 347 "/usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.0/include/stdio.h" 3


# 362 "/usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.0/include/stdio.h" 3



extern int	fseeko();
extern off_t	ftello();




extern FILE	*fopen64();
extern FILE	*freopen64();
extern FILE	*tmpfile64();
extern int	fgetpos64();
extern int	fsetpos64();
extern int	fseeko64();
extern off64_t	ftello64();






# 407 "/usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.0/include/stdio.h" 3











# 3 "rip.c" 2 3

score()
{
    register FILE *outf;

    outf = fdopen(6, "w");
}
--END--
Comment 1 gsicherm 2001-11-16 10:26:00 UTC
Fix:
	To that the elves know not the answer.

-- 
George L. Sicherman
work: gsicherm@elity.com
home: colonel@mail.monmouth.com
Comment 2 Christian Ehrhardt 2002-11-06 13:38:40 UTC
From: "Christian Ehrhardt" <ehrhardt@mathematik.uni-ulm.de>
To: gcc-gnats@gcc.gnu.org, gcc-prs@gcc.gnu.org, gcc-bugs@gcc.gnu.org,
  nobody@gcc.gnu.org, gsicherm@elity.com
Cc:  
Subject: Re: c/4890: inconsistent int-to-pointer warning
Date: Wed, 6 Nov 2002 13:38:40 +0100

 Hi,
 
 I can confirm that this is still present in gcc-3.2. I can't reproduce
 with recent 3.3, don't know about 3.2.1 yet. The problem is not arch
 specific.
 
 Here are instructions on how to reproduce this with a much smaller
 testcase:
 
 touch /usr/include/empty.h
 echo '#include <empty.h>' >t.c
 gcc -traditional -E t.c
 # 1 "p.c"
 # 1 "/usr/include/empty.h" 1 3
 # 2 "p.c" 2 3
 
 The last line is the problem: ``# 2 "p.c 2 3'' means:
                                   ^  ^   ^ ^
                                   |  |   | |
 New line number is 2 -------------+  |   | |
 New file name is p.c ----------------+   | |
 Event was LC_LEAVE   --------------------+ |
 We are returning to SYSTEM header ---------+
 
 The last part is clearly wrong. Also this is a regression from 2.95.3
 
     regards   Christian
 
 http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=4890
 
 -- 
 THAT'S ALL FOLKS!
Comment 3 Neil Booth 2002-11-10 22:38:52 UTC
State-Changed-From-To: open->closed
State-Changed-Why: Fixed.
Comment 4 Neil Booth 2002-11-11 06:38:57 UTC
From: neil@gcc.gnu.org
To: gcc-gnats@gcc.gnu.org
Cc:  
Subject: preprocessor/4890
Date: 11 Nov 2002 06:38:57 -0000

 CVSROOT:	/cvs/gcc
 Module name:	gcc
 Branch: 	gcc-3_2-branch
 Changes by:	neil@gcc.gnu.org	2002-11-10 22:38:57
 
 Modified files:
 	gcc            : tradcpp.c ChangeLog 
 
 Log message:
 	PR preprocessor/4890
 	* tradcpp.c (output_line_command): When leaving a file,
 	system_include_depth has not yet been decremented.
 
 Patches:
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/tradcpp.c.diff?cvsroot=gcc&only_with_tag=gcc-3_2-branch&r1=1.47.2.2&r2=1.47.2.2.2.1
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_2-branch&r1=1.13152.2.657.2.128&r2=1.13152.2.657.2.129