]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: [[deprecated]] on template redecl [PR84542]
authorPatrick Palka <ppalka@redhat.com>
Thu, 21 Dec 2023 19:33:56 +0000 (14:33 -0500)
committerPatrick Palka <ppalka@redhat.com>
Thu, 21 Dec 2023 19:33:56 +0000 (14:33 -0500)
The deprecated and unavailable attributes weren't working when used on
a template redeclaration ultimately because we weren't merging the
corresponding tree flags in duplicate_decls.

PR c++/84542

gcc/cp/ChangeLog:

* decl.cc (merge_attribute_bits): Merge TREE_DEPRECATED
and TREE_UNAVAILABLE.

gcc/testsuite/ChangeLog:

* g++.dg/ext/attr-deprecated-2.C: No longer XFAIL.
* g++.dg/ext/attr-unavailable-12.C: New test.

gcc/cp/decl.cc
gcc/testsuite/g++.dg/ext/attr-deprecated-2.C
gcc/testsuite/g++.dg/ext/attr-unavailable-12.C [new file with mode: 0644]

index 409d8f15448a9d77cb5d0843ebdd1fa8d56556f8..e044bfa6701e514a7cbe82246755ee1f060a7275 100644 (file)
@@ -1545,6 +1545,10 @@ merge_attribute_bits (tree newdecl, tree olddecl)
   DECL_PURE_P (olddecl) |= DECL_PURE_P (newdecl);
   DECL_UNINLINABLE (newdecl) |= DECL_UNINLINABLE (olddecl);
   DECL_UNINLINABLE (olddecl) |= DECL_UNINLINABLE (newdecl);
+  TREE_DEPRECATED (newdecl) |= TREE_DEPRECATED (olddecl);
+  TREE_DEPRECATED (olddecl) |= TREE_DEPRECATED (newdecl);
+  TREE_UNAVAILABLE (newdecl) |= TREE_UNAVAILABLE (olddecl);
+  TREE_UNAVAILABLE (olddecl) |= TREE_UNAVAILABLE (newdecl);
 }
 
 #define GNU_INLINE_P(fn) (DECL_DECLARED_INLINE_P (fn)                  \
@@ -1557,7 +1561,6 @@ merge_attribute_bits (tree newdecl, tree olddecl)
 static bool
 duplicate_function_template_decls (tree newdecl, tree olddecl)
 {
-
   tree newres = DECL_TEMPLATE_RESULT (newdecl);
   tree oldres = DECL_TEMPLATE_RESULT (olddecl);
   /* Function template declarations can be differentiated by parameter
index bf9041506d1fe2403356d4d61c11c94e5889441a..6f6c210ddb51ce33d15a6e16e6d116e3e8e1ce26 100644 (file)
@@ -23,8 +23,8 @@ fdeprecated_primary ();
 void use_primary ()
 {
   // Verify that uses of the now deprecacted primary are diagnosed.
-  fdeprecated_primary<void>();          // { dg-warning "deprecated" "bug 84542" { xfail *-*-* } }
-  fdeprecated_primary<int>();           // { dg-warning "deprecated" "bug 84542" { xfail *-*-* } }
+  fdeprecated_primary<void>();          // { dg-warning "deprecated" "bug 84542" }
+  fdeprecated_primary<int>();           // { dg-warning "deprecated" "bug 84542" }
 }
 
 void use_special ()
diff --git a/gcc/testsuite/g++.dg/ext/attr-unavailable-12.C b/gcc/testsuite/g++.dg/ext/attr-unavailable-12.C
new file mode 100644 (file)
index 0000000..7174abc
--- /dev/null
@@ -0,0 +1,12 @@
+// PR c++/84542
+
+template<class T>
+void f(T);
+
+template<class T>
+__attribute__((unavailable))
+void f(T) { }
+
+int main() {
+  f(0); // { dg-error "unavailable" }
+}