]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: Fix error recovery ICE [PR112365]
authorJakub Jelinek <jakub@redhat.com>
Thu, 16 Nov 2023 16:42:22 +0000 (17:42 +0100)
committerJakub Jelinek <jakub@redhat.com>
Thu, 16 Nov 2023 16:42:22 +0000 (17:42 +0100)
check_field_decls for DECL_C_BIT_FIELD FIELD_DECLs with error_mark_node
TREE_TYPE continues early and doesn't call check_bitfield_decl which would
either set DECL_BIT_FIELD, or clear DECL_C_BIT_FIELD.  So, the following
testcase ICEs after emitting tons of errors, because
SET_DECL_FIELD_CXX_ZERO_WIDTH_BIT_FIELD asserts DECL_BIT_FIELD.

The patch skips that for FIELD_DECLs with error_mark_node, another
option would be to check DECL_BIT_FIELD in addition to DECL_C_BIT_FIELD.

2023-11-16  Jakub Jelinek  <jakub@redhat.com>

PR c++/112365
* class.cc (layout_class_type): Don't
SET_DECL_FIELD_CXX_ZERO_WIDTH_BIT_FIELD on FIELD_DECLs with
error_mark_node type.

* g++.dg/cpp0x/pr112365.C: New test.

gcc/cp/class.cc
gcc/testsuite/g++.dg/cpp0x/pr112365.C [new file with mode: 0644]

index 9d4d95f85bf750e6aa69f2e1cfb536db302f15cf..4766b7cf832c665bec59752433972435988a2255 100644 (file)
@@ -6962,7 +6962,8 @@ layout_class_type (tree t, tree *virtuals_p)
             check_bitfield_decl eventually sets DECL_SIZE (field)
             to that width.  */
          && (DECL_SIZE (field) == NULL_TREE
-             || integer_zerop (DECL_SIZE (field))))
+             || integer_zerop (DECL_SIZE (field)))
+         && TREE_TYPE (field) != error_mark_node)
        SET_DECL_FIELD_CXX_ZERO_WIDTH_BIT_FIELD (field, 1);
       check_non_pod_aggregate (field);
     }
diff --git a/gcc/testsuite/g++.dg/cpp0x/pr112365.C b/gcc/testsuite/g++.dg/cpp0x/pr112365.C
new file mode 100644 (file)
index 0000000..23409cb
--- /dev/null
@@ -0,0 +1,8 @@
+// PR c++/112365
+// { dg-do compile { target c++11 } }
+// { dg-excess-errors "" }
+
+template <typename> struct A;
+template <typename T> A <T> foo (T;
+template <typename T> struct A { constexpr A : T {} }
+struct { bar ( { foo (this)