This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

C++ PATCH: PR 5919


This patch fixes PR 5919 by using the (newish)
variably_modified_type_p function to test the validity of types during
template argument deduction.

-- 
Mark Mitchell                   mark@codesourcery.com
CodeSourcery, LLC               http://www.codesourcery.com

2002-12-01  Mark Mitchell  <mark@codesourcery.com>

	PR c++/5919
	* g++.dg/template/varmod1.C: New test.

2002-12-01  Mark Mitchell  <mark@codesourcery.com>

	PR c++/5919
	* pt.c (unify): Use variably_modified_type_p to test validity of
	template argument types.
	
Index: cp/pt.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/pt.c,v
retrieving revision 1.633
diff -c -p -r1.633 pt.c
*** cp/pt.c	1 Dec 2002 04:55:19 -0000	1.633
--- cp/pt.c	1 Dec 2002 20:42:13 -0000
*************** unify (tparms, targs, parm, arg, strict)
*** 8852,8872 ****
  	    return 0;
  	  else if (targ)
  	    return 1;
- 	}
  
!       /* Make sure that ARG is not a variable-sized array.  (Note that
! 	 were talking about variable-sized arrays (like `int[n]'),
! 	 rather than arrays of unknown size (like `int[]').)  We'll
! 	 get very confused by such a type since the bound of the array
! 	 will not be computable in an instantiation.  Besides, such
! 	 types are not allowed in ISO C++, so we can do as we please
! 	 here.  */
!       if (TREE_CODE (arg) == ARRAY_TYPE 
! 	  && !uses_template_parms (arg)
! 	  && TYPE_DOMAIN (arg)
! 	  && (TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (arg)))
! 	      != INTEGER_CST))
! 	return 1;
  
        TREE_VEC_ELT (targs, idx) = arg;
        return 0;
--- 8852,8868 ----
  	    return 0;
  	  else if (targ)
  	    return 1;
  
! 	  /* Make sure that ARG is not a variable-sized array.  (Note
! 	     that were talking about variable-sized arrays (like
! 	     `int[n]'), rather than arrays of unknown size (like
! 	     `int[]').)  We'll get very confused by such a type since
! 	     the bound of the array will not be computable in an
! 	     instantiation.  Besides, such types are not allowed in
! 	     ISO C++, so we can do as we please here.  */
! 	  if (variably_modified_type_p (arg))
! 	    return 1;
! 	}
  
        TREE_VEC_ELT (targs, idx) = arg;
        return 0;
Index: testsuite/g++.dg/template/varmod1.C
===================================================================
RCS file: testsuite/g++.dg/template/varmod1.C
diff -N testsuite/g++.dg/template/varmod1.C
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- testsuite/g++.dg/template/varmod1.C	1 Dec 2002 20:44:04 -0000
***************
*** 0 ****
--- 1,10 ----
+ // { dg-options "-w" }
+ 
+ template<typename T> void foo(T);
+  
+ void bar()
+ {
+   int i;
+   int A[i][i]; 
+   foo(A); // { dg-error } 
+ }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]