template in namespace; constructor calls

Pal Benko benko@sztaki.hu
Mon Aug 2 05:06:00 GMT 1999


Input (namespace.cc):

namespace bar
{
  template <typename T>
  T const foo(T const &);
}

template <typename T>
T const
bar::foo(T const &a)
{
  return a;
}

--------------------------------------
$ g++ -v
Reading specs from /usr/local/gcc-2.95/lib/gcc-lib/i686-pc-linux-gnu/2.95/specs
gcc version 2.95 19990728 (release)
$ g++ namespace.cc -c
namespace.cc:10: `bar::foo(const T &)' should have been declared inside `bar'

--------------------------------------

The non-template version compiles.  This version compiles and runs
correctly on older versions (egcs-1.1.2).


=============================================================================

Another problem (I do not know who is right):

the compiler takes the following line:

type1 f(type2(a));

to be a declaration of a function f taking one parameter of type2
called a, returning type1.

I meant a variable f of type type1 constructed from a temporary of
type type2 which in turn is constructed from a.

In this case there is no difference between different versions of gcc.

Benko Pal



More information about the Gcc-bugs mailing list