public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/14030] New: missing parameter count check ?
@ 2004-02-05 13:25 d dot binderman at virgin dot net
  2004-02-05 18:40 ` [Bug c/14030] " bangerth at dealii dot org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: d dot binderman at virgin dot net @ 2004-02-05 13:25 UTC (permalink / raw)
  To: gcc-bugs

Given the following broken source code

void f( one, two)
int one;
char two;
{
}

void g(int i)
{
	f( 1);
	f( 1, 'e', i);
}

gcc 332 says

[dcb@localhost src]$ gcc -c bad.c
[dcb@localhost src]$

gcc 332 with lots of warning flags says

[dcb@localhost src]$ gcc -c -g -O2 -Wall -ansi -pedantic bad.c
[dcb@localhost src]$

Surprising.  Here is Intel compiler on the same code. Note the lack
of extra flags.

[dcb@localhost src]$ icc -c bad.c
bad.c(13): warning #165: too few arguments in function call
        f( 1);
            ^

bad.c(14): warning #140: too many arguments in function call
        f( 1, 'e', i);
                   ^

Any chance of getting gcc to find the faults in the code, without
changing the original code from K & R to ISO ?

-- 
           Summary: missing parameter count check ?
           Product: gcc
           Version: 3.3.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: d dot binderman at virgin dot net
                CC: gcc-bugs at gcc dot gnu dot org
  GCC host triplet: redhat linux on i686


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14030


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c/14030] missing parameter count check ?
  2004-02-05 13:25 [Bug c/14030] New: missing parameter count check ? d dot binderman at virgin dot net
@ 2004-02-05 18:40 ` bangerth at dealii dot org
  2004-05-11 16:35 ` pinskia at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: bangerth at dealii dot org @ 2004-02-05 18:40 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From bangerth at dealii dot org  2004-02-05 18:40 -------
Confirmed. A warning is clearly in order. The only thing I get with 
all the flags listed and -W in addition is a warning that the parameters 
"one" and "two" are unused in "f". 
 
W. 

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|                            |1
      Known to fail|                            |3.2.3 3.3.3 3.4.0
   Last reconfirmed|0000-00-00 00:00:00         |2004-02-05 18:40:27
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14030


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c/14030] missing parameter count check ?
  2004-02-05 13:25 [Bug c/14030] New: missing parameter count check ? d dot binderman at virgin dot net
  2004-02-05 18:40 ` [Bug c/14030] " bangerth at dealii dot org
@ 2004-05-11 16:35 ` pinskia at gcc dot gnu dot org
  2004-05-11 20:32 ` jsm at polyomino dot org dot uk
  2004-05-11 23:19 ` geoffk at geoffk dot org
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-05-11 16:35 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-05-10 17:41 -------
Actually this has to do with old style function declarations there was a draft of a pre-DR 
report about this (or at least something related to this) sent to the gcc@ mailing list but I 
cannot find it at this point.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |diagnostic
   Last reconfirmed|2004-02-05 18:40:27         |2004-05-10 17:41:45
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14030


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c/14030] missing parameter count check ?
  2004-02-05 13:25 [Bug c/14030] New: missing parameter count check ? d dot binderman at virgin dot net
  2004-02-05 18:40 ` [Bug c/14030] " bangerth at dealii dot org
  2004-05-11 16:35 ` pinskia at gcc dot gnu dot org
@ 2004-05-11 20:32 ` jsm at polyomino dot org dot uk
  2004-05-11 23:19 ` geoffk at geoffk dot org
  3 siblings, 0 replies; 5+ messages in thread
From: jsm at polyomino dot org dot uk @ 2004-05-11 20:32 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From jsm at polyomino dot org dot uk  2004-05-10 22:39 -------
Subject: Re:  missing parameter count check ?

On Mon, 10 May 2004, pinskia at gcc dot gnu dot org wrote:

> Actually this has to do with old style function declarations there was a
> draft of a pre-DR report about this (or at least something related to
> this) sent to the gcc@ mailing list but I cannot find it at this point.

There's no immediate relevance of this feature request to my pre-DR, as in 
this case it's clear what the standard means and that the code is meant to 
be accepted as long as g need never be called.

The code is of course very bad style (simply using unprototyped functions
at all is somewhat dubious nowadays, but I don't see any real use for
calls of them with the wrong parameters given that such calls yield
undefined behavior if ever executed).  As I said in
<http://gcc.gnu.org/ml/gcc-patches/2004-03/msg01317.html>:

The manual lists diagnosing this sort of thing under "Certain Changes We
Don't Want to Make".  IMA means one of the reasons given there no longer
applies; all calls in a whole program compiled at once could be checked
for consistency with an old-style definition and compiled into aborts with
a warning given if inconsistent.  (The most likely reason for it actually
to be worthwhile to implement this would be to avoid problems arising with
optimizations attempting to inline such calls, etc..)

I think a mandatory warning (not a pedwarn) for bad calls to functions
with old-style definitions (whenever the call and definition are visible
to the compiler in the same compilation, regardless of the order in the
source file or whether in different source files) would be reasonable if
someone wants to implement it.



-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14030


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c/14030] missing parameter count check ?
  2004-02-05 13:25 [Bug c/14030] New: missing parameter count check ? d dot binderman at virgin dot net
                   ` (2 preceding siblings ...)
  2004-05-11 20:32 ` jsm at polyomino dot org dot uk
@ 2004-05-11 23:19 ` geoffk at geoffk dot org
  3 siblings, 0 replies; 5+ messages in thread
