[gcc(refs/vendors/redhat/heads/gcc-10-branch)] c++: Fix deprecated attribute handling on templates (PR c++/93228)
Jakub Jelinek
jakub@gcc.gnu.org
Fri Jan 17 19:23:00 GMT 2020
https://gcc.gnu.org/g:04dc4b25a2a7af4eb6d54c5c2b0f8cb09fb5bcbb
commit 04dc4b25a2a7af4eb6d54c5c2b0f8cb09fb5bcbb
Author: Jakub Jelinek <jakub@redhat.com>
Date: Fri Jan 17 15:22:22 2020 +0100
c++: Fix deprecated attribute handling on templates (PR c++/93228)
As the following testcase shows, when deprecated attribute is on a template,
we'd never print the message if any, because the attribute is not
present on the TEMPLATE_DECL with which warn_deprecated_use is called,
but on its DECL_TEMPLATE_RESULT or its type.
2020-01-17 Jakub Jelinek <jakub@redhat.com>
PR c++/93228
* parser.c (cp_parser_template_name): Look up deprecated attribute
in DECL_TEMPLATE_RESULT or its type's attributes.
* g++.dg/cpp1y/attr-deprecated-3.C: New test.
Diff:
---
gcc/cp/ChangeLog | 6 ++++++
gcc/cp/parser.c | 12 +++++++++++-
gcc/testsuite/ChangeLog | 5 +++++
gcc/testsuite/g++.dg/cpp1y/attr-deprecated-3.C | 13 +++++++++++++
4 files changed, 35 insertions(+), 1 deletion(-)
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index c37e461..d76675e 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+2020-01-17 Jakub Jelinek <jakub@redhat.com>
+
+ PR c++/93228
+ * parser.c (cp_parser_template_name): Look up deprecated attribute
+ in DECL_TEMPLATE_RESULT or its type's attributes.
+
2020-01-16 Jason Merrill <jason@redhat.com>
PR c++/93286 - ICE with __is_constructible and variadic template.
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index c5f9798..728474d 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -16884,7 +16884,17 @@ cp_parser_template_name (cp_parser* parser,
{
if (TREE_DEPRECATED (decl)
&& deprecated_state != DEPRECATED_SUPPRESS)
- warn_deprecated_use (decl, NULL_TREE);
+ {
+ tree d = DECL_TEMPLATE_RESULT (decl);
+ tree attr;
+ if (TREE_CODE (d) == TYPE_DECL)
+ attr = lookup_attribute ("deprecated",
+ TYPE_ATTRIBUTES (TREE_TYPE (d)));
+ else
+ attr = lookup_attribute ("deprecated",
+ DECL_ATTRIBUTES (d));
+ warn_deprecated_use (decl, attr);
+ }
}
else
{
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 435d4d6..29a2aa9 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2020-01-17 Jakub Jelinek <jakub@redhat.com>
+
+ PR c++/93228
+ * g++.dg/cpp1y/attr-deprecated-3.C: New test.
+
2020-01-17 Richard Sandiford <richard.sandiford@arm.com>
* g++.target/aarch64/sve/acle/general-c++/gimplify_1.C: New test.
diff --git a/gcc/testsuite/g++.dg/cpp1y/attr-deprecated-3.C b/gcc/testsuite/g++.dg/cpp1y/attr-deprecated-3.C
new file mode 100644
index 0000000..16e5018
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1y/attr-deprecated-3.C
@@ -0,0 +1,13 @@
+// PR c++/93228
+// { dg-do compile { target c++14 } }
+
+template <typename T>
+struct [[deprecated("foo")]] bar {}; // { dg-message "declared here" }
+struct [[deprecated("baz")]] qux {}; // { dg-message "declared here" }
+
+void
+quux ()
+{
+ bar<int> b; // { dg-warning "is deprecated: foo" }
+ qux c; // { dg-warning "is deprecated: baz" }
+}
More information about the Gcc-cvs
mailing list