This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Patch for internal compiler errors with template recursion
- To: Jim Peterson <jspeter at roanoke dot infi dot net>, Jason Merrill <jason at cygnus dot com>, egcs-bugs at cygnus dot com
- Subject: Patch for internal compiler errors with template recursion
- From: Mark Mitchell <mmitchell at usa dot net>
- Date: Sun, 7 Dec 1997 17:47:41 -0800
- Reply-to: mmitchell at usa dot net
You reported two bugs today:
template<int N> f<0>(){}
This bug is fixed by a patch I posted earlier today. I believe Jason
has already installed his own version (it turned out we fixed the same
bug at roughly the same time) which presumably fixes this
problem as well. Jason? My version gives:
supernova% test-g++ -c test2.cc
test2.cc:1: specialization does not match any template declaration
Then you mentioned:
const double M_PI=3.14159265358979323846;
template<int N,int I,int J,int K>
inline double SineSeries()
{
const double x=I*2*M_PI/N;
const bool go=K+1!=J;
return 1.0-x*x/(2*K+2)/(2*K+3)*SineSeries<N*go,I*go,J*go,(K+1)*go>();
}
template<>
inline double SineSeries<0,0,0,0>()
{
return 1.0;
}
template<int N,int I>
inline double Sine()
{
const double x=(I*2*M_PI/N);
return x * SineSeries<N,I,10,0>();
}
int main()
{
double f=Sine<32,5>();
return 0;
}
I've appended a patch for this. (BTW, f seems to be 0.83147, which is
sin(5*2*pi/32), so I think that the program works now. I note that at -O4
all the calls were successfully inlined so that you get no run-time
computation as you had hoped.)
--
Mark Mitchell mmitchell@usa.net
Stanford University http://www.stanford.edu
Index: gcc/cp/pt.c
===================================================================
RCS file: /home/mitchell/Repository/egcs/gcc/cp/pt.c,v
retrieving revision 1.5
diff -c -p -r1.5 pt.c
*** pt.c 1997/12/07 22:50:40 1.5
--- pt.c 1997/12/08 01:30:26
*************** lookup_template_function (fns, arglist)
*** 1350,1360 ****
}
if (arglist != NULL_TREE && !TREE_PERMANENT (arglist))
! {
! push_obstacks (&permanent_obstack, &permanent_obstack);
! arglist = copy_list (arglist);
! pop_obstacks ();
! }
return build_min (TEMPLATE_ID_EXPR,
TREE_TYPE (fns)
--- 1350,1356 ----
}
if (arglist != NULL_TREE && !TREE_PERMANENT (arglist))
! copy_to_permanent (arglist);
return build_min (TEMPLATE_ID_EXPR,
TREE_TYPE (fns)
Index: gcc/testsuite/g++.old-deja/g++.pt/recursion.C
===================================================================
RCS file: recursion.C
diff -N recursion.C
*** /dev/null Mon Dec 31 20:00:00 1979
--- recursion.C Sun Dec 7 17:35:14 1997
***************
*** 0 ****
--- 1,31 ----
+ // Build don't link:
+
+ const double M_PI=3.14159265358979323846;
+
+ template<int N,int I,int J,int K>
+ inline double SineSeries()
+ {
+ const double x=I*2*M_PI/N;
+ const bool go=K+1!=J;
+ return 1.0-x*x/(2*K+2)/(2*K+3)*SineSeries<N*go,I*go,J*go,(K+1)*go>();
+ }
+
+ template<>
+ inline double SineSeries<0,0,0,0>()
+ {
+ return 1.0;
+ }
+
+ template<int N,int I>
+ inline double Sine()
+ {
+ const double x=(I*2*M_PI/N);
+ return x * SineSeries<N,I,10,0>();
+ }
+
+ int main()
+ {
+ double f=Sine<32,5>();
+ return 0;
+ }
+