re PR c++/48909 ([C++0x] ICE in cxx_eval_conditional_expression, at cp/semantics...
authorJason Merrill <jason@redhat.com>
Fri, 6 May 2011 21:57:49 +0000 (17:57 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Fri, 6 May 2011 21:57:49 +0000 (17:57 -0400)
PR c++/48909
* semantics.c (cxx_eval_conditional_expression): Check
integer_zerop/onep instead.

From-SVN: r173511

gcc/cp/ChangeLog
gcc/cp/semantics.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/constexpr-condition2.C [new file with mode: 0644]

index 3bc6a14680ff000bbfac2ebfcfe44557c4f5f6c8..af5e6d05544462133d16bd074d946d10a36d087f 100644 (file)
@@ -1,5 +1,10 @@
 2011-05-06  Jason Merrill  <jason@redhat.com>
 
+       PR c++/48909
+       * semantics.c (cxx_eval_conditional_expression): Check
+       integer_zerop instead.
+       (potential_constant_expression_1): Likewise.
+
        PR c++/48911
        * semantics.c (cxx_eval_array_reference): Handle implicit
        initializers.
index ca069f577000e1d76643c191d5ad422bcb43061e..d33f9fe16a9ffcfd3dfe6cc017b1ab8f7aead160 100644 (file)
@@ -6298,13 +6298,12 @@ cxx_eval_conditional_expression (const constexpr_call *call, tree t,
                                           allow_non_constant, addr,
                                           non_constant_p);
   VERIFY_CONSTANT (val);
-  if (val == boolean_true_node)
-    return cxx_eval_constant_expression (call, TREE_OPERAND (t, 1),
+  /* Don't VERIFY_CONSTANT the other operands.  */
+  if (integer_zerop (val))
+    return cxx_eval_constant_expression (call, TREE_OPERAND (t, 2),
                                         allow_non_constant, addr,
                                         non_constant_p);
-  gcc_assert (val == boolean_false_node);
-  /* Don't VERIFY_CONSTANT here.  */
-  return cxx_eval_constant_expression (call, TREE_OPERAND (t, 2),
+  return cxx_eval_constant_expression (call, TREE_OPERAND (t, 1),
                                       allow_non_constant, addr,
                                       non_constant_p);
 }
@@ -7871,12 +7870,12 @@ potential_constant_expression_1 (tree t, bool want_rval, tsubst_flags_t flags)
       tmp = TREE_OPERAND (t, 0);
       if (!potential_constant_expression_1 (tmp, rval, flags))
        return false;
-      else if (tmp == boolean_true_node)
-       return potential_constant_expression_1 (TREE_OPERAND (t, 1),
-                                               want_rval, flags);
-      else if (tmp == boolean_false_node)
+      else if (integer_zerop (tmp))
        return potential_constant_expression_1 (TREE_OPERAND (t, 2),
                                                want_rval, flags);
+      else if (TREE_CODE (tmp) == INTEGER_CST)
+       return potential_constant_expression_1 (TREE_OPERAND (t, 1),
+                                               want_rval, flags);
       for (i = 1; i < 3; ++i)
        if (potential_constant_expression_1 (TREE_OPERAND (t, i),
                                             want_rval, tf_none))
index a59b4722b201274dc5a52f230810f0ba0cf2cde8..ea142c2e956b0cf25448e25cd045970d0b623ed7 100644 (file)
@@ -1,5 +1,7 @@
 2011-05-06  Jason Merrill  <jason@redhat.com>
 
+       * g++.dg/cpp0x/constexpr-condition2.C: New.
+
        * g++.dg/cpp0x/constexpr-missing.C: New.
 
 2011-05-06  Tobias Burnus  <burnus@net-b.de>
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-condition2.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-condition2.C
new file mode 100644 (file)
index 0000000..2434096
--- /dev/null
@@ -0,0 +1,18 @@
+// PR c++/48909
+// { dg-options -std=c++0x }
+
+#define SA(X) static_assert((X),#X)
+
+constexpr int const * is_sorted_until(int const * first, int const * last)
+{
+ return first == last || first + 1 == last ? last
+  : (*(first + 1) < *first) != false ? first + 1
+  : is_sorted_until(first + 1, last);
+}
+
+int main()
+{
+ static constexpr int array[2] = {0, 1};
+ constexpr int const * last = is_sorted_until(array, array + 2);
+ SA(last==array+2);
+}