]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++ modules: ICE with bitfield in class template
authorPatrick Palka <ppalka@redhat.com>
Fri, 7 Oct 2022 16:01:58 +0000 (12:01 -0400)
committerPatrick Palka <ppalka@redhat.com>
Fri, 7 Oct 2022 16:01:58 +0000 (12:01 -0400)
According to grokbitfield, DECL_BIT_FIELD_REPRESENTATIVE contains the
width of the bitfield until we layout the class type (after which it'll
contain a decl).  Thus for a bitfield in a class template it'll always
be the width, and this patch makes us avoid ICEing from mark_class_def
in this case.

gcc/cp/ChangeLog:

* module.cc (trees_out::mark_class_def): Guard against
DECL_BIT_FIELD_REPRESENTATIVE not being a decl.

gcc/testsuite/ChangeLog:

* g++.dg/modules/bfield-3.H: New test.

gcc/cp/module.cc
gcc/testsuite/g++.dg/modules/bfield-3.H [new file with mode: 0644]

index cb1929bc5d55ebbf3af20ef57a62ae38a5361482..94fbee8522525b97b855a9f6ab6e40b5ace4bf3e 100644 (file)
@@ -11919,7 +11919,11 @@ trees_out::mark_class_def (tree defn)
        mark_class_member (member);
        if (TREE_CODE (member) == FIELD_DECL)
          if (tree repr = DECL_BIT_FIELD_REPRESENTATIVE (member))
-           mark_declaration (repr, false);
+           /* If we're marking a class template definition, then
+              this'll contain the width (as set by grokbitfield)
+              instead of a decl.  */
+           if (DECL_P (repr))
+             mark_declaration (repr, false);
       }
 
   /* Mark the binfo hierarchy.  */
diff --git a/gcc/testsuite/g++.dg/modules/bfield-3.H b/gcc/testsuite/g++.dg/modules/bfield-3.H
new file mode 100644 (file)
index 0000000..4fd4db7
--- /dev/null
@@ -0,0 +1,8 @@
+// { dg-additional-options -fmodule-header }
+// { dg-module-cmi {} }
+
+template<int N>
+struct A {
+  int x : 1;
+  int y : N;
+};