This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
2.95.1 doesn't permit default template parameter?
- To: GCC Bug Reports <gcc-bugs at gcc dot gnu dot org>
- Subject: 2.95.1 doesn't permit default template parameter?
- From: Jonathan Thornburg <jthorn at galileo dot thp dot univie dot ac dot at>
- Date: Mon, 13 Sep 1999 19:47:22 +0200
- Cc: Jonathan Thornburg <jthorn at galileo dot thp dot univie dot ac dot at>
This is a I'm-pretty-sure-it's-a-bug report for gcc version 2.95.1
on sparc-sun-sunos4.1.3: default template parameters don't seem to
work.
For example, consider the input file
#include <stdio.h>
template <int X>
inline int tfn(int i)
{
return i + X;
}
template <int X, int Y>
inline int tfn(int i)
{
return X + Y*i;
}
#ifdef DEFAULT
// default template parameter syntax as per C++PL3 section 13.4.1
template <int X, int Y = 100>
inline int dfn(int i)
{
return X + Y*i;
}
#endif
int main()
{
printf("tfn<2>(10) = %d\n", tfn<2>(10));
printf("tfn<2,3>(10) = %d\n", tfn<2,3>(10));
#ifdef DEFAULT
printf("dfn<2>(10) = %d\n", dfn<2>(10));
printf("dfn<2,3>(10) = %d\n", dfn<2,3>(10));
#endif
return 0;
}
The error message:
% /usr/local/bin/g++ --version
2.95.1
% /usr/local/bin/g++ -Wall -o tov tov.cc
% ./tov
tfn<2>(10) = 12
tfn<2,3>(10) = 32
% /usr/local/bin/g++ -Wall -DDEFAULT -o tov tov.cc
tov.cc: In function `int dfn(int)':
tov.cc:19: default argument for template parameter in function template `dfn(int)'
tov.cc: In function `int main()':
tov.cc:29: no matching function for call to `dfn (int)'
%
Notice that without -DDEFAULT (so there are no default template parameters
specified), everything is fine, but with -DDEFAULT (parameter Y for the
template dfn() is defaulted), gcc gives an error.
So far as I can see, the -DDEFAULT code is correct C++, as per C++PL3
section 13.4.1. (If I'm mistaken, and this is in fact not valid C++,
my apologies.) I have grepped all occurences of 'template' in the gcc
2.95.1 info files, and not found any statements that this usage isn't
supported.
--
-- Jonathan Thornburg <jthorn@galileo.thp.univie.ac.at>
http://www.thp.univie.ac.at/~jthorn/home.html
Universitaet Wien (Vienna, Austria) / Institut fuer Theoretische Physik
"There are no significant bugs in our released software that any
significant number of users want fixed." - Bill Gates, 23 Oct 1995