re PR c++/85227 (ICE with structured binding of a forward declared variable)
authorPaolo Carlini <paolo.carlini@oracle.com>
Mon, 9 Apr 2018 22:33:35 +0000 (22:33 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Mon, 9 Apr 2018 22:33:35 +0000 (22:33 +0000)
/cp
2018-04-09  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/85227
* decl.c (cp_finish_decomp): In a template, if the type is incomplete
issue a pedwarn and defer trying to do bindings.

/testsuite
2018-04-09  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/85227
* g++.dg/cpp1z/decomp44.C: New.
* g++.dg/cpp1z/decomp45.C: Likewise.

From-SVN: r259259

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

index c8eae2e..33f0c37 100644 (file)
@@ -1,3 +1,9 @@
+2018-04-09  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/85227
+       * decl.c (cp_finish_decomp): In a template, if the type is incomplete
+       issue a pedwarn and defer trying to do bindings.
+
 2018-04-09  Jason Merrill  <jason@redhat.com>
 
        PR c++/85279 - dump_expr doesn't understand decltype.
index d55c2b7..44a152b 100644 (file)
@@ -7756,6 +7756,9 @@ cp_finish_decomp (tree decl, tree first, unsigned int count)
       error_at (loc, "cannot decompose lambda closure type %qT", type);
       goto error_out;
     }
+  else if (processing_template_decl && !COMPLETE_TYPE_P (type))
+    pedwarn (loc, 0, "structured binding refers to incomplete class type %qT",
+            type);
   else
     {
       tree btype = find_decomp_class_base (loc, type, NULL_TREE);
index 9bfd591..260150c 100644 (file)
@@ -1,3 +1,9 @@
+2018-04-09  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/85227
+       * g++.dg/cpp1z/decomp44.C: New.
+       * g++.dg/cpp1z/decomp45.C: Likewise.
+
 2018-04-09  Thomas Koenig  <tkoenig@gcc.gnu.org>
 
        PR fortran/83064
diff --git a/gcc/testsuite/g++.dg/cpp1z/decomp44.C b/gcc/testsuite/g++.dg/cpp1z/decomp44.C
new file mode 100644 (file)
index 0000000..168a13e
--- /dev/null
@@ -0,0 +1,10 @@
+// PR c++/85227
+// { dg-do compile { target c++11 } }
+// { dg-options "" }
+
+extern struct A a;
+
+template<int> void foo()
+{
+  auto[i] = a;  // { dg-warning "incomplete" }
+}  // { dg-warning "structured bindings only available with -std=c..17 or -std=gnu..17" "" { target c++14_down } .-1 }
diff --git a/gcc/testsuite/g++.dg/cpp1z/decomp45.C b/gcc/testsuite/g++.dg/cpp1z/decomp45.C
new file mode 100644 (file)
index 0000000..27874fb
--- /dev/null
@@ -0,0 +1,18 @@
+// PR c++/85227
+// { dg-do compile { target c++11 } }
+// { dg-options "" }
+
+extern struct A a;
+
+template<int>
+void f()
+{
+  auto [x] = a;  // { dg-warning "incomplete" }
+}  // { dg-warning "structured bindings only available with -std=c..17 or -std=gnu..17" "" { target c++14_down } .-1 }
+
+struct A { int i; };
+
+int main()
+{
+  f<0>();
+}