Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look
OK for trunk?
-- >8 --
The deprecated and unavailable attributes weren't working when used on
a template redeclaration ultimately because the corresponding tree flags
on the underlying decls weren't being merged across redeclarations.
PR c++/84542
gcc/cp/ChangeLog:
* decl.cc (merge_attribute_bits):
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 | 5 ++++-
gcc/testsuite/g++.dg/ext/attr-deprecated-2.C | 4 ++--
gcc/testsuite/g++.dg/ext/attr-unavailable-12.C | 12 ++++++++++++
3 files changed, 18 insertions(+), 3 deletions(-)
create mode 100644 gcc/testsuite/g++.dg/ext/attr-unavailable-12.C
diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
index 1ffe4c82748..36375ea3c14 100644
--- a/gcc/cp/decl.cc
+++ b/gcc/cp/decl.cc
@@ -1530,6 +1530,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) \
@@ -1542,7 +1546,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
diff --git a/gcc/testsuite/g++.dg/ext/attr-deprecated-2.C
b/gcc/testsuite/g++.dg/ext/attr-deprecated-2.C
index bf9041506d1..6f6c210ddb5 100644
--- a/gcc/testsuite/g++.dg/ext/attr-deprecated-2.C
+++ b/gcc/testsuite/g++.dg/ext/attr-deprecated-2.C
@@ -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
index 00000000000..7174abc8bb9
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/attr-unavailable-12.C
@@ -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" }
+}
--
2.43.0.76.g1a87c842ec