Bug 169991 - gcc4 problem with glib g_return_val... functions
Summary: gcc4 problem with glib g_return_val... functions
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Fedora
Classification: Fedora
Component: gcc
Version: 4
Hardware: i686
OS: Linux
medium
medium
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact:
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2005-10-06 07:32 UTC by Thomas M Steenholdt
Modified: 2007-11-30 22:11 UTC (History)
0 users

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2005-10-07 10:24:32 UTC
Type: ---
Embargoed:


Attachments (Terms of Use)
testcase created from trimmed down gaim plugin (1.91 KB, application/octet-stream)
2005-10-06 21:18 UTC, Thomas M Steenholdt
no flags Details
tiny g_return_val_if_fail testcase (66 bytes, text/plain)
2005-10-07 10:18 UTC, Thomas M Steenholdt
no flags Details

Description Thomas M Steenholdt 2005-10-06 07:32:39 UTC
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8b4) Gecko/20051006 Fedora/1.5b1-0.fc4 Firefox/1.4

Description of problem:
The g_return_val_if_fail macro from glib-2.0 fails with gcc4.
The macro wraps the g_return_if_fail_warning function, but building with gcc4 and "-Wall -Werror -ansi" makes it spew the following error at every call to g_return_val_if_fail

warning: passing argument 2 of 'g_return_if_fail_warning' discards qualifiers from pointer target type

i'm not calling g_return_if_fail_warning directly from anywhere within my code.

if i do the exact same build with gcc32,  I have no problems...


Version-Release number of selected component (if applicable):


How reproducible:
Always

Steps to Reproduce:
1. get meanwhile (or other software that uses g_return_val_if_fail) from meanwhile.sf.net
2. untar and CFLAGS="-Wall -Werror -ansi" ./configure
3. make and watch the errors
  

Actual Results:  lots of "warning: passing argument 2 of 'g_return_if_fail_warning' discards qualifiers from pointer target type" 

Expected Results:  clean compile!

Additional info:

Trying instead :

CC=gcc32 CFLAGS="-Wall -Werror -ansi" ./configure
make

All is good!

It looks like it may have something to do with gcc's __PRETTY_FUNCTION__ thing?

Comment 1 Jakub Jelinek 2005-10-06 07:44:50 UTC
Please provide either preprocessed source of the file on which you get the
warning, or create a minimal self-contained testcase.
I haven't seen any problem on the short testcase I tried, so likely the program
you're trying to build is doing something wrong.
g_return_if_fail_warning has 3 const char * arguments, so if you pass say a char
* argument to it, the warning is in order.  But, __PRETTY_FUNCTION__ unless
redefined in the source is const char *.


Comment 2 Thomas M Steenholdt 2005-10-06 21:18:15 UTC
Created attachment 119688 [details]
testcase created from trimmed down gaim plugin

This is the easiest way (for me) to try to illustrate the problem for you.

untar, then run CFLAGS="-Wall -Werror -ansi" ./autogen.sh followed by make...
assuming you're on FC4 or likely any gcc4 based platform, you should get the
error i'm talking about.

then try make clean, CC=gcc32 CFLAGS="-Wall -Werror -ansi" ./autogen.sh
followed by make and the error is gone.

I have to admit that i'm new to gnu make and all the stuff that goes on in
here, so i hope that's not what screws things up!

Comment 3 Jakub Jelinek 2005-10-06 21:56:47 UTC
I can't reproduce this.  Though I can't understand how is it easiest for you
to create such trimmed down testcase as opposed simply noting all command line
options used to build that file, replacing -c on that command line with -E
and if -o is missing, adding -o test.i and attaching test.i here, plus
writing what options were used.


Comment 4 Thomas M Steenholdt 2005-10-07 10:17:24 UTC
That's because i'm a moron!

Here's a better way to reproduce that involves much less work and much fewer
variable/unknown factors.

gcc -Dconst= -I. -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -Wall
-Werror -ansi test.c

I'll attach the test.c file in 30 secs...

Also, in cleaning up this test to be a lot better suited for tracking down
problems, I discovered that the problem goes away when taking -Dconst= out of
the command.

I hope this works for you!

I have tried this with several FC4 installations all on latest errata level and
they all do the same thing!

Comment 5 Thomas M Steenholdt 2005-10-07 10:18:28 UTC
Created attachment 119701 [details]
tiny g_return_val_if_fail testcase

Comment 6 Thomas M Steenholdt 2005-10-07 10:21:22 UTC
Exact output is:

[tmus@home testcase]$ gcc -Dconst= -I. -I/usr/include/glib-2.0
-I/usr/lib/glib-2.0/include -Wall -Werror -ansi test.c
cc1: warnings being treated as errors
test.c: In function âtestâ:
test.c:4: warning: passing argument 2 of âg_return_if_fail_warningâ discards
qualifiers from pointer target type



Comment 7 Jakub Jelinek 2005-10-07 10:24:32 UTC
If you use -Dconst=, then you certainly get what you are asking for.
There is no bug on the GCC side.  __PRETTY_FUNCTION__ is const char *,
no matter if you redefine const keyword using a macro or not, so the
compiler has all rights to warn about it being assigned to a char * argument
(as g_return_if_fail_warning uses const in the prototype and you changed
the prototype with -Dconst=).


Comment 8 Thomas M Steenholdt 2005-10-07 15:47:32 UTC
Right, that's what I thought - I'm no compiler expert even by a longshot. But
try to do the same thing with gcc32 - No warning! Which indicates to me that
something is rotten! It may be with gcc32 though??

Comment 9 Thomas M Steenholdt 2005-10-09 21:41:55 UTC
Anyways - I should have trimmed it all the way down to this from the beginning.
I don't really need the -Dconst= and everyhing is working now!


Note You need to log in before you can comment on or make changes to this bug.