Message ID | 20200110202820.GZ10088@tucnak |
---|---|
State | New |
Headers | show |
Series | [C++] Fix deprecated attribute handling on templates (PR c++/93228) | expand |
Hi! I'd like to ping following patch. Thanks. On Fri, Jan 10, 2020 at 09:28:20PM +0100, Jakub Jelinek wrote: > 2020-01-10 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. > > --- gcc/cp/parser.c.jj 2020-01-10 17:52:48.084062620 +0100 > +++ gcc/cp/parser.c 2020-01-10 19:15:29.019861630 +0100 > @@ -16882,7 +16882,17 @@ cp_parser_template_name (cp_parser* pars > { > 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 > { > --- gcc/testsuite/g++.dg/cpp1y/attr-deprecated-3.C.jj 2020-01-10 19:20:44.165196267 +0100 > +++ gcc/testsuite/g++.dg/cpp1y/attr-deprecated-3.C 2020-01-10 19:20:48.699129148 +0100 > @@ -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" } > +} > Jakub
On 1/10/20 3:28 PM, Jakub Jelinek wrote: > Hi! > > 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. > > Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for > trunk? > > 2020-01-10 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. OK. Jason
--- gcc/cp/parser.c.jj 2020-01-10 17:52:48.084062620 +0100 +++ gcc/cp/parser.c 2020-01-10 19:15:29.019861630 +0100 @@ -16882,7 +16882,17 @@ cp_parser_template_name (cp_parser* pars { 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 { --- gcc/testsuite/g++.dg/cpp1y/attr-deprecated-3.C.jj 2020-01-10 19:20:44.165196267 +0100 +++ gcc/testsuite/g++.dg/cpp1y/attr-deprecated-3.C 2020-01-10 19:20:48.699129148 +0100 @@ -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" } +}