aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2024-11-23 10:00:18 +0100
committerJason Merrill <jason@redhat.com>2025-01-11 01:26:58 -0500
commitfdabd93cde4aae38d6a67fe0927eca8cea1b22b9 (patch)
treea16be44750554e8cc83d0707c12dea6249e195c2
parentf30423ea8c2152dcee91056e75a4f3736cce6a6e (diff)
downloadgcc-fdabd93cde4aae38d6a67fe0927eca8cea1b22b9.zip
gcc-fdabd93cde4aae38d6a67fe0927eca8cea1b22b9.tar.gz
gcc-fdabd93cde4aae38d6a67fe0927eca8cea1b22b9.tar.bz2
c++: modules and class attributes
std/time/traits/is_clock.cc was getting a warning about applying the deprecated attribute to a variant of auto_ptr, which was wrong because it's on the primary type. This turned out to be because we were ignoring the attributes on the definition of auto_ptr because the forward declaration in unique_ptr.h has no attributes. We need to merge attributes as usual in a redeclaration. gcc/cp/ChangeLog: * module.cc (trees_in::decl_value): Merge attributes. gcc/testsuite/ChangeLog: * g++.dg/modules/attrib-1_a.C: New test. * g++.dg/modules/attrib-1_b.C: New test.
-rw-r--r--gcc/cp/module.cc4
-rw-r--r--gcc/testsuite/g++.dg/modules/attrib-1_a.C13
-rw-r--r--gcc/testsuite/g++.dg/modules/attrib-1_b.C10
3 files changed, 27 insertions, 0 deletions
diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc
index 4fbe522..321d416 100644
--- a/gcc/cp/module.cc
+++ b/gcc/cp/module.cc
@@ -8637,6 +8637,10 @@ trees_in::decl_value ()
TYPE_STUB_DECL (type) = stub_decl ? stub_decl : inner;
if (stub_decl)
TREE_TYPE (stub_decl) = type;
+
+ /* Handle separate declarations with different attributes. */
+ tree &eattr = TYPE_ATTRIBUTES (TREE_TYPE (existing));
+ eattr = merge_attributes (eattr, TYPE_ATTRIBUTES (type));
}
if (inner_tag)
diff --git a/gcc/testsuite/g++.dg/modules/attrib-1_a.C b/gcc/testsuite/g++.dg/modules/attrib-1_a.C
new file mode 100644
index 0000000..d5f89d0
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/attrib-1_a.C
@@ -0,0 +1,13 @@
+// { dg-additional-options "-fmodules -Wno-global-module" }
+// { dg-module-cmi M }
+
+module;
+
+template <class T> struct A {
+ void f() const { }
+} __attribute__ ((deprecated ("y tho")));
+
+export module M;
+
+export template <class T>
+A<T> a; // { dg-warning "deprecated" }
diff --git a/gcc/testsuite/g++.dg/modules/attrib-1_b.C b/gcc/testsuite/g++.dg/modules/attrib-1_b.C
new file mode 100644
index 0000000..48ac751
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/attrib-1_b.C
@@ -0,0 +1,10 @@
+// { dg-additional-options -fmodules }
+
+template <class T> struct A;
+
+import M;
+
+int main()
+{
+ a<int>.f();
+}