This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
PATCH: Fix PR2765
- To: gcc-patches at gcc dot gnu dot org
- Subject: PATCH: Fix PR2765
- From: Mark Mitchell <mark at codesourcery dot com>
- Date: Thu, 24 May 2001 23:31:57 -0700
- Organization: CodeSourcery, LLC
This patch fixes PR2765, the regression on file-scope division by
zero.
With no response from Jakub, I've essentially reverted his original
change, which I'm now pretty convinced was incorrect. If C99 needs to
allow non-constants in this context, it shouldn't be setting
REQUIRE_CONSTANT; simple as that.
Bootstrapped and tested on i686-pc-linux-gnu, installed on the
mainline and on the branch.
--
Mark Mitchell mark@codesourcery.com
CodeSourcery, LLC http://www.codesourcery.com
2001-05-24 Mark Mitchell <mark@codesourcery.com>
* c-typeck.c (digest_init): Issue error messages about
invalid constants, not warnings.
Index: c-typeck.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-typeck.c,v
retrieving revision 1.114.2.4
diff -c -p -r1.114.2.4 c-typeck.c
*** c-typeck.c 2001/05/01 00:09:48 1.114.2.4
--- c-typeck.c 2001/05/25 06:14:17
*************** digest_init (type, init, require_constan
*** 4777,4790 ****
if (flag_pedantic_errors)
inside_init = error_mark_node;
}
! else if (require_constant && ! TREE_CONSTANT (inside_init))
{
error_init ("initializer element is not constant");
inside_init = error_mark_node;
}
- else if (require_constant
- && initializer_constant_valid_p (inside_init, TREE_TYPE (inside_init)) == 0)
- pedwarn ("initializer element is not computable at load time");
return inside_init;
}
--- 4777,4797 ----
if (flag_pedantic_errors)
inside_init = error_mark_node;
}
! else if (require_constant
! && (!TREE_CONSTANT (inside_init)
! /* This test catches things like `7 / 0' which
! result in an expression for which TREE_CONSTANT
! is true, but which is not actually something
! that is a legal constant. We really should not
! be using this function, because it is a part of
! the back-end. Instead, the expression should
! already have been turned into ERROR_MARK_NODE. */
! || !initializer_constant_valid_p (inside_init,
! TREE_TYPE (inside_init))))
{
error_init ("initializer element is not constant");
inside_init = error_mark_node;
}
return inside_init;
}
Index: testsuite/gcc.dg/noncompile/20010524-1.c
===================================================================
RCS file: 20010524-1.c
diff -N 20010524-1.c
*** /dev/null Tue May 5 13:32:27 1998
--- 20010524-1.c Thu May 24 23:14:24 2001
***************
*** 0 ****
--- 1,2 ----
+ int i = 7 / 0; /* { dg-error "not constant" } */
+