public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Marek Polacek <polacek@redhat.com>
To: GCC Patches <gcc-patches@gcc.gnu.org>, Jason Merrill <jason@redhat.com>
Subject: [PATCH] c++: Attribute deprecated/unavailable divergence
Date: Wed,  2 Mar 2022 13:31:06 -0500	[thread overview]
Message-ID: <20220302183106.355982-1-polacek@redhat.com> (raw)

Attributes deprecated and unavailable are largely the same, except
that the former produces a warning whereas the latter produces an error.
So is_late_template_attribute should treat them the same.  Confirmed by
Iain that this divergence is not intentional:
<https://gcc.gnu.org/pipermail/gcc-patches/2022-February/591007.html>.

Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk or defer to GCC 13?

gcc/cp/ChangeLog:

	* decl2.cc (is_late_template_attribute): Do not defer attribute
	unavailable.
	* pt.cc (tsubst_enum): Set TREE_UNAVAILABLE.

gcc/testsuite/ChangeLog:

	* g++.dg/ext/attr-unavailable-9.C: Add dg-error.
---
 gcc/cp/decl2.cc                               | 1 +
 gcc/cp/pt.cc                                  | 4 +---
 gcc/testsuite/g++.dg/ext/attr-unavailable-9.C | 4 ++--
 3 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/gcc/cp/decl2.cc b/gcc/cp/decl2.cc
index 22edc2ba7f9..2752426546c 100644
--- a/gcc/cp/decl2.cc
+++ b/gcc/cp/decl2.cc
@@ -1314,6 +1314,7 @@ is_late_template_attribute (tree attr, tree decl)
 	       /* But some attributes specifically apply to templates.  */
 	       && !is_attribute_p ("abi_tag", name)
 	       && !is_attribute_p ("deprecated", name)
+	       && !is_attribute_p ("unavailable", name)
 	       && !is_attribute_p ("visibility", name))
 	return true;
       else
diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index 8fb17349ee1..853738410be 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -26976,9 +26976,7 @@ tsubst_enum (tree tag, tree newtag, tree args)
   DECL_SOURCE_LOCATION (TYPE_NAME (newtag))
     = DECL_SOURCE_LOCATION (TYPE_NAME (tag));
   TREE_DEPRECATED (newtag) = TREE_DEPRECATED (tag);
-  /* We don't need to propagate TREE_UNAVAILABLE here, because it is, unlike
-     deprecated, applied at instantiation time rather than template
-     definition time.  */
+  TREE_UNAVAILABLE (newtag) = TREE_UNAVAILABLE (tag);
 }
 
 /* DECL is a FUNCTION_DECL that is a template specialization.  Return
diff --git a/gcc/testsuite/g++.dg/ext/attr-unavailable-9.C b/gcc/testsuite/g++.dg/ext/attr-unavailable-9.C
index 44161336e78..6df55d534f8 100644
--- a/gcc/testsuite/g++.dg/ext/attr-unavailable-9.C
+++ b/gcc/testsuite/g++.dg/ext/attr-unavailable-9.C
@@ -3,10 +3,10 @@
 /* { dg-options "" } */
 
 template<typename T> struct __attribute__ ((unavailable)) S {};
-S<int> s;
+S<int> s;			// { dg-error "unavailable" }
 
 template <template <class> class T> struct A { };
-A<S> a;
+A<S> a;				// { dg-error "unavailable" }
 
 template <class T> void f() __attribute__ ((unavailable));
 

base-commit: 8fede2876a751d53a28442dcca32466daa929daa
-- 
2.35.1


             reply	other threads:[~2022-03-02 18:31 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-02 18:31 Marek Polacek [this message]
2022-03-08 19:48 ` 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=20220302183106.355982-1-polacek@redhat.com \
    --to=polacek@redhat.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).