Message ID | 20160217144927.GR1111@redhat.com |
---|---|
State | New |
Headers | show |
On 02/17/2016 09:49 AM, Jonathan Wakely wrote: > https://gcc.gnu.org/onlinedocs/gcc/C_002b_002b-Attributes.html says > that attribute((warn_unused)) is not useful for std::mutex because it > controls a resource. That's incorrect, std::mutex *is* a resource, but > it doesn't control one. In fact declaring std::mutex as a local > variable and then never using it almost certainly is a mistake, > because it won't be locked unless you use it. > > A better example of a type that controls a resource would be > std::lock_guard, which you would typically construct and then never > refer to again (because everything interesting happens in the > constructor and destructor). > > OK for trunk? OK. Jason
commit 01e62a231d9a446130fec253a2001f1e844e184c Author: Jonathan Wakely <jwakely@redhat.com> Date: Wed Feb 17 14:08:39 2016 +0000 * doc/extend.texi (C++ Attributes): Correct description of warn_unused type attribute. diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi index 78017fe..476d089 100644 --- a/gcc/doc/extend.texi +++ b/gcc/doc/extend.texi @@ -20313,7 +20313,7 @@ types. This attribute is appropriate for types which just represent a value, such as @code{std::string}; it is not appropriate for types which -control a resource, such as @code{std::mutex}. +control a resource, such as @code{std::lock_guard}. This attribute is also accepted in C, but it is unnecessary because C does not have constructors or destructors.