This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: c++/4205: function template can call other function with incorrectparameters
- From: Wolfgang Bangerth <bangerth at ticam dot utexas dot edu>
- To: gcc-bugs at gcc dot gnu dot org, <gcc-gnats at gcc dot gnu dot org>, <nathan at codesourcery dot com>, <gdr at codesourcery dot com>
- Date: Fri, 15 Nov 2002 19:55:02 -0600 (CST)
- Subject: Re: c++/4205: function template can call other function with incorrectparameters
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