Patch for bug with constant template parameters
Mark Mitchell
mmitchell@usa.net
Wed Dec 17 10:01:00 GMT 1997
Here's a patch for code like this:
template<unsigned int n> struct PartialDotProduct {
template<class T>
static T Expand(T* a, T* b) { return T(); }
};
const int N = 10;
template<class In1, class In2>
void
dot(In1 f1, In2 f2)
{
PartialDotProduct<N>::Expand(f1, f2);
}
int main()
{
double a[N], b[N];
dot(&a[0], &b[0]);
}
We were complaining (incorrectly) that N was not constant in the
definition of dot().
--
Mark Mitchell mmitchell@usa.net
Stanford University http://www.stanford.edu
Wed Dec 17 09:53:56 1997 Mark Mitchell <mmitchell@usa.net>
* pt.c (coerce_template_parms): Make sure to digest_init if
possible.
(maybe_fold_nontype_arg): Add prototype.
Index: gcc/cp/pt.c
===================================================================
RCS file: /home/mitchell/Repository/egcs/gcc/cp/pt.c,v
retrieving revision 1.1.1.6
diff -c -p -r1.1.1.6 pt.c
*** pt.c 1997/12/17 06:31:08 1.1.1.6
--- pt.c 1997/12/17 17:46:06
*************** static int type_unification_real PROTO(
*** 82,87 ****
--- 82,88 ----
int, int, int));
static int processing_explicit_specialization PROTO((int));
static void note_template_header PROTO((int));
+ static tree maybe_fold_nontype_arg PROTO((tree));
/* Restore the template parameter context. */
*************** coerce_template_parms (parms, arglist, i
*** 1078,1084 ****
if (processing_template_decl)
val = maybe_fold_nontype_arg (arg);
else
! val = digest_init (t, arg, (tree *) 0);
if (val == error_mark_node
|| (processing_template_decl && uses_template_parms (val)))
--- 1079,1088 ----
if (processing_template_decl)
val = maybe_fold_nontype_arg (arg);
else
! val = arg;
!
! if (!uses_template_parms (val) && !uses_template_parms (t))
! val = digest_init (t, val, (tree *) 0);
if (val == error_mark_node
|| (processing_template_decl && uses_template_parms (val)))
Index: gcc/testsuite/g++.old-deja/g++.pt/memtemp65.C
===================================================================
RCS file: memtemp65.C
diff -N memtemp65.C
*** /dev/null Mon Dec 31 20:00:00 1979
--- memtemp65.C Fri Dec 5 11:18:46 1997
***************
*** 0 ****
--- 1,23 ----
+ // Build don't link:
+
+ template<unsigned int n> struct PartialDotProduct {
+ template<class T>
+ static T Expand(T* a, T* b) { return T(); }
+ };
+
+ const int N = 10;
+
+ template<class In1, class In2>
+ void
+ dot(In1 f1, In2 f2)
+ {
+ PartialDotProduct<N>::Expand(f1, f2);
+
+ }
+
+ int main()
+ {
+ double a[N], b[N];
+
+ dot(&a[0], &b[0]);
+ }
More information about the Gcc-bugs
mailing list