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 c8eae2ef179bc46f6842c17489a83b5e7ebf48cd..33f0c37a3cde89827e4976e2b3e02ae8281752b7 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 d55c2b70c0e3f71ebae237462ffd51c7162e306d..44a152bd1956c0c77fd3c1c893b1a62abeadd3dd 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 9bfd5915ed10cc1411d92086cf88e5a7889aeaea..260150c3da2216322c6a79c3614a3b5dfd7bf306 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>();
+}