This is the mail archive of the mailing list for the libstdc++ 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]

Re: warnings about unused shared_ptr/unique_ptr comparisons

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  <>

	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.

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