This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/28385] New: templated function call goes awry
- From: "Colin dot McCabe at ecitele dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 14 Jul 2006 19:52:10 -0000
- Subject: [Bug c++/28385] New: templated function call goes awry
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
I have compiled the following code under gcc 3.4.6, 4.0.2, and 4.1.1:
=========================================================
#include <iostream>
class Foo {
public:
template<typename T>
void operator()(const T& fcn) {
std::cout << "calling fcn()..." << std::endl;
fcn();
}
};
void bar() {
std::cout << "bar()" << std::endl;
}
int main() {
Foo myFoo;
myFoo(bar);
myFoo(&bar);
return 0;
}
========================================================
Output for gcc 4.0.2 and 4.1.1:
calling bar()...
calling bar()...
bar()
Output for gcc 3.4.6:
calling bar()...
bar()
calling bar()...
bar()
Also, if you change
void operator()(const T& fcn) {
to
void operator()(const T fcn) {
It successfully makes both function calls on every version of gcc.
Everyone knows that in C, "&function_name" and "function_name" are generally
equivalent-- you can write:
func_ptr_type* f = &function_name;
or
func_ptr_type* f = function_name;
So it is surprising to me that
myFoo(bar);
seems to behave differently than:
myFoo(&bar);
I'm also surprised that there is no type error or other diagnostic message in
cases where code to call bar() is omitted.
--
Summary: templated function call goes awry
Product: gcc
Version: 4.1.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: Colin dot McCabe at ecitele dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28385