This is the mail archive of the
mailing list for the libstdc++ project.
Re: Implement C++20 feature P0600r1: nodiscard in the library
- From: Jonathan Wakely <jwakely at redhat dot com>
- To: Ulrich Drepper <drepper at redhat dot com>
- Cc: libstdc++ at gcc dot gnu dot org, gcc-patches at gcc dot gnu dot org
- Date: Mon, 21 Jan 2019 11:18:27 +0000
- Subject: Re: Implement C++20 feature P0600r1: nodiscard in the library
- References: <firstname.lastname@example.org>
On 20/01/19 17:09 +0100, Ulrich Drepper wrote:
Since a previous patch introduced the _GLIBCXX_NODISCARD macro it is now
simple to implement the rest of P0600. The parts specific to C++20 were
already added, this patch adds the attribute to the other functions.
Even though the feature specifies the nodiscard attribute only for C++20
it makes no sense to restrict its use. Code which provokes the warning
but uses C++17 also has a problem. I do not propose to go beyond C++17
yet. Just as for the shared_ptr comparison patch, let's first see how
things go and then we can extend the attribute to previous revisions.
If a code base is compiled with multiple compilers chances are that no
problem will be flagged. Other library implementations are much more
aggressive with the use of this flag. In the gcc code base on one test
case was flagged and that code sequence obviously should never appear in
real code (allocate and discard the result).
The test suite shows no additional errors and given that only the
functions mentioned in the feature (allocate, empty, new, async) are
changed I think this is a patch which can be applied to the trunk. It
can catch real mistakes.