]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: modules and deprecated namespaces
authorJason Merrill <jason@redhat.com>
Mon, 3 Nov 2025 14:51:38 +0000 (17:51 +0300)
committerJason Merrill <jason@redhat.com>
Mon, 3 Nov 2025 14:51:38 +0000 (17:51 +0300)
20_util/rel_ops.cc was failing because the gcm didn't represent
[[deprecated]] on a namespace.  Are there any other attributes we're
missing?

gcc/cp/ChangeLog:

* module.cc (module_state::write_namespaces): Handle
TREE_DEPRECATED.
(module_state::read_namespaces): Likewise.

gcc/testsuite/ChangeLog:

* g++.dg/modules/namespace-15_a.C: New test.
* g++.dg/modules/namespace-15_b.C: New test.

gcc/cp/module.cc
gcc/testsuite/g++.dg/modules/namespace-15_a.C [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/namespace-15_b.C [new file with mode: 0644]

index e0b9efa02b6144b075239de1d0b8ad155cd1c41f..b475b07dcb1cb0da010ac39d342f4a6738825c65 100644 (file)
@@ -17246,13 +17246,16 @@ module_state::write_namespaces (elf_out *to, vec<depset *> spaces,
        flags |= 4;
       if (DECL_MODULE_EXPORT_P (ns))
        flags |= 8;
+      if (TREE_DEPRECATED (ns))
+       flags |= 16;
 
       dump () && dump ("Writing namespace:%u %N%s%s%s%s",
                       b->cluster, ns,
                       flags & 1 ? ", public" : "",
                       flags & 2 ? ", inline" : "",
                       flags & 4 ? ", purview" : "",
-                      flags & 8 ? ", export" : "");
+                      flags & 8 ? ", export" : "",
+                      flags & 16 ? ", deprecated" : "");
       sec.u (b->cluster);
       sec.u (to->name (DECL_NAME (ns)));
       write_namespace (sec, b->deps[0]);
@@ -17328,7 +17331,8 @@ module_state::read_namespaces (unsigned num)
                       flags & 1 ? ", public" : "",
                       flags & 2 ? ", inline" : "",
                       flags & 4 ? ", purview" : "",
-                      flags & 8 ? ", export" : "");
+                      flags & 8 ? ", export" : "",
+                      flags & 16 ? ", deprecated" : "");
       bool visible_p = ((flags & 8)
                        || ((flags & 1)
                            && (flags & 4)
@@ -17349,6 +17353,9 @@ module_state::read_namespaces (unsigned num)
            DECL_MODULE_EXPORT_P (inner) = true;
        }
 
+      if (flags & 16)
+       TREE_DEPRECATED (inner) = true;
+
       if (tags)
        DECL_ATTRIBUTES (inner)
          = tree_cons (get_identifier ("abi_tag"), tags, DECL_ATTRIBUTES (inner));
diff --git a/gcc/testsuite/g++.dg/modules/namespace-15_a.C b/gcc/testsuite/g++.dg/modules/namespace-15_a.C
new file mode 100644 (file)
index 0000000..7c0c0e6
--- /dev/null
@@ -0,0 +1,9 @@
+// Test that namespace deprecation is represented in the gcm.
+
+// { dg-additional-options "-fmodules" }
+
+export module M;
+
+export {
+  namespace [[deprecated]] N { }
+}
diff --git a/gcc/testsuite/g++.dg/modules/namespace-15_b.C b/gcc/testsuite/g++.dg/modules/namespace-15_b.C
new file mode 100644 (file)
index 0000000..5128e82
--- /dev/null
@@ -0,0 +1,5 @@
+// { dg-additional-options -fmodules }
+
+import M;
+
+using namespace N;             // { dg-warning "deprecated" }