]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: Allow IS_FAKE_BASE_TYPE for union types [PR114954]
authorNathaniel Shead <nathanieloshead@gmail.com>
Mon, 6 May 2024 03:05:52 +0000 (13:05 +1000)
committerNathaniel Shead <nathanieloshead@gmail.com>
Tue, 7 May 2024 01:37:47 +0000 (11:37 +1000)
In some circumstances, unions can also have an __as_base type; we need
to make sure that IS_FAKE_BASE_TYPE correctly recognises this.

PR c++/114954

gcc/cp/ChangeLog:

* cp-tree.h (IS_FAKE_BASE_TYPE): Also apply to unions.

gcc/testsuite/ChangeLog:

* g++.dg/modules/pr114954.C: New test.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
Reviewed-by: Jason Merrill <jason@redhat.com>
gcc/cp/cp-tree.h
gcc/testsuite/g++.dg/modules/pr114954.C [new file with mode: 0644]

index 4fadc9aaf48865130b098977c88fc832cebf1698..db098c32f2d087a9da80ce85ab91ed617ce8d3cd 100644 (file)
@@ -2616,7 +2616,7 @@ struct GTY(()) lang_type {
 
 /* True iff NODE is the CLASSTYPE_AS_BASE version of some type.  */
 #define IS_FAKE_BASE_TYPE(NODE)                                        \
-  (TREE_CODE (NODE) == RECORD_TYPE                             \
+  (RECORD_OR_UNION_TYPE_P (NODE)                               \
    && TYPE_CONTEXT (NODE) && CLASS_TYPE_P (TYPE_CONTEXT (NODE))        \
    && CLASSTYPE_AS_BASE (TYPE_CONTEXT (NODE)) == (NODE))
 
diff --git a/gcc/testsuite/g++.dg/modules/pr114954.C b/gcc/testsuite/g++.dg/modules/pr114954.C
new file mode 100644 (file)
index 0000000..a978714
--- /dev/null
@@ -0,0 +1,14 @@
+// PR c++/114954
+// { dg-additional-options "-fmodules-ts" }
+// { dg-module-cmi main }
+
+export module main;
+
+template <int N>
+union U {
+private:
+  char a[N + 1];
+  int b;
+};
+
+U<4> p;