Patchwork C++ PATCH for c++/56998 (ICE with call in C++03 mode)

login
register
mail settings
Submitter Jason Merrill
Date May 14, 2013, 12:50 p.m.
Message ID <519232FC.2070207@redhat.com>
Download mbox | patch
Permalink /patch/243696/
State New
Headers show

Comments

Jason Merrill - May 14, 2013, 12:50 p.m.
On 05/13/2013 03:36 PM, Jakub Jelinek wrote:
> What about the 4 other
> maybe_constant_value on fold_non_dependent_expr_sfinae (something, tf_none)
> calls in typeck.c (two for -Wdiv-by-zero and two for shift diagnostics)?

You're right, that was a poor approach to fixing the bug.  This one 
properly fixes potential_constant_expression to recognize that the 
expression can't be constant, so it never gets to 
value_dependent_expression.

Patch

commit 24c19b3d38977fafbf870ef2ea45d05f37feb36a
Author: Jason Merrill <jason@redhat.com>
Date:   Mon May 13 17:09:36 2013 -0400

    	PR c++/56998
    	* semantics.c (potential_constant_expression_1): Make sure the
    	called function is potentially constant.
    	* call.c (null_ptr_cst_p): Revert earlier change.

diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index 9f3a50d..bd8f531 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -554,7 +554,7 @@  null_ptr_cst_p (tree t)
   if (CP_INTEGRAL_TYPE_P (TREE_TYPE (t)))
     {
       /* Core issue 903 says only literal 0 is a null pointer constant.  */
-      if (cxx_dialect < cxx0x && !TREE_SIDE_EFFECTS (t))
+      if (cxx_dialect < cxx0x)
 	t = maybe_constant_value (fold_non_dependent_expr_sfinae (t, tf_none));
       STRIP_NOPS (t);
       if (integer_zerop (t) && !TREE_OVERFLOW (t))
diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index 3e78887..92a4917 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -8476,7 +8476,11 @@  potential_constant_expression_1 (tree t, bool want_rval, tsubst_flags_t flags)
 		  }
 	      }
 	    else
-	      fun = get_first_fn (fun);
+	      {
+		if (!potential_constant_expression_1 (fun, true, flags))
+		  return false;
+		fun = get_first_fn (fun);
+	      }
 	    /* Skip initial arguments to base constructors.  */
 	    if (DECL_BASE_CONSTRUCTOR_P (fun))
 	      i = num_artificial_parms_for (fun);