re PR c++/79372 (ICE on C++ code with illegal decomposition declaration on x86_64...
authorJakub Jelinek <jakub@redhat.com>
Mon, 6 Feb 2017 20:03:15 +0000 (21:03 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Mon, 6 Feb 2017 20:03:15 +0000 (21:03 +0100)
PR c++/79372
* decl.c (cp_finish_decomp): On error set decl type to error_mark_node.
* pt.c (tsubst_expr): Don't call tsubst_decomp_names on decompositions
with error_mark_node type.

* g++.dg/cpp1z/decomp25.C: New test.

From-SVN: r245218

gcc/cp/ChangeLog
gcc/cp/decl.c
gcc/cp/pt.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp1z/decomp25.C [new file with mode: 0644]

index d032028d17cd632df8688be64b2ac241a360ba8d..9889c171b017451013d0929d411f583315d78262 100644 (file)
@@ -1,3 +1,10 @@
+2017-02-06  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/79372
+       * decl.c (cp_finish_decomp): On error set decl type to error_mark_node.
+       * pt.c (tsubst_expr): Don't call tsubst_decomp_names on decompositions
+       with error_mark_node type.
+
 2017-02-03  Jason Merrill  <jason@redhat.com>
 
        PR c++/78689 - ICE on constructor with label
index 9bdfd4ff64ba8ad9a5a3827071e5b76d49d50dea..d1d485a4fed5585273bd37080a37435fa2adb2eb 100644 (file)
@@ -7378,6 +7378,7 @@ cp_finish_decomp (tree decl, tree first, unsigned int count)
            }
          first = DECL_CHAIN (first);
        }
+      TREE_TYPE (decl) = error_mark_node;
       if (DECL_P (decl) && DECL_NAMESPACE_SCOPE_P (decl))
        SET_DECL_ASSEMBLER_NAME (decl, get_identifier ("<decomp>"));
       return;
index 4c4941a88aa43103cca91d11ddf5c20d76fa67ec..6072432382d51afa304f7a791e57e5cd2098f761 100644 (file)
@@ -15765,7 +15765,9 @@ tsubst_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl,
                      const_init = (DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P
                                    (pattern_decl));
                    cp_finish_decl (decl, init, const_init, NULL_TREE, 0);
-                   if (VAR_P (decl) && DECL_DECOMPOSITION_P (decl))
+                   if (VAR_P (decl)
+                       && DECL_DECOMPOSITION_P (decl)
+                       && TREE_TYPE (pattern_decl) != error_mark_node)
                      {
                        unsigned int cnt;
                        tree first;
index 8e9b5fae17c7584662b9090bc29f81358b01ac8e..954851b961dc34e1b776a920d3b5781fc6423f9d 100644 (file)
@@ -1,5 +1,8 @@
 2017-02-06  Jakub Jelinek  <jakub@redhat.com>
 
+       PR c++/79372
+       * g++.dg/cpp1z/decomp25.C: New test.
+
        PR tree-optimization/79284
        * gcc.c-torture/compile/pr79284.c: New test.
 
diff --git a/gcc/testsuite/g++.dg/cpp1z/decomp25.C b/gcc/testsuite/g++.dg/cpp1z/decomp25.C
new file mode 100644 (file)
index 0000000..c992736
--- /dev/null
@@ -0,0 +1,20 @@
+// PR c++/79372
+// { dg-do compile { target c++11 } }
+// { dg-options "" }
+
+template <typename T>
+struct S
+{
+  enum E { A };
+  void f () { auto [x] = 0; x++; }     // { dg-error "cannot decompose non-array non-class type" }
+                                       // { dg-warning "decomposition declaration only available with" "" { target c++14_down } .-1 }
+  void g (T t) { auto [y] = t; y++; }  // { dg-error "cannot decompose non-array non-class type" }
+};                                     // { dg-warning "decomposition declaration only available with" "" { target c++14_down } .-1 }
+
+int
+main ()
+{
+  S <int> s;
+  s.f ();
+  s.g (5);
+}