Hi!

This patch reverts part of
https://gcc.gnu.org/ml/gcc-patches/2012-10/msg01665.html
which looks wrong to me.
The problem is that in templates, if the build_x_conditional_expr
arguments aren't type dependent, we might get NON_DEPENDENT_EXPR
wrappers around the argument, so after issuing possibly needed diagnostics
we need to return back to the original unmodified arguments,
which for VEC_COND_EXPR the condition has been bypassing and we ended up
with NON_DEPENDENT_EXPR in the IL, which nothing strips away
(plus VEC_COND_EXPR isn't really supported in tsubst_copy/tsubst_copy_and_build
and perhaps other spots).
While we could do build_min_non_dep with VEC_COND_EXPR and teach pt.c about
VEC_COND_EXPR, I really don't see advantages of doing that, if we build just
COND_EXPR, build_min_non_dep ensures that it will have the right type, and
when we instantiate it build_x_conditional_expr will be called again and
that will create VEC_COND_EXPR when not processing_template_decl.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2016-07-14  Jakub Jelinek  <ja...@redhat.com>

        PR c++/71871
        * typeck.c (build_x_conditional_expr): Revert the 2012-10-25 change.

        * g++.dg/ext/vector31.C: New test.

--- gcc/cp/typeck.c.jj  2016-07-11 11:14:28.000000000 +0200
+++ gcc/cp/typeck.c     2016-07-14 12:47:48.436699222 +0200
@@ -6288,8 +6288,7 @@ build_x_conditional_expr (location_t loc
     }
 
   expr = build_conditional_expr (loc, ifexp, op1, op2, complain);
-  if (processing_template_decl && expr != error_mark_node
-      && TREE_CODE (expr) != VEC_COND_EXPR)
+  if (processing_template_decl && expr != error_mark_node)
     {
       tree min = build_min_non_dep (COND_EXPR, expr,
                                    orig_ifexp, orig_op1, orig_op2);
--- gcc/testsuite/g++.dg/ext/vector31.C.jj      2016-07-14 13:01:04.933206583 
+0200
+++ gcc/testsuite/g++.dg/ext/vector31.C 2016-07-14 13:00:59.943272143 +0200
@@ -0,0 +1,29 @@
+// PR c++/71871
+// { dg-do compile }
+
+typedef unsigned int V __attribute__ ((__vector_size__ (32)));
+
+template <int N>
+void
+foo (V *x)
+{
+  V a = *x;
+  a = a ? a : -1;
+  *x = a;
+}
+
+template <typename T>
+void
+bar (T *x)
+{
+  T a = *x;
+  a = a ? a : -1;
+  *x = a;
+}
+
+void
+test (V *x, V *y)
+{
+  foo<0> (x);
+  bar<V> (y);
+}

        Jakub

Reply via email to