C++ PATCH: PR 10939

Mark Mitchell mark@codesourcery.com
Fri Jun 20 06:46:00 GMT 2003


This patch fixes PR c++/10939 by checking to see if a FUNCTION_DECL is
actually dependent before trying to substitute into it.  The 3.3 patch
is slightly different because value_dependent_expression_p did not
exist at that point.

Tested on i686-pc-linux-gnu, applied on the mainline and on the
branch.

--
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com

2003-06-19  Mark Mitchell  <mark@codesourcery.com>

	PR c++/10939
	* pt.c (tsubst_decl): Do not try to substitute into non-dependent
	functions.
	(value_dependent_expression_p): Correct logic for FUNCTION_DECLs.

2003-06-19  Mark Mitchell  <mark@codesourcery.com>

	PR c++/10939
	* g++.dg/template/func1.C: New test.

Index: cp/pt.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/pt.c,v
retrieving revision 1.702
diff -c -5 -p -r1.702 pt.c
*** cp/pt.c	19 Jun 2003 01:24:07 -0000	1.702
--- cp/pt.c	20 Jun 2003 05:49:28 -0000
*************** tsubst_decl (tree t, tree args, tree typ
*** 5907,5916 ****
--- 5907,5927 ----
  	my_friendly_assert (DECL_TEMPLATE_INFO (t) != NULL_TREE, 0);
  
  	if (TREE_CODE (DECL_TI_TEMPLATE (t)) == TEMPLATE_DECL)
  	  {
  	    tree spec;
+ 	    bool dependent_p;
+ 
+ 	    /* If T is not dependent, just return it.  We have to
+ 	       increment PROCESSING_TEMPLATE_DECL because
+ 	       value_dependent_expression_p assumes that nothing is
+ 	       dependent when PROCESSING_TEMPLATE_DECL is zero.  */
+ 	    ++processing_template_decl;
+ 	    dependent_p = value_dependent_expression_p (t);
+ 	    --processing_template_decl;
+ 	    if (!dependent_p)
+ 	      return t;
  
  	    /* Calculate the most general template of which R is a
  	       specialization, and the complete set of arguments used to
  	       specialize R.  */
  	    gen_tmpl = most_general_template (DECL_TI_TEMPLATE (t));
*************** value_dependent_expression_p (tree expre
*** 11366,11377 ****
    if (!processing_template_decl)
      return false;
  
    /* A name declared with a dependent type.  */
    if (TREE_CODE (expression) == LOOKUP_EXPR
!       || (DECL_P (expression)
! 	  && dependent_type_p (TREE_TYPE (expression))))
      return true;
    /* A non-type template parameter.  */
    if ((TREE_CODE (expression) == CONST_DECL
         && DECL_TEMPLATE_PARM_P (expression))
        || TREE_CODE (expression) == TEMPLATE_PARM_INDEX)
--- 11377,11388 ----
    if (!processing_template_decl)
      return false;
  
    /* A name declared with a dependent type.  */
    if (TREE_CODE (expression) == LOOKUP_EXPR
!       || (DECL_P (expression) 
! 	  && type_dependent_expression_p (expression)))
      return true;
    /* A non-type template parameter.  */
    if ((TREE_CODE (expression) == CONST_DECL
         && DECL_TEMPLATE_PARM_P (expression))
        || TREE_CODE (expression) == TEMPLATE_PARM_INDEX)
Index: testsuite/g++.dg/template/func1.C
===================================================================
RCS file: testsuite/g++.dg/template/func1.C
diff -N testsuite/g++.dg/template/func1.C
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- testsuite/g++.dg/template/func1.C	20 Jun 2003 05:49:29 -0000
***************
*** 0 ****
--- 1,13 ----
+ template <typename T1,typename T2>
+ inline void f(const T1&,const T2&) { }
+ 
+ template <typename T1,typename T2,void F(const T1&,const T2&)>
+ struct A {
+     template <typename T> void g(T& i) { }
+ };
+ 
+ int main() {
+     int i;
+     A<int,int,f> a;
+     a.g(i);
+ }



More information about the Gcc-patches mailing list