Bug 16313 - Function's address automatically taken
Summary: Function's address automatically taken
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.0.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-07-01 10:31 UTC by akim@lrde.epita.fr
Modified: 2005-07-23 22:49 UTC (History)
1 user (show)

See Also:
Host: i486-pc-linux-gnu
Target: i486-pc-linux-gnu
Build: i486-pc-linux-gnu
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description akim@lrde.epita.fr 2004-07-01 10:31:08 UTC
NOTE: Defaulting component because reported component no longer exists

Consider the following piece of code:

void foo (){}

template < typename T >
void
bar (const T &arg)
{
  (void) arg;
}

int
main ()
{
  bar (foo);
}

G++ 3.3, 3.4, and ICC 7.1 consider it invalid: bar (foo) must be
written bar (&foo).  Nevertheless 3.5 accepts it.  I'm tempted to say
this piece of code is invalid, but IANALL :)

Environment:
System: Linux nostromo 2.4.25 #2 Mon Mar 15 12:03:26 CET 2004 i686 GNU/Linux
Architecture: i686

	
host: i486-pc-linux-gnu
build: i486-pc-linux-gnu
target: i486-pc-linux-gnu
configured with: ../src/configure -v --enable-languages=c,c++,java,f95,objc --prefix=/usr/lib/gcc-snapshot --enable-shared --with-system-zlib --enable-nls --enable-threads=posix --without-included-gettext --disable-werror --enable-__cxa_atexit --enable-clocale=gnu --enable-libstdcxx-debug --enable-java-gc=boehm --enable-java-awt=gtk i486-linux-gnu

How-To-Repeat:

~/tmp % icc foo.cc
foo.cc(18): error: no instance of function template "bar" matches the argument list
            argument types are: (void ())
    bar (foo);
    ^

compilation aborted for foo.cc (code 2)
~/tmp % g++-3.4 foo.cc
foo.cc: In function `int main()':
foo.cc:18: error: pas de fonction concordante pour l'appel de «bar(void (&)())»
~/tmp % g++-3.5 foo.cc
~/tmp %
Comment 1 Volker Reichelt 2004-07-01 11:46:37 UTC
Your code is valid, so mainline's behavior is correct.
GCC 3.4.1 will also accept it.

An explanation and the patches that fixed the compiler can be found
in PR 3518.

Btw, your code is accepted by gcc 2.95.x, rejected by gcc 3.0.x,
again accepted by gcc 3.1 - 3.2.1, again rejected by gcc 3.2.2 - 3.4.0,
and (hopefully) finally accepted by 3.4.1 and later. ICC 8.0 also accepts
the code.