From: Jakub Jelinek Date: Wed, 22 Jan 2020 16:52:11 +0000 (+0100) Subject: c++: Fix deprecated attribute handling on templates (PR c++/93228) X-Git-Tag: releases/gcc-9.3.0~198 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=514314b73109b3672ecb3c3c04f614bb7c7fef57;p=thirdparty%2Fgcc.git 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 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 --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 13601ce975e7..da55c7ae07bf 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,12 @@ +2020-01-22 Jakub Jelinek + + Backported from mainline + 2020-01-17 Jakub Jelinek + + PR c++/93228 + * parser.c (cp_parser_template_name): Look up deprecated attribute + in DECL_TEMPLATE_RESULT or its type's attributes. + 2020-01-22 Jakub Jelinek Backported from mainline diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 54b3522dc8ee..3e9950bcbed4 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -16732,7 +16732,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 c313090d0645..d49da0ada276 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,11 @@ +2020-01-22 Jakub Jelinek + + Backported from mainline + 2020-01-17 Jakub Jelinek + + PR c++/93228 + * g++.dg/cpp1y/attr-deprecated-3.C: New test. + 2020-01-22 Jakub Jelinek Backported from mainline 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 000000000000..16e5018f9cfc --- /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 +struct [[deprecated("foo")]] bar {}; // { dg-message "declared here" } +struct [[deprecated("baz")]] qux {}; // { dg-message "declared here" } + +void +quux () +{ + bar b; // { dg-warning "is deprecated: foo" } + qux c; // { dg-warning "is deprecated: baz" } +}