]> gcc.gnu.org Git - gcc.git/commitdiff
c++: Fix deprecated attribute handling on templates (PR c++/93228)
authorJakub Jelinek <jakub@redhat.com>
Wed, 22 Jan 2020 16:52:11 +0000 (17:52 +0100)
committerJakub Jelinek <jakub@redhat.com>
Wed, 22 Jan 2020 19:12:56 +0000 (20:12 +0100)
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.

gcc/cp/ChangeLog
gcc/cp/parser.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp1y/attr-deprecated-3.C [new file with mode: 0644]

index 13601ce975e7f5886d747392652f825ed2440c21..da55c7ae07bfd224ed1aa2b35d000b067edb52f9 100644 (file)
@@ -1,3 +1,12 @@
+2020-01-22  Jakub Jelinek  <jakub@redhat.com>
+
+       Backported from mainline
+       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-22  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
index 54b3522dc8ee6a612f444c73649e4c63ad8de146..3e9950bcbed495ca4b4c9d99eb01b9fb26d5120d 100644 (file)
@@ -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
     {
index c313090d06456d1ba0d0dcf6b2139285ae6c5b33..d49da0ada2760849f6bf493e6d8c46a22a076609 100644 (file)
@@ -1,3 +1,11 @@
+2020-01-22  Jakub Jelinek  <jakub@redhat.com>
+
+       Backported from mainline
+       2020-01-17  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/93228
+       * g++.dg/cpp1y/attr-deprecated-3.C: New test.
+
 2020-01-22  Jakub Jelinek  <jakub@redhat.com>
 
        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 (file)
index 0000000..16e5018
--- /dev/null
@@ -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" }
+}
This page took 0.146654 seconds and 5 git commands to generate.