hanchenye-llvm-project/libcxx/include
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
..
experimental Re-apply "[libcxx] implement <simd> ABI for Clang/GCC vector extension, constructors, copy_from and copy_to." 2018-07-30 22:27:38 +00:00
ext
support [libc++] Exclude posix_l/strtonum fallback inclusion for newlib > 2.4 2018-07-27 20:02:58 +00:00
CMakeLists.txt Recommit r339943 - Establish the <bit> header. NFC yet. Reviewed as https://reviews.llvm.org/D50815 - with a fix for the sanitizer bots 2018-08-17 16:07:48 +00:00
__bit_reference Refactor the newly created <bit> header. Still (almost) NFC. Reviewed as https://reviews.llvm.org/D50876 2018-08-17 17:27:25 +00:00
__bsd_locale_defaults.h
__bsd_locale_fallbacks.h [libc++] Take 2: Replace uses of _LIBCPP_ALWAYS_INLINE by _LIBCPP_INLINE_VISIBILITY 2018-07-11 23:14:33 +00:00
__config [libc++] Add _LIBCPP_ENABLE_NODISCARD and _LIBCPP_NODISCARD_EXT to allow pre-C++2a [[nodiscard]] 2018-09-22 17:54:48 +00:00
__config_site.in [libcxx] By default, do not use internal_linkage to hide symbols from the ABI 2018-08-16 12:44:28 +00:00
__debug
__errc [libc++] Lift std::errc into a separated header 2018-07-03 03:25:10 +00:00
__functional_03 [libcxx] func.wrap.func.con: Unset function before destroying anything 2018-04-25 23:38:41 +00:00
__functional_base [libc++] Remove _LIBCPP_BUILDING_XXX macros, which are redundant since _LIBCPP_BUILDING_LIBRARY 2018-08-01 02:08:59 +00:00
__functional_base_03
__hash_table First half of C++17's splicing maps and sets 2018-08-01 01:33:38 +00:00
__libcpp_version Update version to 8.0.0svn: cmake, includes files and docs 2018-08-01 13:54:28 +00:00
__locale [libc++] Take 2: Replace uses of _LIBCPP_ALWAYS_INLINE by _LIBCPP_INLINE_VISIBILITY 2018-07-11 23:14:33 +00:00
__mutex_base [libc++] Remove _LIBCPP_BUILDING_XXX macros, which are redundant since _LIBCPP_BUILDING_LIBRARY 2018-08-01 02:08:59 +00:00
__node_handle Comment out #define __cpp_lib_node_extract, we only support half of that functionality 2018-08-23 17:08:02 +00:00
__nullptr [libc++] Take 2: Replace uses of _LIBCPP_ALWAYS_INLINE by _LIBCPP_INLINE_VISIBILITY 2018-07-11 23:14:33 +00:00
__split_buffer
__sso_allocator Fix PR22634 - std::allocator doesn't respect over-aligned types. 2018-03-22 04:42:56 +00:00
__std_stream
__string Fix misleading indentation; replace a couple of NULLs with nullptr. Resolves https://reviews.llvm.org/D42945 ; thanks to Bruce Mitchener for the patch. 2018-02-06 18:58:05 +00:00
__threading_support Fix typo 2018-09-17 07:40:42 +00:00
__tree [NFC][libc++] Consistently use spaces to indent 2018-08-03 22:36:53 +00:00
__tuple
__undef_macros
algorithm Implement the infrastructure for feature-test macros. Very few actual feature test macros, though. Reviewed as: https://reviews.llvm.org/D51955 2018-09-12 19:41:40 +00:00
any Implement the infrastructure for feature-test macros. Very few actual feature test macros, though. Reviewed as: https://reviews.llvm.org/D51955 2018-09-12 19:41:40 +00:00
array Implement the infrastructure for feature-test macros. Very few actual feature test macros, though. Reviewed as: https://reviews.llvm.org/D51955 2018-09-12 19:41:40 +00:00
atomic Implement the infrastructure for feature-test macros. Very few actual feature test macros, though. Reviewed as: https://reviews.llvm.org/D51955 2018-09-12 19:41:40 +00:00
bit Implement the infrastructure for feature-test macros. Very few actual feature test macros, though. Reviewed as: https://reviews.llvm.org/D51955 2018-09-12 19:41:40 +00:00
bitset [NFC][libc++] Consistently use spaces to indent 2018-08-03 22:36:53 +00:00
cassert
ccomplex
cctype
cerrno
cfenv
cfloat Test for the presence of a bunch of new macros for c++17. These macros come from C11. Part of P0063 2018-07-31 23:29:06 +00:00
charconv [libc++][C++17] Elementary string conversions for integral types 2018-08-01 02:38:30 +00:00
chrono Implement the infrastructure for feature-test macros. Very few actual feature test macros, though. Reviewed as: https://reviews.llvm.org/D51955 2018-09-12 19:41:40 +00:00
cinttypes
ciso646
climits
clocale
cmath Implement the infrastructure for feature-test macros. Very few actual feature test macros, though. Reviewed as: https://reviews.llvm.org/D51955 2018-09-12 19:41:40 +00:00
codecvt [libc++] Take 2: Replace uses of _LIBCPP_ALWAYS_INLINE by _LIBCPP_INLINE_VISIBILITY 2018-07-11 23:14:33 +00:00
compare [libc++] Declare <compare> operators with the proper visibility attribute 2018-07-10 13:21:03 +00:00
complex Implement the infrastructure for feature-test macros. Very few actual feature test macros, though. Reviewed as: https://reviews.llvm.org/D51955 2018-09-12 19:41:40 +00:00
complex.h
condition_variable
csetjmp
csignal
cstdarg
cstdbool
cstddef Implement the infrastructure for feature-test macros. Very few actual feature test macros, though. Reviewed as: https://reviews.llvm.org/D51955 2018-09-12 19:41:40 +00:00
cstdint
cstdio
cstdlib Selectively import timespec_get into namespace std, since some C libraries don't have it. Reviewed as https://reviews.llvm.org/D50799 2018-08-15 21:19:08 +00:00
cstring
ctgmath
ctime Selectively import timespec_get into namespace std, since some C libraries don't have it. Reviewed as https://reviews.llvm.org/D50799 2018-08-15 21:19:08 +00:00
ctype.h
cwchar
cwctype
deque Implement the infrastructure for feature-test macros. Very few actual feature test macros, though. Reviewed as: https://reviews.llvm.org/D51955 2018-09-12 19:41:40 +00:00
errno.h
exception Implement the infrastructure for feature-test macros. Very few actual feature test macros, though. Reviewed as: https://reviews.llvm.org/D51955 2018-09-12 19:41:40 +00:00
filesystem Implement the infrastructure for feature-test macros. Very few actual feature test macros, though. Reviewed as: https://reviews.llvm.org/D51955 2018-09-12 19:41:40 +00:00
float.h Test for the presence of a bunch of new macros for c++17. These macros come from C11. Part of P0063 2018-07-31 23:29:06 +00:00
forward_list Implement the infrastructure for feature-test macros. Very few actual feature test macros, though. Reviewed as: https://reviews.llvm.org/D51955 2018-09-12 19:41:40 +00:00
fstream Implement <filesystem> 2018-07-27 03:07:09 +00:00
functional Implement the infrastructure for feature-test macros. Very few actual feature test macros, though. Reviewed as: https://reviews.llvm.org/D51955 2018-09-12 19:41:40 +00:00
future [libc++] Remove race condition in std::async 2018-08-24 14:00:59 +00:00
initializer_list [libc++] Take 2: Replace uses of _LIBCPP_ALWAYS_INLINE by _LIBCPP_INLINE_VISIBILITY 2018-07-11 23:14:33 +00:00
inttypes.h
iomanip Implement the infrastructure for feature-test macros. Very few actual feature test macros, though. Reviewed as: https://reviews.llvm.org/D51955 2018-09-12 19:41:40 +00:00
ios [libc++] Take 2: Replace uses of _LIBCPP_ALWAYS_INLINE by _LIBCPP_INLINE_VISIBILITY 2018-07-11 23:14:33 +00:00
iosfwd
iostream
istream [libc++] Factor duplicate code into function templates 2018-07-25 19:40:01 +00:00
iterator Implement the infrastructure for feature-test macros. Very few actual feature test macros, though. Reviewed as: https://reviews.llvm.org/D51955 2018-09-12 19:41:40 +00:00
limits
limits.h
list Implement the infrastructure for feature-test macros. Very few actual feature test macros, though. Reviewed as: https://reviews.llvm.org/D51955 2018-09-12 19:41:40 +00:00
locale [libc++] Take 2: Replace uses of _LIBCPP_ALWAYS_INLINE by _LIBCPP_INLINE_VISIBILITY 2018-07-11 23:14:33 +00:00
locale.h
map Implement the infrastructure for feature-test macros. Very few actual feature test macros, though. Reviewed as: https://reviews.llvm.org/D51955 2018-09-12 19:41:40 +00:00
math.h [libc++] Take 2: Replace uses of _LIBCPP_ALWAYS_INLINE by _LIBCPP_INLINE_VISIBILITY 2018-07-11 23:14:33 +00:00
memory [libc++] Add _LIBCPP_ENABLE_NODISCARD and _LIBCPP_NODISCARD_EXT to allow pre-C++2a [[nodiscard]] 2018-09-22 17:54:48 +00:00
module.modulemap Recommit r339943 - Establish the <bit> header. NFC yet. Reviewed as https://reviews.llvm.org/D50815 - with a fix for the sanitizer bots 2018-08-17 16:07:48 +00:00
mutex Implement the infrastructure for feature-test macros. Very few actual feature test macros, though. Reviewed as: https://reviews.llvm.org/D51955 2018-09-12 19:41:40 +00:00
new Implement the infrastructure for feature-test macros. Very few actual feature test macros, though. Reviewed as: https://reviews.llvm.org/D51955 2018-09-12 19:41:40 +00:00
numeric Implement the infrastructure for feature-test macros. Very few actual feature test macros, though. Reviewed as: https://reviews.llvm.org/D51955 2018-09-12 19:41:40 +00:00
optional Implement the infrastructure for feature-test macros. Very few actual feature test macros, though. Reviewed as: https://reviews.llvm.org/D51955 2018-09-12 19:41:40 +00:00
ostream Revert "Implement LWG 2221 - No formatted output operator for nullptr." 2018-09-19 23:31:34 +00:00
queue Deduction guides for the container adaptors - queue, stack, and priority_queue 2018-05-22 01:57:53 +00:00
random [libc++] Use correct rand.eng.mers all-zeroes seed sequence fallback 2018-08-16 23:56:54 +00:00
ratio
regex Implement the infrastructure for feature-test macros. Very few actual feature test macros, though. Reviewed as: https://reviews.llvm.org/D51955 2018-09-12 19:41:40 +00:00
scoped_allocator Implement the infrastructure for feature-test macros. Very few actual feature test macros, though. Reviewed as: https://reviews.llvm.org/D51955 2018-09-12 19:41:40 +00:00
set Implement the infrastructure for feature-test macros. Very few actual feature test macros, though. Reviewed as: https://reviews.llvm.org/D51955 2018-09-12 19:41:40 +00:00
setjmp.h
shared_mutex Implement the infrastructure for feature-test macros. Very few actual feature test macros, though. Reviewed as: https://reviews.llvm.org/D51955 2018-09-12 19:41:40 +00:00
span [NFC][libc++] Consistently use spaces to indent 2018-08-03 22:36:53 +00:00
sstream [NFC][libc++] Consistently use spaces to indent 2018-08-03 22:36:53 +00:00
stack Deduction guides for the container adaptors - queue, stack, and priority_queue 2018-05-22 01:57:53 +00:00
stdbool.h
stddef.h Teach libc++ to use native NetBSD's max_align_t 2018-08-20 22:29:20 +00:00
stdexcept [NFC][libc++] Consistently use spaces to indent 2018-08-03 22:36:53 +00:00
stdint.h
stdio.h libcxx: Rename vasprintf function to __libcpp_vasprintf. 2018-01-23 18:53:33 +00:00
stdlib.h
streambuf [libc++] Take 2: Replace uses of _LIBCPP_ALWAYS_INLINE by _LIBCPP_INLINE_VISIBILITY 2018-07-11 23:14:33 +00:00
string Implement the infrastructure for feature-test macros. Very few actual feature test macros, though. Reviewed as: https://reviews.llvm.org/D51955 2018-09-12 19:41:40 +00:00
string.h
string_view Implement the infrastructure for feature-test macros. Very few actual feature test macros, though. Reviewed as: https://reviews.llvm.org/D51955 2018-09-12 19:41:40 +00:00
strstream
system_error [libc++] Remove _LIBCPP_BUILDING_XXX macros, which are redundant since _LIBCPP_BUILDING_LIBRARY 2018-08-01 02:08:59 +00:00
tgmath.h Implement LWG 2835 - fix <tgmath.h> 2018-02-12 19:13:24 +00:00
thread Implement LWG 3039 and 3041 - 'Treating Unnecessary decay'. 2018-03-20 22:37:37 +00:00
tuple Implement the infrastructure for feature-test macros. Very few actual feature test macros, though. Reviewed as: https://reviews.llvm.org/D51955 2018-09-12 19:41:40 +00:00
type_traits Implement the infrastructure for feature-test macros. Very few actual feature test macros, though. Reviewed as: https://reviews.llvm.org/D51955 2018-09-12 19:41:40 +00:00
typeindex
typeinfo [NFC][libc++] Consistently use spaces to indent 2018-08-03 22:36:53 +00:00
unordered_map Implement the infrastructure for feature-test macros. Very few actual feature test macros, though. Reviewed as: https://reviews.llvm.org/D51955 2018-09-12 19:41:40 +00:00
unordered_set Implement the infrastructure for feature-test macros. Very few actual feature test macros, though. Reviewed as: https://reviews.llvm.org/D51955 2018-09-12 19:41:40 +00:00
utility Implement the infrastructure for feature-test macros. Very few actual feature test macros, though. Reviewed as: https://reviews.llvm.org/D51955 2018-09-12 19:41:40 +00:00
valarray Fix PR22634 - std::allocator doesn't respect over-aligned types. 2018-03-22 04:42:56 +00:00
variant Don't require relops on variant alternatives to all return the same 2018-09-19 17:53:21 +00:00
vector Implement the infrastructure for feature-test macros. Very few actual feature test macros, though. Reviewed as: https://reviews.llvm.org/D51955 2018-09-12 19:41:40 +00:00
version Implement the infrastructure for feature-test macros. Very few actual feature test macros, though. Reviewed as: https://reviews.llvm.org/D51955 2018-09-12 19:41:40 +00:00
wchar.h
wctype.h