public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Martin Sebor <msebor@gmail.com>
To: Jason Merrill <jason@redhat.com>,
	Gcc Patch List <gcc-patches@gcc.gnu.org>
Subject: [PATCH] diagnose specializations of deprecated templates (PR c++/84318)
Date: Mon, 12 Feb 2018 23:33:00 -0000	[thread overview]
Message-ID: <ef1c97f4-ee73-0317-11fd-d0e73735408a@gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 655 bytes --]

While testing my fix for 83871 (handling attributes on explicit
specializations) I noticed another old regression: while GCC 4.4
would diagnose declarations of explicit soecializations of all
primary templates declared deprecated, GCC 4.5 and later only
diagnose declarations of explicit soecializations of class
templates but not those of function or variable templates.

The root cause of this regression is different than 83871 so I
prefer to fix each separately.  The attached patch does that.
Because there is an opportunity to share code between the two
fixes I expect to integrate one into the other (whichever is
approved/committed last).

Martin

[-- Attachment #2: gcc-84318.diff --]
[-- Type: text/x-patch, Size: 3249 bytes --]

PR c++/84318 - attribute deprecated on function templates different than class templates

gcc/cp/ChangeLog:

	PR c++/84318
	* pt.c (check_explicit_specialization): Warn for explicit
	specializations of deprecated primary templates.

gcc/testsuite/ChangeLog:

	PR c++/84318
	* g++.dg/ext/attr-deprecated-2.C: New test.

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index b58c60f..aa5f0dd 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -3104,6 +3104,20 @@ check_explicit_specialization (tree declarator,
 	  else if (VAR_P (decl))
 	    DECL_COMDAT (decl) = false;
 
+	  if (TREE_CODE (gen_tmpl) != TYPE_DECL)
+	    {
+	      tree tmpl = gen_tmpl;
+	      if (DECL_FUNCTION_TEMPLATE_P (tmpl)
+		  || TREE_CODE (tmpl) == TEMPLATE_DECL)
+		tmpl = DECL_TEMPLATE_RESULT (tmpl);
+
+	      /* Diagnose declarations of specializations of
+		 a deprecated primary template.  */
+	      if (TREE_DEPRECATED (tmpl)
+		  || lookup_attribute ("deprecated", DECL_ATTRIBUTES (tmpl)))
+		warn_deprecated_use (tmpl, NULL_TREE);
+	    }
+
 	  /* If this is a full specialization, register it so that we can find
 	     it again.  Partial specializations will be registered in
 	     process_partial_specialization.  */
diff --git a/gcc/testsuite/g++.dg/ext/attr-deprecated-2.C b/gcc/testsuite/g++.dg/ext/attr-deprecated-2.C
new file mode 100644
index 0000000..f639a73
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/attr-deprecated-2.C
@@ -0,0 +1,63 @@
+// PR c++/84318 - attribute deprecated on function templates different
+// than class templates
+// { dg-do compile }
+// { dg-options "-Wall" }
+
+#define DEPRECATED __attribute__ ((deprecated))
+
+template <typename T>
+struct DEPRECATED
+ClassPartial { };                       // { dg-message "declared here" }
+
+// Verify that a partial specialization is diagnosed.
+template <typename T>
+struct ClassPartial<const T> { };       // { dg-warning ".template *<class T> struct ClassPartial. is deprecated" }
+
+
+template <typename T>
+struct
+ClassPartialDeprecated { };
+
+template <typename T>
+struct DEPRECATED
+ClassPartialDeprecated<T*> { };
+
+ClassPartialDeprecated<int> cpdi;
+ClassPartialDeprecated<int*> cpdci;     // { dg-warning "is deprecated" "bug 84347" { xfail *-*-* } }
+
+
+template <typename T>
+struct DEPRECATED
+ClassExplicit { };                      // { dg-message "declared here" }
+
+template <>
+struct
+ClassExplicit<int> { };                 // { dg-warning ".template *<class T> struct ClassExplicit. is deprecated" }
+
+
+template <typename T>
+void DEPRECATED
+FuncExplicit ();                        // { dg-message "declared here" }
+
+template <>
+void
+FuncExplicit<int>();                    // { dg-warning ".void FuncExplicit\\\(\\\). is deprecated" }
+
+
+template <typename T>
+int DEPRECATED
+VarPartial;                             // { dg-message "declared here" }
+
+template <class T>
+int
+VarPartial<const T>;                    // { dg-warning ".VarPartial<T>. is deprecated" }
+
+template <typename T>
+int DEPRECATED
+VarExplicit;                            // { dg-message "declared here" }
+
+template <>
+int
+VarExplicit<int>;                       // { dg-warning ".VarExplicit<T>. is deprecated" }
+
+// { dg-prune-output "variable templates only available" }

             reply	other threads:[~2018-02-12 23:33 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-12 23:33 Martin Sebor [this message]
2018-02-13 14:41 ` Jason Merrill
2018-02-13 15:35   ` Martin Sebor
2018-02-13 16:24     ` Martin Sebor
2018-02-13 18:31       ` Martin Sebor
2018-02-13 19:16         ` Jason Merrill
2018-02-13 19:59           ` Martin Sebor
2018-02-13 20:09             ` Jason Merrill
2018-02-13 22:20               ` Martin Sebor
2018-02-14  5:29                 ` Jason Merrill
2018-02-14 15:18                   ` Martin Sebor
2018-02-14 15:33                     ` Jason Merrill

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ef1c97f4-ee73-0317-11fd-d0e73735408a@gmail.com \
    --to=msebor@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jason@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).