c++: Attribute deprecated/unavailable divergence
authorMarek Polacek <polacek@redhat.com>
Wed, 2 Mar 2022 15:48:26 +0000 (10:48 -0500)
committerMarek Polacek <polacek@redhat.com>
Tue, 8 Mar 2022 21:15:55 +0000 (16:15 -0500)
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>.

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
gcc/cp/pt.cc
gcc/testsuite/g++.dg/ext/attr-unavailable-9.C

index e85bb87..c53acf4 100644 (file)
@@ -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
index 8b5faee..c350ebb 100644 (file)
@@ -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
index 4416133..6df55d5 100644 (file)
@@ -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));