From: geoffk at geoffk dot org @ 2004-05-11 23:19 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From geoffk at geoffk dot org  2004-05-11 00:45 -------
Subject: Re:  missing parameter count check ?

"jsm at polyomino dot org dot uk" <gcc-bugzilla@gcc.gnu.org> writes:

> ------- Additional Comments From jsm at polyomino dot org dot uk  2004-05-10 22:39 -------
> Subject: Re:  missing parameter count check ?
> 
> On Mon, 10 May 2004, pinskia at gcc dot gnu dot org wrote:
> 
> > Actually this has to do with old style function declarations there was a
> > draft of a pre-DR report about this (or at least something related to
> > this) sent to the gcc@ mailing list but I cannot find it at this point.
> 
> There's no immediate relevance of this feature request to my pre-DR, as in 
> this case it's clear what the standard means and that the code is meant to 
> be accepted as long as g need never be called.
> 
> The code is of course very bad style (simply using unprototyped functions
> at all is somewhat dubious nowadays, but I don't see any real use for
> calls of them with the wrong parameters given that such calls yield
> undefined behavior if ever executed).  As I said in
> <http://gcc.gnu.org/ml/gcc-patches/2004-03/msg01317.html>:
> 
> The manual lists diagnosing this sort of thing under "Certain Changes We
> Don't Want to Make".  IMA means one of the reasons given there no longer
> applies; all calls in a whole program compiled at once could be checked
> for consistency with an old-style definition and compiled into aborts with
> a warning given if inconsistent.  (The most likely reason for it actually
> to be worthwhile to implement this would be to avoid problems arising with
> optimizations attempting to inline such calls, etc..)

Yes, this seems like a good idea: When the compiler is compiling a call
to a function which has no prototype but has a definition, and the
parameters in the definition don't match the actual parameters,
print a warning.

With unit-at-a-time, this will work for all function calls when the
definition is visible in the same translation unit.  With IMA, this is
extended further.

Even if we decide not to do this, the paragraph in the manual should
be changed to delete the words "following the definition".



-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14030


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2004-05-11  0:45 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-02-05 13:25 [Bug c/14030] New: missing parameter count check ? d dot binderman at virgin dot net
2004-02-05 18:40 ` [Bug c/14030] " bangerth at dealii dot org
2004-05-11 16:35 ` pinskia at gcc dot gnu dot org
2004-05-11 20:32 ` jsm at polyomino dot org dot uk
2004-05-11 23:19 ` geoffk at geoffk dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).