[libcxx-commits] [PATCH] D128267: [libc++] Enable [[nodiscard]] extensions by default

Nikolas Klauser via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Tue Jun 21 05:41:39 PDT 2022


philnik created this revision.
philnik added reviewers: ldionne, Mordante, var-const, EricWF.
Herald added a project: All.
philnik requested review of this revision.
Herald added a project: libc++.
Herald added a subscriber: libcxx-commits.
Herald added a reviewer: libc++.

Adding `[[nodiscard]]` to functions is a conforming extension and done extensively in the MSVC STL.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D128267

Files:
  libcxx/docs/ReleaseNotes.rst
  libcxx/docs/UsingLibcxx.rst
  libcxx/include/__config


Index: libcxx/include/__config
===================================================================
--- libcxx/include/__config
+++ libcxx/include/__config
@@ -880,13 +880,13 @@
 
 // _LIBCPP_NODISCARD_EXT may be used to apply [[nodiscard]] to entities not
 // specified as such as an extension.
-#  if defined(_LIBCPP_ENABLE_NODISCARD) && !defined(_LIBCPP_DISABLE_NODISCARD_EXT)
+#  if !defined(_LIBCPP_DISABLE_NODISCARD) && !defined(_LIBCPP_DISABLE_NODISCARD_EXT)
 #    define _LIBCPP_NODISCARD_EXT _LIBCPP_NODISCARD
 #  else
 #    define _LIBCPP_NODISCARD_EXT
 #  endif
 
-#  if !defined(_LIBCPP_DISABLE_NODISCARD_AFTER_CXX17) && (_LIBCPP_STD_VER > 17 || defined(_LIBCPP_ENABLE_NODISCARD))
+#  if !defined(_LIBCPP_DISABLE_NODISCARD_AFTER_CXX17) && (_LIBCPP_STD_VER > 17 || !defined(_LIBCPP_DISABLE_NODISCARD))
 #    define _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_NODISCARD
 #  else
 #    define _LIBCPP_NODISCARD_AFTER_CXX17
Index: libcxx/docs/UsingLibcxx.rst
===================================================================
--- libcxx/docs/UsingLibcxx.rst
+++ libcxx/docs/UsingLibcxx.rst
@@ -254,12 +254,11 @@
   replacement scenarios from working, e.g. replacing `operator new` and
   expecting a non-replaced `operator new[]` to call the replaced `operator new`.
 
-**_LIBCPP_ENABLE_NODISCARD**:
-  Allow the library to add ``[[nodiscard]]`` attributes to entities not specified
-  as ``[[nodiscard]]`` by the current language dialect. This includes
-  backporting applications of ``[[nodiscard]]`` from newer dialects and
-  additional extended applications at the discretion of the library. All
-  additional applications of ``[[nodiscard]]`` are disabled by default.
+**_LIBCPP_DISABLE_NODISCARD**:
+  Add ``[[nodiscard]]`` attributes only to entities specified as ``[[nodiscard]]``
+  by the current language dialect. This disables backporting applications
+  of ``[[nodiscard]]`` from newer dialects and additional extended applications
+  at the discretion of the library.
   See :ref:`Extended Applications of [[nodiscard]] <nodiscard extension>` for
   more information.
 
@@ -356,8 +355,8 @@
 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:
+extension is enabled by default and can be disabled 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.
Index: libcxx/docs/ReleaseNotes.rst
===================================================================
--- libcxx/docs/ReleaseNotes.rst
+++ libcxx/docs/ReleaseNotes.rst
@@ -148,6 +148,9 @@
   will be removed in LLVM 17. You can disable the deprecation warnings by defining
   ``_LIBCPP_NO_EXPERIMENTAL_DEPRECATION_WARNING_SEARCHERS``.
 
+- Extended applications of ``[[nodiscard]]`` are now enabled by default. They can be
+  disabled by defining ``_LIBCPP_DISBALE_NODISCARD``.
+
 ABI Changes
 -----------
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D128267.438658.patch
Type: text/x-patch
Size: 3158 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20220621/11aab421/attachment.bin>


More information about the libcxx-commits mailing list