Hi,

On 23/03/2018 13:39, Jason Merrill wrote:
On Fri, Mar 23, 2018 at 6:13 AM, Paolo Carlini <paolo.carl...@oracle.com> wrote:
On 22/03/2018 23:26, Jason Merrill wrote:
On Thu, Mar 22, 2018 at 5:39 PM, Paolo Carlini <paolo.carl...@oracle.com>
wrote:
... with patch ;)

If you are curious where the heck that INDIRECT_REF is coming from, is
coming from the gimplifier, cp_gimpliify_expr, via build_vec_init. Grrr.
Hmm, maybe build_vec_init should call itself directly rather than via
build_aggr_init in the case of multidimensional arrays.
Yes, arranging things like that seems doable. However, yesterday, while
fiddling with the idea and instrumenting the code with some gcc_asserts, I
noticed that we have yet another tree code to handle, TARGET_EXPR, as in
lines #41, #47, #56 of ext/complit12.C, and in that case build_aggr_init is
simply called by check_initializer via build_aggr_init_full_exprs, the
"normal" path. Well, unless we want to adjust/reject complit12.C too, which
clang rejects, in fact with errors on lines #19 and #29 too. The below
passes testing.
I think I'd like to allow TARGET_EXPR here, with a comment about
compound literals, but avoid INDIRECT_REF with that build_vec_init
change.
I see. Having run the full testsuite a number of times with additional gcc_asserts, I'm very confident that something as simple as the below is fine, at least as far as the testsuite + variants of lambda-array.C is concerned. In it I'm also proposing a gcc_assert verifying that the very idea of not using any diagnostic conditional makes sense for the internally generated INDIRECT_REFs: in the existing build_aggr_init if the types were different from_array would be zero and, for INDIRECT_REF as init, the condition true.

Thanks, Paolo.

///////////////////////
Index: cp/init.c
===================================================================
--- cp/init.c   (revision 258846)
+++ cp/init.c   (working copy)
@@ -1688,14 +1688,6 @@ build_aggr_init (tree exp, tree init, int flags, t
        }
       else
        {
-         /* An array may not be initialized use the parenthesized
-            initialization form -- unless the initializer is "()".  */
-         if (init && TREE_CODE (init) == TREE_LIST)
-           {
-             if (complain & tf_error)
-               error ("bad array initializer");
-             return error_mark_node;
-           }
          /* Must arrange to initialize each element of EXP
             from elements of INIT.  */
          if (cv_qualified_p (type))
@@ -1705,14 +1697,17 @@ build_aggr_init (tree exp, tree init, int flags, t
          from_array = (itype && same_type_p (TREE_TYPE (init),
                                              TREE_TYPE (exp)));
 
-         if (init && !from_array
-             && !BRACE_ENCLOSED_INITIALIZER_P (init))
+         if (init && !BRACE_ENCLOSED_INITIALIZER_P (init)
+             && (!from_array
+                 || (TREE_CODE (init) != CONSTRUCTOR
+                     /* Can happen, eg, handling the compound-literals
+                        extension (ext/complit12.C).  */
+                     && TREE_CODE (init) != TARGET_EXPR)))
            {
              if (complain & tf_error)
-               permerror (init_loc, "array must be initialized "
-                          "with a brace-enclosed initializer");
-             else
-               return error_mark_node;
+               error_at (init_loc, "array must be initialized "
+                         "with a brace-enclosed initializer");
+             return error_mark_node;
            }
        }
 
@@ -4371,7 +4366,19 @@ build_vec_init (tree base, tree maxindex, tree ini
            elt_init = cp_build_modify_expr (input_location, to, NOP_EXPR,
                                             from, complain);
          else if (type_build_ctor_call (type))
-           elt_init = build_aggr_init (to, from, 0, complain);
+           {
+             if (TREE_CODE (type) == ARRAY_TYPE
+                 && from && TREE_CODE (from) == INDIRECT_REF)
+               {
+                 gcc_assert (same_type_ignoring_top_level_qualifiers_p
+                             (type, TREE_TYPE (from)));
+                 elt_init = build_vec_init (to, NULL_TREE, from,
+                                            /*explicit_value_init_p=*/false,
+                                            /*from_array=*/1, complain);
+               }
+             else
+               elt_init = build_aggr_init (to, from, 0, complain);
+           }
          else if (from)
            elt_init = cp_build_modify_expr (input_location, to, NOP_EXPR, from,
                                             complain);
Index: testsuite/g++.dg/init/array49.C
===================================================================
--- testsuite/g++.dg/init/array49.C     (nonexistent)
+++ testsuite/g++.dg/init/array49.C     (working copy)
@@ -0,0 +1,6 @@
+// PR c++/84632
+// { dg-additional-options "-w" }
+
+class {
+  &a;  // { dg-error "forbids declaration" }
+} b[2] = b;  // { dg-error "initialized" }
Index: testsuite/g++.dg/torture/pr70499.C
===================================================================
--- testsuite/g++.dg/torture/pr70499.C  (revision 258846)
+++ testsuite/g++.dg/torture/pr70499.C  (working copy)
@@ -1,5 +1,5 @@
 // { dg-do compile }
-// { dg-additional-options "-w -fpermissive -Wno-psabi" }
+// { dg-additional-options "-w -Wno-psabi" }
 // { dg-additional-options "-mavx" { target x86_64-*-* i?86-*-* } }
 
 typedef double __m256d __attribute__ ((__vector_size__ (32), __may_alias__));
@@ -30,7 +30,7 @@ struct Foo {
 template<typename Tx>  
 __attribute__((__always_inline__)) inline void inlineFunc(Tx hx[]) {
     Tx x = hx[0], y = hx[1];
-    Tx lam[1] = (x*y);
+    Tx lam[1] = {(x*y)};
 }
 
 void FooBarFunc () {

Reply via email to