Hi,

here, for an incomplete type we ICE pretty soon in find_decomp_class_base. Comparing to other cases too, I convinced myself that trying to complete the type is Ok. Also, it seems that in these functions we want to talk about structured binding and use an appropriate location, thus no complete_type_or_maybe_complain. Tested x86_64-linux.


Thanks, Paolo.

/////////////////////

/cp
2018-04-06  Paolo Carlini  <paolo.carl...@oracle.com>

        PR c++/85227
        * decl.c (find_decomp_class_base): Try to complete the type
        and give an error if that fails.

/testsuite
2018-04-06  Paolo Carlini  <paolo.carl...@oracle.com>

        PR c++/85227
        * g++.dg/cpp1z/decomp42.C: New.
Index: cp/decl.c
===================================================================
--- cp/decl.c   (revision 259156)
+++ cp/decl.c   (working copy)
@@ -7310,6 +7310,13 @@ cp_finish_decl (tree decl, tree init, bool init_co
 static tree
 find_decomp_class_base (location_t loc, tree type, tree ret)
 {
+  if (!COMPLETE_TYPE_P (complete_type (type)))
+    {
+      error_at (loc, "structured binding refers to incomplete class type %qT",
+               type);
+      return error_mark_node;
+    }
+
   bool member_seen = false;
   for (tree field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
     if (TREE_CODE (field) != FIELD_DECL
Index: testsuite/g++.dg/cpp1z/decomp42.C
===================================================================
--- testsuite/g++.dg/cpp1z/decomp42.C   (nonexistent)
+++ testsuite/g++.dg/cpp1z/decomp42.C   (working copy)
@@ -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-error "incomplete" }
+}  // { dg-warning "structured bindings only available with -std=c..17 or 
-std=gnu..17" "" { target c++14_down } .-1 }

Reply via email to