This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/55203] No unused warning for variables of non-trivial types


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55203

--- Comment #13 from Marc Glisse <glisse at gcc dot gnu.org> ---
(In reply to Jonathan Wakely from comment #6)
> Which are the relevant classes?  It seems to me that we want to tag almost
> everything except a few RAII types such as std::lock_guard and
> std::unique_lock, which would be quite tedious.  It's certainly applicable
> on all containers, and most streams except fstreams (which have constructors
> with side-effects.)

__attribute__((unused)) on types seems to exist precisely for the reverse
situation where gcc would warn by default, and we would mark the odd class that
is meant to be used this way:
"When attached to a type (including a union or a struct), this attribute means
that variables of that type are meant to appear possibly unused. GCC does not
produce a warning for any variables of that type, even if the variable appears
to do nothing. This is often the case with lock or thread classes, which are
usually defined and then not referenced, but contain constructors and
destructors that have nontrivial bookkeeping functions."

I would be in favor of:
- mark the few relevant types in libstdc++ with this attribute,
- change the warning to apply to all non-marked types, with an extra note
(possibly restricted to the case of non-trivial types) pointing out this
attribute.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]