warnings about unused shared_ptr/unique_ptr comparisons

Kyrill Tkachov kyrylo.tkachov@foss.arm.com
Mon Jan 14 16:04:00 GMT 2019


On 14/01/19 15:53, Ulrich Drepper wrote:
> This is a conservative implementation of a patch to make
> shared/unique_ptrs behave more like plain old pointers.  More about this
> in bug #88738
>
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88738
>
> The summary is
>
> - using clang, which enables a warning for unused results of all
> comparison operation, found a real bug
>
> - a library implementation is limited in scope and tedious to add
> everywhere. At this stage of gcc 9 it was the only acceptable solution,
> though
>
> - longer term there should be a warning for comparison operators.
> Possibly on by default with the possibility to disable it with an
> attribute (see the discussion in the bug).
>
>
> The patch proposed here only changes the code for C++17 and up to use
> the [[nodiscard]] attribute.  For gcc 10 we can either widen this or
> implement a better way with the help of the compiler.
>
> I ran the regression test suite and didn't see any additional failures.
>
> OK?

Forwarding to the libstdc++ list for these patches.

Thanks,
Kyrill

> libstdc++-v3/
> 2019-02-14  Ulrich Drepper  <drepper@redhat.com>
>
> 	PR libstdc++/88738
> 	Warn about unused comparisons of shared_ptr/unique_ptr
> 	* include/bits/c++config [_GLIBCXX_NODISCARD]: Define.
> 	* include/bits/shared_ptr.h: Use it for operator ==, !=,
> 	<, <=, >, >= for shared_ptr.
> 	* include/bits/unique_ptr.h: Likewise for unique_ptr.
>



More information about the Libstdc++ mailing list