public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* Re: c++/4205: function template can call other function with incorrect parameters
@ 2002-11-21 18:51 Wolfgang Bangerth
  0 siblings, 0 replies; 3+ messages in thread
From: Wolfgang Bangerth @ 2002-11-21 18:51 UTC (permalink / raw)
  To: nobody; +Cc: gcc-prs

The following reply was made to PR c++/4205; it has been noted by GNATS.

From: Wolfgang Bangerth <bangerth@ticam.utexas.edu>
To: gcc-bugs@gcc.gnu.org, <gcc-gnats@gcc.gnu.org>, <nathan@codesourcery.com>,
   <gdr@codesourcery.com>
Cc:  
Subject: Re: c++/4205: function template can call other function with incorrect
 parameters
Date: Fri, 15 Nov 2002 19:55:02 -0600 (CST)

 This code compiles silently:
 -------------------------------------
 template<typename F> void quirk(F f) {
   (*f) (1);
 }
 
 void foo(int i, int j = 5){}
 void bar(int i, int j)    {}
 
 int main() {
   quirk(&foo); 
   quirk(&bar);
 }
 -------------------------------------
 
 The assertion of the submitter is that the first quirk(&foo) is ok, since 
 the call to (*f)(1) will substitute the second arg of foo by the default 
 argument of that function. The second call would be wrong. It succeeds, of 
 course, since the function quirk for exactly this template arg has already 
 been compiled, and no re-compilation means no re-check.
 
 However, I believe that already the first one is bogus. The template 
 argument F of quirk is 
   void (*) (int, int),
 so the call to (*p)(1) should be invalid. We should not know about default 
 arguments in quirk, right? I'm surprised that default arguments are 
 propagated to the template function. They don't appear in the type of 
 quirk as well, since if I enter a
     std::cout << __PRETTY_FUNCTION__ << std::endl;
 into that function, I only get 
     void quirk(F) [with F = void (*)(int, int)]
 But that may of course have other roots.
 
 Regards
   Wolfgang
 
 -------------------------------------------------------------------------
 Wolfgang Bangerth              email:           bangerth@ticam.utexas.edu
                                www: http://www.ticam.utexas.edu/~bangerth
 
 


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

* Re: c++/4205: function template can call other function with incorrect parameters
@ 2001-09-04  8:20 nathan
  0 siblings, 0 replies; 3+ messages in thread
From: nathan @ 2001-09-04  8:20 UTC (permalink / raw)
  To: Jens.Maurer, gcc-bugs, gcc-prs, nobody

Synopsis: function template can call other function with incorrect parameters

State-Changed-From-To: open->analyzed
State-Changed-By: nathan
State-Changed-When: Tue Sep  4 08:20:42 2001
State-Changed-Why:
    confirmed as a bug. I've attached a smaller test case

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view&pr=4205&database=gcc


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

* c++/4205: function template can call other function with incorrect parameters
@ 2001-09-02 10:16 Jens.Maurer
  0 siblings, 0 replies; 3+ messages in thread
From: Jens.Maurer @ 2001-09-02 10:16 UTC (permalink / raw)
  To: gcc-gnats

>Number:         4205
>Category:       c++
>Synopsis:       function template can call other function with incorrect parameters
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          accepts-illegal
>Submitter-Id:   net
>Arrival-Date:   Sun Sep 02 10:16:01 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator:     Jens Maurer
>Release:        gcc 3.0.1
>Organization:
>Environment:
Linux 2.4.8 with glibc 2.2.3
>Description:
The attached code should give an error at least in the
call to foo(&wibble), because you can't call wibble() with
just one argument, but these gcc versions don't:

gcc version 3.0.1
gcc version 3.1 20010901 (experimental)
gcc version 2.95.3 20010315 (release)
>How-To-Repeat:

// Douglas Gregor on boost 2001-08-22

#include <iostream>

template<typename F>
void foo(F f)
{
  f(1);
}

void bar(int i, int j = 5, int k = 7)
{
  std::cout << "bar(" << i << ", " << j << ", " << k << ")" << std::endl;
}

void wibble(int i, int j, int k = 9)
{
  std::cout << "wibble(" << i << ", " << j << ", " << k << ")" << std::endl;
}

int main()
{
  foo(&bar); 
  foo(&wibble); // should give an error, "wibble" cannot be called with one arg
}
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:


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

end of thread, other threads:[~2002-11-16  1:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-11-21 18:51 c++/4205: function template can call other function with incorrect parameters Wolfgang Bangerth
  -- strict thread matches above, loose matches on Subject: below --
2001-09-04  8:20 nathan
2001-09-02 10:16 Jens.Maurer

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).