g++ 2.95.2 parse error taking address of a template function

llewelly@dbritsch.dsl.xmission.com llewelly@dbritsch.dsl.xmission.com
Sun Apr 23 21:35:00 GMT 2000


On Thu, 20 Apr 2000, Martin Sebor wrote:

> Hi,
> 
> g++ 2.95.2 gives a parse error when taking the address of a template
> function.
> 
> Thanks
> Martin
> 
> 
> $ cat test.cpp
> 
> template <class T>
> void foo ()
> {
>     void (*pf)() = &bar<T>;
> }
> 
> template <class T>
> void bar () { }
> 
> 

I think the template func needs to be declared before its first use.

{~/cc_exer}cat address_of_template_func.cc
template <class T>
  void bar () ;

template <class T>
void foo ()
{
    void (*pf)() = &bar<T>;
}

template <class T>
void bar () { }

compiles fine with gcc 2.95.2

[snip]



More information about the Gcc-bugs mailing list