Bug 24068 - Unconditional warning when using -combine
Summary: Unconditional warning when using -combine
Status: RESOLVED WONTFIX
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 4.1.0
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2005-09-26 19:24 UTC by Dan Nicolaescu
Modified: 2010-09-17 09:06 UTC (History)
2 users (show)

See Also:
Host:
Target: i686-pc-linux-gnu
Build:
Known to work:
Known to fail: 3.4.0 4.0.0 4.1.0
Last reconfirmed: 2007-11-12 20:43:26


Attachments
xterm.i (107.17 KB, text/plain)
2005-09-26 19:25 UTC, Dan Nicolaescu
Details
xlwmenu.i (50.37 KB, text/plain)
2005-09-26 19:25 UTC, Dan Nicolaescu
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Dan Nicolaescu 2005-09-26 19:24:27 UTC
When trying to compile the attached preprocessed files using
gcc -c -fwhole-program --combine xterm.i xlwmenu.i

These warnings are produced unconditionally:

/home/dann/build/Emacs-CVS/emacs/lwlib/xlwmenu.c:57: warning: prototype for
'x_alloc_nearest_color_for_widget' follows non-prototype definition
/home/dann/build/Emacs-CVS/emacs/lwlib/xlwmenu.c:58: warning: prototype for
'x_alloc_lighter_color_for_widget' follows non-prototype definition
/home/dann/build/Emacs-CVS/emacs/lwlib/xlwmenu.c:64: warning: prototype for
'x_clear_errors' follows non-prototype definition
/home/dann/build/Emacs-CVS/emacs/lwlib/xlwmenu.c:65: warning: prototype for
'x_copy_dpy_color' follows non-prototype definition

AFAICT the warnings don't make much sense. The code is correct. The functions in
questions are defined in one file and then prototyped and used in the other
file. This kind of stuff appears in countless C programs. 
Can this warning be turned off by default?
Comment 1 Dan Nicolaescu 2005-09-26 19:25:07 UTC
Created attachment 9807 [details]
xterm.i
Comment 2 Dan Nicolaescu 2005-09-26 19:25:38 UTC
Created attachment 9808 [details]
xlwmenu.i
Comment 3 Andrew Pinski 2005-09-26 19:31:30 UTC
Actually this is where C standard is werid really.
Comment 4 Andrew Pinski 2005-09-26 19:41:12 UTC
Because one file uses K&R style function defintions and the other uses a prototype which is ANSI/ISO 
style.

Simple example:
file1.c:
int f(int);
---
file2.c:
int f(a)
int a;
{
  return a;
}
---
Compile it as:
gcc file2.c file1.c -combine


So this about the following:
int f(a)
int a;
{
  return a;
}
int f(int);

Which is questionable.

So I don't think this is not an inappropriate warning.


--------------------------------------------
As an aside, I wish people would stop using K&R style C already.
Comment 5 Andrew Pinski 2005-09-26 19:46:51 UTC
I really want to say this is a bug in their code as
x_alloc_nearest_color_for_widget's prototype is in the source file which is bad form really.
Comment 6 Dan Nicolaescu 2005-09-26 19:54:21 UTC
(In reply to comment #4)
> Because one file uses K&R style function defintions and the other uses a
prototype which is ANSI/ISO 
> style.
> Simple example:
[snip]
> So I don't think this is not an inappropriate warning.

The question is: can this EVER result in incorrect behavior? 
Is it incorrect from the standard point of view? 

If the answer to the above is no, then there no reason to warn.

> --------------------------------------------
> As an aside, I wish people would stop using K&R style C already.

Aggreed.
Comment 7 Andrew Pinski 2005-09-26 19:59:09 UTC
This is not a regression.
Comment 8 Dan Nicolaescu 2005-09-26 20:46:17 UTC
(In reply to comment #4)
> So this about the following:
> int f(a)
> int a;
> {
>   return a;
> }
> int f(int);
> 
> Which is questionable.
> 
> So I don't think this is not an inappropriate warning.

It seems that the warning was designed for code like your example above. 
But if you have 1 K&R file and one C90 file, then there should be no warning... 
Another bad thing is that if you swap the files on the command line then you get
no warning.
Comment 9 Daniel Jacobowitz 2005-09-29 18:58:32 UTC
Subject: Re:  Unconditional warning when using -combine

On Mon, Sep 26, 2005 at 08:46:20PM -0000, dann at godzilla dot ics dot uci dot edu wrote:
> > So this about the following:
> > int f(a)
> > int a;
> > {
> >   return a;
> > }
> > int f(int);
> > 
> > Which is questionable.
> > 
> > So I don't think this is not an inappropriate warning.
> 
> It seems that the warning was designed for code like your example above. 
> But if you have 1 K&R file and one C90 file, then there should be no warning... 
> Another bad thing is that if you swap the files on the command line then you get
> no warning.

There certainly should be a warning.  It's not obvious on most targets
with int, but what you're doing here won't work with float arguments;
if the prototype includes an argument list, the definition should also.

Comment 10 Dan Nicolaescu 2005-09-29 20:10:27 UTC
(In reply to comment #9)
> Subject: Re:  Unconditional warning when using -combine
> 
> On Mon, Sep 26, 2005 at 08:46:20PM -0000, dann at godzilla dot ics dot uci dot
edu wrote:
> > > So this about the following:
> > > int f(a)
> > > int a;
> > > {
> > >   return a;
> > > }
> > > int f(int);
> > > 
> > > Which is questionable.
> > > 
> > > So I don't think this is not an inappropriate warning.
> > 
> > It seems that the warning was designed for code like your example above. 
> > But if you have 1 K&R file and one C90 file, then there should be no warning... 
> > Another bad thing is that if you swap the files on the command line then you get
> > no warning.
> 
> There certainly should be a warning.  It's not obvious on most targets
> with int, but what you're doing here won't work with float arguments;
> if the prototype includes an argument list, the definition should also.
> 

Sorry, I am not sure I understand what are you referring to... Both in the
original bug report and in Andrew's example above both the definition and the
prototype included an argument list with types for all the declarations.
Comment 11 Tom Tromey 2007-11-12 20:43:26 UTC
We unconditionally warn for a prototype following an old-style definition.
The oddity here is that these are in different files, glommed together
with --combine, and so don't represent exactly the same sort of style violation
as the warning is apparently intended to prevent.

I think the point behind comment #9 is that it is important that a prototype
always be visible, because one argument may require widening; in a case like
the sample code, if this were true, it would result in bugs.  See the
info node "Prototypes and Old-Style Function Definitions" for details.
Comment 12 Richard Biener 2010-09-17 09:06:22 UTC
-combine has been removed from GCC 4.6 in favor of LTO, closing as WONTFIX.