llvm-project/libcxx/utils
Roman Lebedev c65d39a464 [libc++] Add _LIBCPP_ENABLE_NODISCARD and _LIBCPP_NODISCARD_EXT to allow pre-C++2a [[nodiscard]]
Summary:
The `[[nodiscard]]` attribute is intended to help users find bugs where
function return values are ignored when they shouldn't be. After C++17 the
C++ standard has started to declared such library functions as `[[nodiscard]]`.
However, this application is limited and applies only to dialects after C++17.
Users who want help diagnosing misuses of STL functions may desire a more
liberal application of `[[nodiscard]]`.

For this reason libc++ provides an extension that does just that! The
extension must be enabled by defining `_LIBCPP_ENABLE_NODISCARD`. The extended
applications of `[[nodiscard]]` takes two forms:

1. Backporting `[[nodiscard]]` to entities declared as such by the
   standard in newer dialects, but not in the present one.

2. Extended applications of `[[nodiscard]]`, at the libraries discretion,
   applied to entities never declared as such by the standard.

Users may also opt-out of additional applications `[[nodiscard]]` using
additional macros.

Applications of the first form, which backport `[[nodiscard]]` from a newer
dialect may be disabled using macros specific to the dialect it was added. For
example `_LIBCPP_DISABLE_NODISCARD_AFTER_CXX17`.

Applications of the second form, which are pure extensions, may be disabled
by defining `_LIBCPP_DISABLE_NODISCARD_EXT`.

This patch was originally written by me (Roman Lebedev),
then but then reworked by Eric Fiselier.

Reviewers: mclow.lists, thakis, EricWF

Reviewed By: thakis, EricWF

Subscribers: llvm-commits, mclow.lists, lebedev.ri, EricWF, rjmccall, Quuxplusone, cfe-commits, christof

Differential Revision: https://reviews.llvm.org/D45179

llvm-svn: 342808
2018-09-22 17:54:48 +00:00
..
google-benchmark Remove BUILD file from google-benchmark 2018-07-10 13:25:26 +00:00
libcxx [libc++] Add _LIBCPP_ENABLE_NODISCARD and _LIBCPP_NODISCARD_EXT to allow pre-C++2a [[nodiscard]] 2018-09-22 17:54:48 +00:00
symcheck-blacklists Start libc++ python cleanup and consolidation. 2017-02-09 22:53:14 +00:00
cat_files.py Fix creating __generated_config on Windows 2017-01-03 03:55:29 +00:00
gen_link_script.py Start libc++ python cleanup and consolidation. 2017-02-09 22:53:14 +00:00
merge_archives.py Use CMAKE_AR instead of the system default 'ar' for merging static libraries 2017-09-13 06:55:44 +00:00
not.py Start libc++ python cleanup and consolidation. 2017-02-09 22:53:14 +00:00
sym_diff.py Start libc++ python cleanup and consolidation. 2017-02-09 22:53:14 +00:00
sym_extract.py Start libc++ python cleanup and consolidation. 2017-02-09 22:53:14 +00:00
sym_match.py Start libc++ python cleanup and consolidation. 2017-02-09 22:53:14 +00:00