On 04/04/2018 01:04 PM, Jason Merrill wrote:
For bugs 54372 and 60063, we changed attributes used and unused to be
applied immediately in a template even if what they apply to is
dependent, to avoid bogus warnings from
maybe_warn_unused_local_typedefs.  But that's only an issue for
TYPE_DECL, so we can use the normal logic for other things.

In our discussion of attributes I thought we decided that explicit
specializations would not inherit attributes from the primary.
IIUC, this change does the opposite for class templates declared
unused so we end up with an inconsistency with function templates:

  namespace {

  template <class T>
  [[gnu::unused]] void f ();

  template <>
  void f<int> () { }

  template <class T>
  struct [[gnu::unused]] A { };

  template <>
  struct A<int> { };   // warning (expected)

  }

  void g ()
  {
    A<int> a;   // missing warning
  }

I would expect both to be treated consistently (i.e., same
as before your change).  I.e., I would think bug 84221 should
be resolved as invalid.)

Martin

PS This is also inconsistent in Clang and ICC, but differently
than in GCC.  Clang warns for the unused variable but not for
the unused function template specialization.  ICC doesn't warn
at all.

Reply via email to