re PR c++/84632 (internal compiler error: tree check: expected record_type or union_t...
authorPaolo Carlini <paolo.carlini@oracle.com>
Tue, 27 Mar 2018 06:52:04 +0000 (06:52 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Tue, 27 Mar 2018 06:52:04 +0000 (06:52 +0000)
/cp
2018-03-27  Paolo Carlini  <paolo.carlini@oracle.com>
    Jason Merrill  <jason@redhat.com>

PR c++/84632
* init.c (build_aggr_init): When initializing from array,
reject anything but CONSTRUCTORs and TARGET_EXPRs.
(build_vec_init): Handle separately ARRAY_TYPEs.

/testsuite
2018-03-27  Paolo Carlini  <paolo.carlini@oracle.com>
    Jason Merrill  <jason@redhat.com>

PR c++/84632
* g++.dg/init/array49.C: New.
* g++.dg/torture/pr70499.C: Adjust.

Co-Authored-By: Jason Merrill <jason@redhat.com>
From-SVN: r258870

gcc/cp/ChangeLog
gcc/cp/init.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/init/array49.C [new file with mode: 0644]
gcc/testsuite/g++.dg/torture/pr70499.C

index 34d5101963d343c2ae771acbc8aae8f37dbd4e82..654e608c6b5e864ab9df854eb4c824e32dc74d18 100644 (file)
@@ -1,3 +1,11 @@
+2018-03-27  Paolo Carlini  <paolo.carlini@oracle.com>
+           Jason Merrill  <jason@redhat.com>
+
+       PR c++/84632
+       * init.c (build_aggr_init): When initializing from array,
+       reject anything but CONSTRUCTORs and TARGET_EXPRs.
+       (build_vec_init): Handle separately ARRAY_TYPEs.
+
 2018-03-26  Jason Merrill  <jason@redhat.com>
 
        PR c++/85062 - ICE with alignas in wrong place.
index ff52c42c1ad85f7446cd77be876d64c0aeb86c17..e52cd64acc8954937797bc0fa9ec102284187ae9 100644 (file)
@@ -1688,14 +1688,6 @@ build_aggr_init (tree exp, tree init, int flags, tsubst_flags_t complain)
        }
       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, tsubst_flags_t complain)
          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;
            }
        }
 
@@ -4367,7 +4362,10 @@ build_vec_init (tree base, tree maxindex, tree init,
          else
            from = NULL_TREE;
 
-         if (from_array == 2)
+         if (TREE_CODE (type) == ARRAY_TYPE)
+           elt_init = build_vec_init (to, NULL_TREE, from, /*val_init*/false,
+                                      from_array, complain);
+         else if (from_array == 2)
            elt_init = cp_build_modify_expr (input_location, to, NOP_EXPR,
                                             from, complain);
          else if (type_build_ctor_call (type))
index 857870af8706ab8a268f14cceef9685ea0018c93..87d9bd4b204bcd15291ee58c8c6c2349ead0c204 100644 (file)
@@ -1,3 +1,10 @@
+2018-03-27  Paolo Carlini  <paolo.carlini@oracle.com>
+           Jason Merrill  <jason@redhat.com>
+
+       PR c++/84632
+       * g++.dg/init/array49.C: New.
+       * g++.dg/torture/pr70499.C: Adjust.
+
 2018-03-26  Uros Bizjak  <ubizjak@gmail.com>
 
        PR target/85073
diff --git a/gcc/testsuite/g++.dg/init/array49.C b/gcc/testsuite/g++.dg/init/array49.C
new file mode 100644 (file)
index 0000000..9905483
--- /dev/null
@@ -0,0 +1,6 @@
+// PR c++/84632
+// { dg-additional-options "-w" }
+
+class {
+  &a;  // { dg-error "forbids declaration" }
+} b[2] = b;  // { dg-error "initialized" }
index e08c26f56744558e033f5e0f56dc6457b42482d0..4b8b3329d6cc1c175bebe126124a38bfb4c1dfb7 100644 (file)
@@ -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 () {