[Bug c++/104682] Missing deprecated warning on enumerator in class template

2022-02-28 Thread mpolacek at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104682

Marek Polacek  changed:

   What|Removed |Added

 Resolution|--- |FIXED
 Status|ASSIGNED|RESOLVED

--- Comment #4 from Marek Polacek  ---
Fixed in GCC 12.

[Bug c++/104682] Missing deprecated warning on enumerator in class template

2022-02-28 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104682

--- Comment #3 from CVS Commits  ---
The trunk branch has been updated by Marek Polacek :

https://gcc.gnu.org/g:430c89274d7f82810724126637ffdc5507d442f0

commit r12-7413-g430c89274d7f82810724126637ffdc5507d442f0
Author: Marek Polacek 
Date:   Fri Feb 25 14:56:13 2022 -0500

c++: Lost deprecated/unavailable attr in class tmpl [PR104682]

When looking into the other PR I noticed that we fail to give a warning
for a deprecated enumerator when the enum is in a class template.  This
only happens when the attribute doesn't have an argument.  The reason is
that when we tsubst_enum, we create a new enumerator:

  build_enumerator (DECL_NAME (decl), value, newtag,
   DECL_ATTRIBUTES (decl), DECL_SOURCE_LOCATION (decl));

but DECL_ATTRIBUTES (decl) is null when the attribute was provided
without an argument -- in that case it simply melts into a tree flag.
handle_deprecated_attribute has:

  if (!args)
 *no_add_attrs = true;

so the attribute isn't retained and we lose it when tsubsting.  Same
thing when the attribute is on the enum itself.

Attribute unavailable is a similar case, but it's different in that
it can be a late attribute whereas "deprecated" can't:
is_late_template_attribute has

/* But some attributes specifically apply to templates.  */
&& !is_attribute_p ("abi_tag", name)
&& !is_attribute_p ("deprecated", name)
&& !is_attribute_p ("visibility", name))
 return true;
   else
 return false;

which looks strange, but attr-unavailable-9.C tests that we don't error
when
the attribute is applied on a template.

PR c++/104682

gcc/cp/ChangeLog:

* cp-tree.h (build_enumerator): Adjust.
* decl.cc (finish_enum): Make it return the new decl.
* pt.cc (tsubst_enum): Propagate TREE_DEPRECATED and
TREE_UNAVAILABLE.

gcc/testsuite/ChangeLog:

* g++.dg/ext/attr-unavailable-10.C: New test.
* g++.dg/ext/attr-unavailable-11.C: New test.
* g++.dg/warn/deprecated-17.C: New test.
* g++.dg/warn/deprecated-18.C: New test.

[Bug c++/104682] Missing deprecated warning on enumerator in class template

2022-02-28 Thread mpolacek at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104682

Marek Polacek  changed:

   What|Removed |Added

   Keywords||patch

--- Comment #2 from Marek Polacek  ---
Patch posted:
https://gcc.gnu.org/pipermail/gcc-patches/2022-February/590946.html

[Bug c++/104682] Missing deprecated warning on enumerator in class template

2022-02-24 Thread mpolacek at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104682

Marek Polacek  changed:

   What|Removed |Added

 Status|NEW |ASSIGNED
   Assignee|unassigned at gcc dot gnu.org  |mpolacek at gcc dot 
gnu.org

[Bug c++/104682] Missing deprecated warning on enumerator in class template

2022-02-24 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104682

Andrew Pinski  changed:

   What|Removed |Added

   Last reconfirmed||2022-02-24
 Status|UNCONFIRMED |NEW
 Ever confirmed|0   |1

--- Comment #1 from Andrew Pinski  ---
Confirmed, it is not just the value but all enum types too:
template
struct S {
  enum B {
A
  } __attribute__((deprecated)) ;
};

struct S2 {
  enum B {
A
  } __attribute__((deprecated));
};

void
g ()
{
  S::B a; // { dg-warning "is deprecated" }
  S2::B a1; // { dg-warning "is deprecated" }
}