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] Handle GNU style COND_EXPRs with omitted middle arg (PR c++/34270)


Hi!

In templates x ?: y is represented as COND_EXPR with
TREE_OPERAND (cond_expr, 1) == NULL, but several routines just assume it
must be always there.  If it is missing, the condition should be used
instead.

Ok for trunk?

2007-11-29  Jakub Jelinek  <jakub@redhat.com>

	PR c++/34270
	* tree.c (lvalue_p_1) <case COND_EXPR>: Handle x ?: y
	in templates.
	* typeck.c (is_bitfield_expr_with_lowered_type) <case COND_EXPR>:
	Likewise.

	* g++.dg/template/cond7.C: New test.

--- gcc/cp/tree.c.jj	2007-11-26 22:19:48.000000000 +0100
+++ gcc/cp/tree.c	2007-11-29 11:16:49.000000000 +0100
@@ -160,7 +160,9 @@ lvalue_p_1 (const_tree ref,
       break;
 
     case COND_EXPR:
-      op1_lvalue_kind = lvalue_p_1 (TREE_OPERAND (ref, 1),
+      op1_lvalue_kind = lvalue_p_1 (TREE_OPERAND (ref, 1)
+				    ? TREE_OPERAND (ref, 1)
+				    : TREE_OPERAND (ref, 0),
 				    treat_class_rvalues_as_lvalues);
       op2_lvalue_kind = lvalue_p_1 (TREE_OPERAND (ref, 2),
 				    treat_class_rvalues_as_lvalues);
--- gcc/cp/typeck.c.jj	2007-11-26 11:02:22.000000000 +0100
+++ gcc/cp/typeck.c	2007-11-29 11:15:59.000000000 +0100
@@ -1419,7 +1419,9 @@ is_bitfield_expr_with_lowered_type (cons
   switch (TREE_CODE (exp))
     {
     case COND_EXPR:
-      if (!is_bitfield_expr_with_lowered_type (TREE_OPERAND (exp, 1)))
+      if (!is_bitfield_expr_with_lowered_type (TREE_OPERAND (exp, 1)
+					       ? TREE_OPERAND (exp, 1)
+					       : TREE_OPERAND (exp, 0)))
 	return NULL_TREE;
       return is_bitfield_expr_with_lowered_type (TREE_OPERAND (exp, 2));
 
--- gcc/testsuite/g++.dg/template/cond7.C.jj	2007-11-29 11:19:38.000000000 +0100
+++ gcc/testsuite/g++.dg/template/cond7.C	2007-11-29 11:17:55.000000000 +0100
@@ -0,0 +1,15 @@
+// PR c++/34270
+// { dg-do compile }
+// { dg-options "" }
+
+void foo ()
+{
+  __typeof__ (0 ?: 0) x;
+  __decltype (0 ?: 0) y;
+}
+
+template<int> void bar ()
+{
+  __typeof__ (0 ?: 0) x;
+  __decltype (0 ?: 0) y;
+}

	Jakub


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