[Bug c++/104760] New: Attribute [[deprecated]] causes diagnostic in never-instantiated template
ldionne.2 at gmail dot com
gcc-bugzilla@gcc.gnu.org
Wed Mar 2 14:27:42 GMT 2022
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104760
Bug ID: 104760
Summary: Attribute [[deprecated]] causes diagnostic in
never-instantiated template
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: ldionne.2 at gmail dot com
Target Milestone: ---
When using the [[deprecated]] attribute on a class template, a diagnostic is
produced even if that class template is never actually instantiated. For
example, if that class template is only mentioned from another function
template (which is never actually instantiated), we get a diagnostic:
template <class Pred>
struct [[deprecated]] unary_negate {
explicit unary_negate(const Pred&);
};
template <class Pred>
[[deprecated]]
unary_negate<Pred> not1(const Pred& p) { return unary_negate<Pred>(p); }
We get:
<source>:8:1: warning: 'template<class Pred> struct unary_negate' is
deprecated [-Wdeprecated-declarations]
8 | unary_negate<Pred> not1(const Pred& p) { return
unary_negate<Pred>(p); }
| ^~~~~~~~~~~~
<source>:2:23: note: declared here
2 | struct [[deprecated]] unary_negate {
| ^~~~~~~~~~~~
<source>: In function 'unary_negate<Pred> not1(const Pred&)':
<source>:8:49: warning: 'template<class Pred> struct unary_negate' is
deprecated [-Wdeprecated-declarations]
8 | unary_negate<Pred> not1(const Pred& p) { return
unary_negate<Pred>(p); }
| ^~~~~~~~~~~~
<source>:2:23: note: declared here
2 | struct [[deprecated]] unary_negate {
| ^~~~~~~~~~~~
We are encountering this issue in libc++, where we do mark several things as
[[deprecated]] (per the Standard), and those warnings fire off when the headers
are used not as system headers. Any other non-system header library would have
the same problem.
Note that in comparison, Clang does not issue a warning in this case. It only
issues a warning if we actually instantiate `not1` or `unary_negate`.
Godbolt: https://godbolt.org/z/559EfKn9K
More information about the Gcc-bugs
mailing list