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]

Re: PATCH for division by zero in template arguments


>>>>> "Jason" == Jason Merrill <jason@cygnus.com> writes:

    Jason> Perhaps what it means is that it's ill-formed in any
    Jason> situation that expects a constant-expression.  So

Perhaps.

    >> Why call something that must be evaluated at run-time a
    >> constant?

    Jason> Precedent.  The C frontend does.

I find those semantics confusing, but so be it. 

I've checked in the patch below.

-- 
Mark Mitchell 			mark@markmitchell.com
Mark Mitchell Consulting	http://www.markmitchell.com

1998-06-17  Mark Mitchell  <mark@markmitchell.com>

	* pt.c (convert_nontype_argument): Issue an error when presented
	with an integer (real) constant that cannot be simplified to an
	INT_CST (REAL_CST).

Index: pt.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/pt.c,v
retrieving revision 1.156
diff -c -p -r1.156 pt.c
*** pt.c	1998/06/13 23:35:45	1.156
--- pt.c	1998/06/18 04:46:23
*************** convert_nontype_argument (type, expr)
*** 2056,2061 ****
--- 2056,2062 ----
      {
        if (! TREE_CONSTANT (expr))
  	{
+ 	non_constant:
  	  cp_error ("non-constant `%E' cannot be used as template argument",
  		    expr);
  	  return NULL_TREE;
*************** convert_nontype_argument (type, expr)
*** 2128,2143 ****
        
        /* It's safe to call digest_init in this case; we know we're
  	 just converting one integral constant expression to another.  */
!       return digest_init (type, expr, (tree*) 0);
  
      case REAL_TYPE:
      case COMPLEX_TYPE:
        /* These are g++ extensions.  */
        if (TREE_CODE (expr_type) != TREE_CODE (type))
  	return error_mark_node;
  
!       return digest_init (type, expr, (tree*) 0);
  
      case POINTER_TYPE:
        {
  	tree type_pointed_to = TREE_TYPE (type);
--- 2129,2157 ----
        
        /* It's safe to call digest_init in this case; we know we're
  	 just converting one integral constant expression to another.  */
!       expr = digest_init (type, expr, (tree*) 0);
  
+       if (TREE_CODE (expr) != INTEGER_CST)
+ 	/* Curiously, some TREE_CONSTNAT integral expressions do not
+ 	   simply to integer constants: for example, things like `3 %
+ 	   0'.  */
+ 	goto non_constant;
+       
+       return expr;
+ 	
      case REAL_TYPE:
      case COMPLEX_TYPE:
        /* These are g++ extensions.  */
        if (TREE_CODE (expr_type) != TREE_CODE (type))
  	return error_mark_node;
  
!       expr = digest_init (type, expr, (tree*) 0);
!       
!       if (TREE_CODE (expr) != REAL_CST)
! 	goto non_constant;
  
+       return expr;
+ 
      case POINTER_TYPE:
        {
  	tree type_pointed_to = TREE_TYPE (type);


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