]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++/modules: Handle reflection SPLICE_SCOPE tree node
authorvspefs <vspefs@protonmail.com>
Mon, 26 Jan 2026 20:56:52 +0000 (20:56 +0000)
committerJason Merrill <jason@redhat.com>
Wed, 28 Jan 2026 02:40:33 +0000 (10:40 +0800)
This patch adds support for serializing and deserializing SPLICE_SCOPE trees
in C++20 modules implementation. SPLICE_SCOPE is introduced by C++26
reflection, notably used for dependent splice types, thus needing to be
exported/imported as part of the module interface. Not handling SPLICE_SCOPE
leads to ICE.

This patch also includes 2 simple test cases: one for exporting splice scope
types and another for importing them.

gcc/cp/

* module.cc (trees_out::type_node): Add case for SPLICE_SCOPE.
(trees_in::tree_node): Add case for SPLICE_SCOPE.

gcc/testsuite/

* g++.dg/modules/splice-scope-tree_a.C: New test.
* g++.dg/modules/splice-scope-tree_b.C: New test.

Reviewed-by: Patrick Palka <ppalka@redhat.com>
Reviewed-by: Jason Merrill <jason@redhat.com>
gcc/cp/module.cc
gcc/testsuite/g++.dg/modules/splice-scope-tree_a.C [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/splice-scope-tree_b.C [new file with mode: 0644]

index e2097027dbd915deca5ac1d11e880dd9e1bdd4d8..2d9b727d2b3df12df5117193e623ae00f1d137be 100644 (file)
@@ -9847,6 +9847,12 @@ trees_out::type_node (tree type)
     case META_TYPE:
       /* No additional data.  */
       break;
+
+    case SPLICE_SCOPE:
+      if (streaming_p ())
+       u (SPLICE_SCOPE_TYPE_P (type));
+      tree_node (SPLICE_SCOPE_EXPR (type));
+      break;
     }
 
   tree_node (TYPE_ATTRIBUTES (type));
@@ -10697,6 +10703,16 @@ trees_in::tree_node (bool is_use)
            if (!get_overrun ())
              res = meta_info_type_node;
            break;
+
+         case SPLICE_SCOPE:
+           {
+             bool type = u ();
+             tree expr = tree_node ();
+
+             if (!get_overrun ())
+               res = make_splice_scope (expr, type);
+           }
+           break;
          }
 
        /* In the exporting TU, a derived type with attributes was built by
diff --git a/gcc/testsuite/g++.dg/modules/splice-scope-tree_a.C b/gcc/testsuite/g++.dg/modules/splice-scope-tree_a.C
new file mode 100644 (file)
index 0000000..3cf638a
--- /dev/null
@@ -0,0 +1,12 @@
+// { dg-do compile { target c++26 } }
+// { dg-additional-options "-fmodules -freflection" }
+
+export module exporting_splice_scope;
+// { dg-module-cmi exporting_splice_scope }
+
+export template <typename T>
+using dependent_splice_type = typename [: ^^T :];
+
+export template <bool Cond, typename T, typename U>
+using somehow_more_complicated_dependent_splice_type =
+    typename [: Cond ? ^^T : ^^U :];
diff --git a/gcc/testsuite/g++.dg/modules/splice-scope-tree_b.C b/gcc/testsuite/g++.dg/modules/splice-scope-tree_b.C
new file mode 100644 (file)
index 0000000..55132f2
--- /dev/null
@@ -0,0 +1,16 @@
+// { dg-do compile { target c++26 } }
+// { dg-additional-options "-fmodules -freflection" }
+
+import exporting_splice_scope;
+
+#include <meta>
+
+int
+main ()
+{
+  static_assert (std::meta::dealias (^^dependent_splice_type<int>) == ^^int);
+  static_assert (std::meta::dealias (
+      ^^somehow_more_complicated_dependent_splice_type<true, int, double>) == ^^int);
+  static_assert (std::meta::dealias (
+      ^^somehow_more_complicated_dependent_splice_type<false, int, double>) == ^^double);
+}