Hi!

Two years ago Paolo has added the
  else if (processing_template_decl && !COMPLETE_TYPE_P (type))
    pedwarn (...);
lines into cp_finish_decomp.  For type dependent decl we punt much earlier,
but even for types which aren't type dependent COMPLETE_TYPE_P might be
false as this testcase shows, so this patch tries to complete_type first
(the reason for writing it that way is that it is then followed by another
else if and if complete_type returns error_mark_node, we shouldn't report
anything, as a bug should have been reported already.

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

2020-05-27  Jakub Jelinek  <ja...@redhat.com>

        PR c++/95328
        * decl.c (cp_finish_decomp): Call complete_type before checking
        COMPLETE_TYPE_P.

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

--- gcc/cp/decl.c.jj    2020-05-22 11:07:21.884215758 +0200
+++ gcc/cp/decl.c       2020-05-26 15:21:25.039880747 +0200
@@ -8392,6 +8392,8 @@ cp_finish_decomp (tree decl, tree first,
       error_at (loc, "cannot decompose lambda closure type %qT", type);
       goto error_out;
     }
+  else if (processing_template_decl && complete_type (type) == error_mark_node)
+    goto error_out;
   else if (processing_template_decl && !COMPLETE_TYPE_P (type))
     pedwarn (loc, 0, "structured binding refers to incomplete class type %qT",
             type);
--- gcc/testsuite/g++.dg/cpp1z/decomp53.C.jj    2020-05-26 15:25:01.397644953 
+0200
+++ gcc/testsuite/g++.dg/cpp1z/decomp53.C       2020-05-26 15:24:37.764998398 
+0200
@@ -0,0 +1,22 @@
+// PR c++/95328
+// { dg-do compile { target c++11 } }
+// { dg-options "" }
+
+template <typename T>
+struct S
+{
+  int a, b;
+};
+
+template <typename T>
+void
+foo ()
+{
+  auto [a, b] = S<int>();      // { dg-warning "structured bindings only 
available with" "" { target c++14_down } }
+}
+
+int
+main ()
+{
+  foo<int> ();
+}

        Jakub

Reply via email to