This is the mail archive of the
mailing list for the libstdc++ project.
Re: warnings about unused shared_ptr/unique_ptr comparisons
- From: Kyrill Tkachov <kyrylo dot tkachov at foss dot arm dot com>
- To: Ulrich Drepper <drepper at redhat dot com>, gcc-patches at gcc dot gnu dot org
- Cc: libstdc++ at gcc dot gnu dot org
- Date: Mon, 14 Jan 2019 16:04:27 +0000
- Subject: Re: warnings about unused shared_ptr/unique_ptr comparisons
- References: <firstname.lastname@example.org>
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
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,
- 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.
Forwarding to the libstdc++ list for these patches.
2019-02-14 Ulrich Drepper <email@example.com>
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.