xref: /aosp_15_r20/external/libcxx/docs/UsingLibcxx.rst (revision 58b9f456b02922dfdb1fad8a988d5fd8765ecb80)
1*58b9f456SAndroid Build Coastguard Worker============
2*58b9f456SAndroid Build Coastguard WorkerUsing libc++
3*58b9f456SAndroid Build Coastguard Worker============
4*58b9f456SAndroid Build Coastguard Worker
5*58b9f456SAndroid Build Coastguard Worker.. contents::
6*58b9f456SAndroid Build Coastguard Worker  :local:
7*58b9f456SAndroid Build Coastguard Worker
8*58b9f456SAndroid Build Coastguard WorkerGetting Started
9*58b9f456SAndroid Build Coastguard Worker===============
10*58b9f456SAndroid Build Coastguard Worker
11*58b9f456SAndroid Build Coastguard WorkerIf you already have libc++ installed you can use it with clang.
12*58b9f456SAndroid Build Coastguard Worker
13*58b9f456SAndroid Build Coastguard Worker.. code-block:: bash
14*58b9f456SAndroid Build Coastguard Worker
15*58b9f456SAndroid Build Coastguard Worker    $ clang++ -stdlib=libc++ test.cpp
16*58b9f456SAndroid Build Coastguard Worker    $ clang++ -std=c++11 -stdlib=libc++ test.cpp
17*58b9f456SAndroid Build Coastguard Worker
18*58b9f456SAndroid Build Coastguard WorkerOn OS X and FreeBSD libc++ is the default standard library
19*58b9f456SAndroid Build Coastguard Workerand the ``-stdlib=libc++`` is not required.
20*58b9f456SAndroid Build Coastguard Worker
21*58b9f456SAndroid Build Coastguard Worker.. _alternate libcxx:
22*58b9f456SAndroid Build Coastguard Worker
23*58b9f456SAndroid Build Coastguard WorkerIf you want to select an alternate installation of libc++ you
24*58b9f456SAndroid Build Coastguard Workercan use the following options.
25*58b9f456SAndroid Build Coastguard Worker
26*58b9f456SAndroid Build Coastguard Worker.. code-block:: bash
27*58b9f456SAndroid Build Coastguard Worker
28*58b9f456SAndroid Build Coastguard Worker  $ clang++ -std=c++11 -stdlib=libc++ -nostdinc++ \
29*58b9f456SAndroid Build Coastguard Worker            -I<libcxx-install-prefix>/include/c++/v1 \
30*58b9f456SAndroid Build Coastguard Worker            -L<libcxx-install-prefix>/lib \
31*58b9f456SAndroid Build Coastguard Worker            -Wl,-rpath,<libcxx-install-prefix>/lib \
32*58b9f456SAndroid Build Coastguard Worker            test.cpp
33*58b9f456SAndroid Build Coastguard Worker
34*58b9f456SAndroid Build Coastguard WorkerThe option ``-Wl,-rpath,<libcxx-install-prefix>/lib`` adds a runtime library
35*58b9f456SAndroid Build Coastguard Workersearch path. Meaning that the systems dynamic linker will look for libc++ in
36*58b9f456SAndroid Build Coastguard Worker``<libcxx-install-prefix>/lib`` whenever the program is run. Alternatively the
37*58b9f456SAndroid Build Coastguard Workerenvironment variable ``LD_LIBRARY_PATH`` (``DYLD_LIBRARY_PATH`` on OS X) can
38*58b9f456SAndroid Build Coastguard Workerbe used to change the dynamic linkers search paths after a program is compiled.
39*58b9f456SAndroid Build Coastguard Worker
40*58b9f456SAndroid Build Coastguard WorkerAn example of using ``LD_LIBRARY_PATH``:
41*58b9f456SAndroid Build Coastguard Worker
42*58b9f456SAndroid Build Coastguard Worker.. code-block:: bash
43*58b9f456SAndroid Build Coastguard Worker
44*58b9f456SAndroid Build Coastguard Worker  $ clang++ -stdlib=libc++ -nostdinc++ \
45*58b9f456SAndroid Build Coastguard Worker            -I<libcxx-install-prefix>/include/c++/v1
46*58b9f456SAndroid Build Coastguard Worker            -L<libcxx-install-prefix>/lib \
47*58b9f456SAndroid Build Coastguard Worker            test.cpp -o
48*58b9f456SAndroid Build Coastguard Worker  $ ./a.out # Searches for libc++ in the systems library paths.
49*58b9f456SAndroid Build Coastguard Worker  $ export LD_LIBRARY_PATH=<libcxx-install-prefix>/lib
50*58b9f456SAndroid Build Coastguard Worker  $ ./a.out # Searches for libc++ along LD_LIBRARY_PATH
51*58b9f456SAndroid Build Coastguard Worker
52*58b9f456SAndroid Build Coastguard Worker
53*58b9f456SAndroid Build Coastguard WorkerUsing ``<filesystem>`` and libc++fs
54*58b9f456SAndroid Build Coastguard Worker====================================
55*58b9f456SAndroid Build Coastguard Worker
56*58b9f456SAndroid Build Coastguard WorkerLibc++ provides the implementation of the filesystem library in a separate
57*58b9f456SAndroid Build Coastguard Workerlibrary. Users of ``<filesystem>`` and ``<experimental/filesystem>`` are
58*58b9f456SAndroid Build Coastguard Workerrequired to link ``-lc++fs``.
59*58b9f456SAndroid Build Coastguard Worker
60*58b9f456SAndroid Build Coastguard Worker.. note::
61*58b9f456SAndroid Build Coastguard Worker  Prior to libc++ 7.0, users of ``<experimental/filesystem>`` were required
62*58b9f456SAndroid Build Coastguard Worker  to link libc++experimental.
63*58b9f456SAndroid Build Coastguard Worker
64*58b9f456SAndroid Build Coastguard Worker.. warning::
65*58b9f456SAndroid Build Coastguard Worker  The Filesystem library is still experimental in nature. As such normal
66*58b9f456SAndroid Build Coastguard Worker  guarantees about ABI stability and backwards compatibility do not yet apply
67*58b9f456SAndroid Build Coastguard Worker  to it. In the future, this restriction will be removed.
68*58b9f456SAndroid Build Coastguard Worker
69*58b9f456SAndroid Build Coastguard Worker
70*58b9f456SAndroid Build Coastguard WorkerUsing libc++experimental and ``<experimental/...>``
71*58b9f456SAndroid Build Coastguard Worker=====================================================
72*58b9f456SAndroid Build Coastguard Worker
73*58b9f456SAndroid Build Coastguard WorkerLibc++ provides implementations of experimental technical specifications
74*58b9f456SAndroid Build Coastguard Workerin a separate library, ``libc++experimental.a``. Users of ``<experimental/...>``
75*58b9f456SAndroid Build Coastguard Workerheaders may be required to link ``-lc++experimental``.
76*58b9f456SAndroid Build Coastguard Worker
77*58b9f456SAndroid Build Coastguard Worker.. code-block:: bash
78*58b9f456SAndroid Build Coastguard Worker
79*58b9f456SAndroid Build Coastguard Worker  $ clang++ -std=c++14 -stdlib=libc++ test.cpp -lc++experimental
80*58b9f456SAndroid Build Coastguard Worker
81*58b9f456SAndroid Build Coastguard WorkerLibc++experimental.a may not always be available, even when libc++ is already
82*58b9f456SAndroid Build Coastguard Workerinstalled. For information on building libc++experimental from source see
83*58b9f456SAndroid Build Coastguard Worker:ref:`Building Libc++ <build instructions>` and
84*58b9f456SAndroid Build Coastguard Worker:ref:`libc++experimental CMake Options <libc++experimental options>`.
85*58b9f456SAndroid Build Coastguard Worker
86*58b9f456SAndroid Build Coastguard WorkerNote that as of libc++ 7.0 using the ``<experimental/filesystem>`` requires linking
87*58b9f456SAndroid Build Coastguard Workerlibc++fs instead of libc++experimental.
88*58b9f456SAndroid Build Coastguard Worker
89*58b9f456SAndroid Build Coastguard WorkerAlso see the `Experimental Library Implementation Status <http://libcxx.llvm.org/ts1z_status.html>`__
90*58b9f456SAndroid Build Coastguard Workerpage.
91*58b9f456SAndroid Build Coastguard Worker
92*58b9f456SAndroid Build Coastguard Worker.. warning::
93*58b9f456SAndroid Build Coastguard Worker  Experimental libraries are Experimental.
94*58b9f456SAndroid Build Coastguard Worker    * The contents of the ``<experimental/...>`` headers and ``libc++experimental.a``
95*58b9f456SAndroid Build Coastguard Worker      library will not remain compatible between versions.
96*58b9f456SAndroid Build Coastguard Worker    * No guarantees of API or ABI stability are provided.
97*58b9f456SAndroid Build Coastguard Worker
98*58b9f456SAndroid Build Coastguard WorkerUsing libc++ on Linux
99*58b9f456SAndroid Build Coastguard Worker=====================
100*58b9f456SAndroid Build Coastguard Worker
101*58b9f456SAndroid Build Coastguard WorkerOn Linux libc++ can typically be used with only '-stdlib=libc++'. However
102*58b9f456SAndroid Build Coastguard Workersome libc++ installations require the user manually link libc++abi themselves.
103*58b9f456SAndroid Build Coastguard WorkerIf you are running into linker errors when using libc++ try adding '-lc++abi'
104*58b9f456SAndroid Build Coastguard Workerto the link line.  For example:
105*58b9f456SAndroid Build Coastguard Worker
106*58b9f456SAndroid Build Coastguard Worker.. code-block:: bash
107*58b9f456SAndroid Build Coastguard Worker
108*58b9f456SAndroid Build Coastguard Worker  $ clang++ -stdlib=libc++ test.cpp -lc++ -lc++abi -lm -lc -lgcc_s -lgcc
109*58b9f456SAndroid Build Coastguard Worker
110*58b9f456SAndroid Build Coastguard WorkerAlternately, you could just add libc++abi to your libraries list, which in
111*58b9f456SAndroid Build Coastguard Workermost situations will give the same result:
112*58b9f456SAndroid Build Coastguard Worker
113*58b9f456SAndroid Build Coastguard Worker.. code-block:: bash
114*58b9f456SAndroid Build Coastguard Worker
115*58b9f456SAndroid Build Coastguard Worker  $ clang++ -stdlib=libc++ test.cpp -lc++abi
116*58b9f456SAndroid Build Coastguard Worker
117*58b9f456SAndroid Build Coastguard Worker
118*58b9f456SAndroid Build Coastguard WorkerUsing libc++ with GCC
119*58b9f456SAndroid Build Coastguard Worker---------------------
120*58b9f456SAndroid Build Coastguard Worker
121*58b9f456SAndroid Build Coastguard WorkerGCC does not provide a way to switch from libstdc++ to libc++. You must manually
122*58b9f456SAndroid Build Coastguard Workerconfigure the compile and link commands.
123*58b9f456SAndroid Build Coastguard Worker
124*58b9f456SAndroid Build Coastguard WorkerIn particular you must tell GCC to remove the libstdc++ include directories
125*58b9f456SAndroid Build Coastguard Workerusing ``-nostdinc++`` and to not link libstdc++.so using ``-nodefaultlibs``.
126*58b9f456SAndroid Build Coastguard Worker
127*58b9f456SAndroid Build Coastguard WorkerNote that ``-nodefaultlibs`` removes all of the standard system libraries and
128*58b9f456SAndroid Build Coastguard Workernot just libstdc++ so they must be manually linked. For example:
129*58b9f456SAndroid Build Coastguard Worker
130*58b9f456SAndroid Build Coastguard Worker.. code-block:: bash
131*58b9f456SAndroid Build Coastguard Worker
132*58b9f456SAndroid Build Coastguard Worker  $ g++ -nostdinc++ -I<libcxx-install-prefix>/include/c++/v1 \
133*58b9f456SAndroid Build Coastguard Worker         test.cpp -nodefaultlibs -lc++ -lc++abi -lm -lc -lgcc_s -lgcc
134*58b9f456SAndroid Build Coastguard Worker
135*58b9f456SAndroid Build Coastguard Worker
136*58b9f456SAndroid Build Coastguard WorkerGDB Pretty printers for libc++
137*58b9f456SAndroid Build Coastguard Worker------------------------------
138*58b9f456SAndroid Build Coastguard Worker
139*58b9f456SAndroid Build Coastguard WorkerGDB does not support pretty-printing of libc++ symbols by default. Unfortunately
140*58b9f456SAndroid Build Coastguard Workerlibc++ does not provide pretty-printers itself. However there are 3rd
141*58b9f456SAndroid Build Coastguard Workerparty implementations available and although they are not officially
142*58b9f456SAndroid Build Coastguard Workersupported by libc++ they may be useful to users.
143*58b9f456SAndroid Build Coastguard Worker
144*58b9f456SAndroid Build Coastguard WorkerKnown 3rd Party Implementations Include:
145*58b9f456SAndroid Build Coastguard Worker
146*58b9f456SAndroid Build Coastguard Worker* `Koutheir's libc++ pretty-printers <https://github.com/koutheir/libcxx-pretty-printers>`_.
147*58b9f456SAndroid Build Coastguard Worker
148*58b9f456SAndroid Build Coastguard Worker
149*58b9f456SAndroid Build Coastguard WorkerLibc++ Configuration Macros
150*58b9f456SAndroid Build Coastguard Worker===========================
151*58b9f456SAndroid Build Coastguard Worker
152*58b9f456SAndroid Build Coastguard WorkerLibc++ provides a number of configuration macros which can be used to enable
153*58b9f456SAndroid Build Coastguard Workeror disable extended libc++ behavior, including enabling "debug mode" or
154*58b9f456SAndroid Build Coastguard Workerthread safety annotations.
155*58b9f456SAndroid Build Coastguard Worker
156*58b9f456SAndroid Build Coastguard Worker**_LIBCPP_DEBUG**:
157*58b9f456SAndroid Build Coastguard Worker  See :ref:`using-debug-mode` for more information.
158*58b9f456SAndroid Build Coastguard Worker
159*58b9f456SAndroid Build Coastguard Worker**_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS**:
160*58b9f456SAndroid Build Coastguard Worker  This macro is used to enable -Wthread-safety annotations on libc++'s
161*58b9f456SAndroid Build Coastguard Worker  ``std::mutex`` and ``std::lock_guard``. By default these annotations are
162*58b9f456SAndroid Build Coastguard Worker  disabled and must be manually enabled by the user.
163*58b9f456SAndroid Build Coastguard Worker
164*58b9f456SAndroid Build Coastguard Worker**_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS**:
165*58b9f456SAndroid Build Coastguard Worker  This macro is used to disable all visibility annotations inside libc++.
166*58b9f456SAndroid Build Coastguard Worker  Defining this macro and then building libc++ with hidden visibility gives a
167*58b9f456SAndroid Build Coastguard Worker  build of libc++ which does not export any symbols, which can be useful when
168*58b9f456SAndroid Build Coastguard Worker  building statically for inclusion into another library.
169*58b9f456SAndroid Build Coastguard Worker
170*58b9f456SAndroid Build Coastguard Worker**_LIBCPP_DISABLE_EXTERN_TEMPLATE**:
171*58b9f456SAndroid Build Coastguard Worker  This macro is used to disable extern template declarations in the libc++
172*58b9f456SAndroid Build Coastguard Worker  headers. The intended use case is for clients who wish to use the libc++
173*58b9f456SAndroid Build Coastguard Worker  headers without taking a dependency on the libc++ library itself.
174*58b9f456SAndroid Build Coastguard Worker
175*58b9f456SAndroid Build Coastguard Worker**_LIBCPP_ENABLE_TUPLE_IMPLICIT_REDUCED_ARITY_EXTENSION**:
176*58b9f456SAndroid Build Coastguard Worker  This macro is used to re-enable an extension in `std::tuple` which allowed
177*58b9f456SAndroid Build Coastguard Worker  it to be implicitly constructed from fewer initializers than contained
178*58b9f456SAndroid Build Coastguard Worker  elements. Elements without an initializer are default constructed. For example:
179*58b9f456SAndroid Build Coastguard Worker
180*58b9f456SAndroid Build Coastguard Worker  .. code-block:: cpp
181*58b9f456SAndroid Build Coastguard Worker
182*58b9f456SAndroid Build Coastguard Worker    std::tuple<std::string, int, std::error_code> foo() {
183*58b9f456SAndroid Build Coastguard Worker      return {"hello world", 42}; // default constructs error_code
184*58b9f456SAndroid Build Coastguard Worker    }
185*58b9f456SAndroid Build Coastguard Worker
186*58b9f456SAndroid Build Coastguard Worker
187*58b9f456SAndroid Build Coastguard Worker  Since libc++ 4.0 this extension has been disabled by default. This macro
188*58b9f456SAndroid Build Coastguard Worker  may be defined to re-enable it in order to support existing code that depends
189*58b9f456SAndroid Build Coastguard Worker  on the extension. New use of this extension should be discouraged.
190*58b9f456SAndroid Build Coastguard Worker  See `PR 27374 <http://llvm.org/PR27374>`_ for more information.
191*58b9f456SAndroid Build Coastguard Worker
192*58b9f456SAndroid Build Coastguard Worker  Note: The "reduced-arity-initialization" extension is still offered but only
193*58b9f456SAndroid Build Coastguard Worker  for explicit conversions. Example:
194*58b9f456SAndroid Build Coastguard Worker
195*58b9f456SAndroid Build Coastguard Worker  .. code-block:: cpp
196*58b9f456SAndroid Build Coastguard Worker
197*58b9f456SAndroid Build Coastguard Worker    auto foo() {
198*58b9f456SAndroid Build Coastguard Worker      using Tup = std::tuple<std::string, int, std::error_code>;
199*58b9f456SAndroid Build Coastguard Worker      return Tup{"hello world", 42}; // explicit constructor called. OK.
200*58b9f456SAndroid Build Coastguard Worker    }
201*58b9f456SAndroid Build Coastguard Worker
202*58b9f456SAndroid Build Coastguard Worker**_LIBCPP_DISABLE_ADDITIONAL_DIAGNOSTICS**:
203*58b9f456SAndroid Build Coastguard Worker  This macro disables the additional diagnostics generated by libc++ using the
204*58b9f456SAndroid Build Coastguard Worker  `diagnose_if` attribute. These additional diagnostics include checks for:
205*58b9f456SAndroid Build Coastguard Worker
206*58b9f456SAndroid Build Coastguard Worker    * Giving `set`, `map`, `multiset`, `multimap` and their `unordered_`
207*58b9f456SAndroid Build Coastguard Worker      counterparts a comparator which is not const callable.
208*58b9f456SAndroid Build Coastguard Worker    * Giving an unordered associative container a hasher that is not const
209*58b9f456SAndroid Build Coastguard Worker      callable.
210*58b9f456SAndroid Build Coastguard Worker
211*58b9f456SAndroid Build Coastguard Worker**_LIBCPP_NO_VCRUNTIME**:
212*58b9f456SAndroid Build Coastguard Worker  Microsoft's C and C++ headers are fairly entangled, and some of their C++
213*58b9f456SAndroid Build Coastguard Worker  headers are fairly hard to avoid. In particular, `vcruntime_new.h` gets pulled
214*58b9f456SAndroid Build Coastguard Worker  in from a lot of other headers and provides definitions which clash with
215*58b9f456SAndroid Build Coastguard Worker  libc++ headers, such as `nothrow_t` (note that `nothrow_t` is a struct, so
216*58b9f456SAndroid Build Coastguard Worker  there's no way for libc++ to provide a compatible definition, since you can't
217*58b9f456SAndroid Build Coastguard Worker  have multiple definitions).
218*58b9f456SAndroid Build Coastguard Worker
219*58b9f456SAndroid Build Coastguard Worker  By default, libc++ solves this problem by deferring to Microsoft's vcruntime
220*58b9f456SAndroid Build Coastguard Worker  headers where needed. However, it may be undesirable to depend on vcruntime
221*58b9f456SAndroid Build Coastguard Worker  headers, since they may not always be available in cross-compilation setups,
222*58b9f456SAndroid Build Coastguard Worker  or they may clash with other headers. The `_LIBCPP_NO_VCRUNTIME` macro
223*58b9f456SAndroid Build Coastguard Worker  prevents libc++ from depending on vcruntime headers. Consequently, it also
224*58b9f456SAndroid Build Coastguard Worker  prevents libc++ headers from being interoperable with vcruntime headers (from
225*58b9f456SAndroid Build Coastguard Worker  the aforementioned clashes), so users of this macro are promising to not
226*58b9f456SAndroid Build Coastguard Worker  attempt to combine libc++ headers with the problematic vcruntime headers. This
227*58b9f456SAndroid Build Coastguard Worker  macro also currently prevents certain `operator new`/`operator delete`
228*58b9f456SAndroid Build Coastguard Worker  replacement scenarios from working, e.g. replacing `operator new` and
229*58b9f456SAndroid Build Coastguard Worker  expecting a non-replaced `operator new[]` to call the replaced `operator new`.
230*58b9f456SAndroid Build Coastguard Worker
231*58b9f456SAndroid Build Coastguard Worker**_LIBCPP_ENABLE_NODISCARD**:
232*58b9f456SAndroid Build Coastguard Worker  Allow the library to add ``[[nodiscard]]`` attributes to entities not specified
233*58b9f456SAndroid Build Coastguard Worker  as ``[[nodiscard]]`` by the current language dialect. This includes
234*58b9f456SAndroid Build Coastguard Worker  backporting applications of ``[[nodiscard]]`` from newer dialects and
235*58b9f456SAndroid Build Coastguard Worker  additional extended applications at the discretion of the library. All
236*58b9f456SAndroid Build Coastguard Worker  additional applications of ``[[nodiscard]]`` are disabled by default.
237*58b9f456SAndroid Build Coastguard Worker  See :ref:`Extended Applications of [[nodiscard]] <nodiscard extension>` for
238*58b9f456SAndroid Build Coastguard Worker  more information.
239*58b9f456SAndroid Build Coastguard Worker
240*58b9f456SAndroid Build Coastguard Worker**_LIBCPP_DISABLE_NODISCARD_EXT**:
241*58b9f456SAndroid Build Coastguard Worker  This macro prevents the library from applying ``[[nodiscard]]`` to entities
242*58b9f456SAndroid Build Coastguard Worker  purely as an extension. See :ref:`Extended Applications of [[nodiscard]] <nodiscard extension>`
243*58b9f456SAndroid Build Coastguard Worker  for more information.
244*58b9f456SAndroid Build Coastguard Worker
245*58b9f456SAndroid Build Coastguard Worker**_LIBCPP_ENABLE_DEPRECATION_WARNINGS**:
246*58b9f456SAndroid Build Coastguard Worker  This macro enables warnings when using deprecated components. For example,
247*58b9f456SAndroid Build Coastguard Worker  when compiling in C++11 mode, using `std::auto_ptr` with the macro defined
248*58b9f456SAndroid Build Coastguard Worker  will trigger a warning saying that `std::auto_ptr` is deprecated. By default,
249*58b9f456SAndroid Build Coastguard Worker  this macro is not defined.
250*58b9f456SAndroid Build Coastguard Worker
251*58b9f456SAndroid Build Coastguard WorkerC++17 Specific Configuration Macros
252*58b9f456SAndroid Build Coastguard Worker-----------------------------------
253*58b9f456SAndroid Build Coastguard Worker**_LIBCPP_ENABLE_CXX17_REMOVED_FEATURES**:
254*58b9f456SAndroid Build Coastguard Worker  This macro is used to re-enable all the features removed in C++17. The effect
255*58b9f456SAndroid Build Coastguard Worker  is equivalent to manually defining each macro listed below.
256*58b9f456SAndroid Build Coastguard Worker
257*58b9f456SAndroid Build Coastguard Worker**_LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS**:
258*58b9f456SAndroid Build Coastguard Worker  This macro is used to re-enable the `set_unexpected`, `get_unexpected`, and
259*58b9f456SAndroid Build Coastguard Worker  `unexpected` functions, which were removed in C++17.
260*58b9f456SAndroid Build Coastguard Worker
261*58b9f456SAndroid Build Coastguard Worker**_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR**:
262*58b9f456SAndroid Build Coastguard Worker  This macro is used to re-enable `std::auto_ptr` in C++17.
263*58b9f456SAndroid Build Coastguard Worker
264*58b9f456SAndroid Build Coastguard WorkerC++2a Specific Configuration Macros:
265*58b9f456SAndroid Build Coastguard Worker------------------------------------
266*58b9f456SAndroid Build Coastguard Worker**_LIBCPP_DISABLE_NODISCARD_AFTER_CXX17**:
267*58b9f456SAndroid Build Coastguard Worker  This macro can be used to disable diagnostics emitted from functions marked
268*58b9f456SAndroid Build Coastguard Worker  ``[[nodiscard]]`` in dialects after C++17.  See :ref:`Extended Applications of [[nodiscard]] <nodiscard extension>`
269*58b9f456SAndroid Build Coastguard Worker  for more information.
270*58b9f456SAndroid Build Coastguard Worker
271*58b9f456SAndroid Build Coastguard Worker
272*58b9f456SAndroid Build Coastguard WorkerLibc++ Extensions
273*58b9f456SAndroid Build Coastguard Worker=================
274*58b9f456SAndroid Build Coastguard Worker
275*58b9f456SAndroid Build Coastguard WorkerThis section documents various extensions provided by libc++, how they're
276*58b9f456SAndroid Build Coastguard Workerprovided, and any information regarding how to use them.
277*58b9f456SAndroid Build Coastguard Worker
278*58b9f456SAndroid Build Coastguard Worker.. _nodiscard extension:
279*58b9f456SAndroid Build Coastguard Worker
280*58b9f456SAndroid Build Coastguard WorkerExtended applications of ``[[nodiscard]]``
281*58b9f456SAndroid Build Coastguard Worker------------------------------------------
282*58b9f456SAndroid Build Coastguard Worker
283*58b9f456SAndroid Build Coastguard WorkerThe ``[[nodiscard]]`` attribute is intended to help users find bugs where
284*58b9f456SAndroid Build Coastguard Workerfunction return values are ignored when they shouldn't be. After C++17 the
285*58b9f456SAndroid Build Coastguard WorkerC++ standard has started to declared such library functions as ``[[nodiscard]]``.
286*58b9f456SAndroid Build Coastguard WorkerHowever, this application is limited and applies only to dialects after C++17.
287*58b9f456SAndroid Build Coastguard WorkerUsers who want help diagnosing misuses of STL functions may desire a more
288*58b9f456SAndroid Build Coastguard Workerliberal application of ``[[nodiscard]]``.
289*58b9f456SAndroid Build Coastguard Worker
290*58b9f456SAndroid Build Coastguard WorkerFor this reason libc++ provides an extension that does just that! The
291*58b9f456SAndroid Build Coastguard Workerextension must be enabled by defining ``_LIBCPP_ENABLE_NODISCARD``. The extended
292*58b9f456SAndroid Build Coastguard Workerapplications of ``[[nodiscard]]`` takes two forms:
293*58b9f456SAndroid Build Coastguard Worker
294*58b9f456SAndroid Build Coastguard Worker1. Backporting ``[[nodiscard]]`` to entities declared as such by the
295*58b9f456SAndroid Build Coastguard Worker   standard in newer dialects, but not in the present one.
296*58b9f456SAndroid Build Coastguard Worker
297*58b9f456SAndroid Build Coastguard Worker2. Extended applications of ``[[nodiscard]]``, at the libraries discretion,
298*58b9f456SAndroid Build Coastguard Worker   applied to entities never declared as such by the standard.
299*58b9f456SAndroid Build Coastguard Worker
300*58b9f456SAndroid Build Coastguard WorkerUsers may also opt-out of additional applications ``[[nodiscard]]`` using
301*58b9f456SAndroid Build Coastguard Workeradditional macros.
302*58b9f456SAndroid Build Coastguard Worker
303*58b9f456SAndroid Build Coastguard WorkerApplications of the first form, which backport ``[[nodiscard]]`` from a newer
304*58b9f456SAndroid Build Coastguard Workerdialect may be disabled using macros specific to the dialect it was added. For
305*58b9f456SAndroid Build Coastguard Workerexample ``_LIBCPP_DISABLE_NODISCARD_AFTER_CXX17``.
306*58b9f456SAndroid Build Coastguard Worker
307*58b9f456SAndroid Build Coastguard WorkerApplications of the second form, which are pure extensions, may be disabled
308*58b9f456SAndroid Build Coastguard Workerby defining ``_LIBCPP_DISABLE_NODISCARD_EXT``.
309*58b9f456SAndroid Build Coastguard Worker
310*58b9f456SAndroid Build Coastguard Worker
311*58b9f456SAndroid Build Coastguard WorkerEntities declared with ``_LIBCPP_NODISCARD_EXT``
312*58b9f456SAndroid Build Coastguard Worker~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
313*58b9f456SAndroid Build Coastguard Worker
314*58b9f456SAndroid Build Coastguard WorkerThis section lists all extended applications of ``[[nodiscard]]`` to entities
315*58b9f456SAndroid Build Coastguard Workerwhich no dialect declares as such (See the second form described above).
316*58b9f456SAndroid Build Coastguard Worker
317*58b9f456SAndroid Build Coastguard Worker* ``get_temporary_buffer``
318