C++ PATCH for Re: eg++ confusion with template argument
Mark Mitchell
mark@markmitchell.com
Fri Oct 16 13:39:00 GMT 1998
This patch fixes a problem whereby default arguments were tricking us
into not recognizing constant declarations as constant.
--
Mark Mitchell mark@markmitchell.com
Mark Mitchell Consulting http://www.markmitchell.com
1998-10-16 Mark Mitchell <mark@markmitchell.com>
* pt.c (for_each_template_parm): Don't examine uninstantiated
default arguments.
Index: testsuite/g++.old-deja/g++.pt/defarg5.C
===================================================================
RCS file: defarg5.C
diff -N defarg5.C
*** /dev/null Mon Dec 31 20:00:00 1979
--- defarg5.C Fri Oct 16 13:02:23 1998
***************
*** 0 ****
--- 1,24 ----
+ // Build don't link:
+
+ template <int dim>
+ class Point {
+ public:
+ Point (Point<dim> &);
+ Point<dim> & operator = (Point<dim> &);
+ };
+
+
+
+ template <int dim>
+ class bar{
+ public:
+ void foo (Point<dim> p = Point<dim>());
+ };
+
+
+
+ template <>
+ void bar<2>::foo (Point<2> p) {
+ const int dim = 2;
+ Point<dim> q = p;
+ };
Index: cp/pt.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/pt.c,v
retrieving revision 1.215
diff -c -p -r1.215 pt.c
*** pt.c 1998/10/14 21:16:36 1.215
--- pt.c 1998/10/16 20:02:46
*************** for_each_template_parm (t, fn, data)
*** 3766,3787 ****
return for_each_template_parm (TREE_VALUE
(TYPE_TEMPLATE_INFO (t)),
fn, data);
! case FUNCTION_TYPE:
! if (for_each_template_parm (TYPE_ARG_TYPES (t), fn, data))
return 1;
return for_each_template_parm (TREE_TYPE (t), fn, data);
case ARRAY_TYPE:
if (for_each_template_parm (TYPE_DOMAIN (t), fn, data))
return 1;
return for_each_template_parm (TREE_TYPE (t), fn, data);
case OFFSET_TYPE:
if (for_each_template_parm (TYPE_OFFSET_BASETYPE (t), fn, data))
- return 1;
- return for_each_template_parm (TREE_TYPE (t), fn, data);
- case METHOD_TYPE:
- if (for_each_template_parm (TYPE_METHOD_BASETYPE (t), fn, data))
- return 1;
- if (for_each_template_parm (TYPE_ARG_TYPES (t), fn, data))
return 1;
return for_each_template_parm (TREE_TYPE (t), fn, data);
--- 3766,3800 ----
return for_each_template_parm (TREE_VALUE
(TYPE_TEMPLATE_INFO (t)),
fn, data);
! case METHOD_TYPE:
! if (for_each_template_parm (TYPE_METHOD_BASETYPE (t), fn, data))
return 1;
+ /* Fall through. */
+
+ case FUNCTION_TYPE:
+ /* Check the parameter types. Since default arguments are not
+ instantiated until they are needed, the TYPE_ARG_TYPES may
+ contain expressions that involve template parameters. But,
+ no-one should be looking at them yet. And, once they're
+ instantiated, they don't contain template parameters, so
+ there's no point in looking at them then, either. */
+ {
+ tree parm;
+
+ for (parm = TYPE_ARG_TYPES (t); parm; parm = TREE_CHAIN (parm))
+ if (for_each_template_parm (TREE_VALUE (parm), fn, data))
+ return 1;
+ }
+
+ /* Check the return type, too. */
return for_each_template_parm (TREE_TYPE (t), fn, data);
+
case ARRAY_TYPE:
if (for_each_template_parm (TYPE_DOMAIN (t), fn, data))
return 1;
return for_each_template_parm (TREE_TYPE (t), fn, data);
case OFFSET_TYPE:
if (for_each_template_parm (TYPE_OFFSET_BASETYPE (t), fn, data))
return 1;
return for_each_template_parm (TREE_TYPE (t), fn, data);
More information about the Gcc-bugs
mailing list