diff --git a/libcxx/docs/ReleaseNotes.rst b/libcxx/docs/ReleaseNotes.rst --- a/libcxx/docs/ReleaseNotes.rst +++ b/libcxx/docs/ReleaseNotes.rst @@ -55,6 +55,10 @@ functions instead of as hidden friends, in conformance with the C++ standard. Also see `issue 56187 `_. +- ``_LIBCPP_ENABLE_NODISCARD`` and ``_LIBCPP_DISABLE_NODISCARD_AFTER_CXX17`` are no longer respected. + Any standards-required ``[[nodiscard]]`` applications in C++20 are now always enabled. Any extended applications + can now be enabled by defining ``_LIBCPP_ENABLE_NODISCARD_EXT``. + ABI Affecting Changes --------------------- diff --git a/libcxx/docs/UsingLibcxx.rst b/libcxx/docs/UsingLibcxx.rst --- a/libcxx/docs/UsingLibcxx.rst +++ b/libcxx/docs/UsingLibcxx.rst @@ -248,19 +248,9 @@ 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. - See :ref:`Extended Applications of [[nodiscard]] ` for - more information. - -**_LIBCPP_DISABLE_NODISCARD_EXT**: - This macro prevents the library from applying ``[[nodiscard]]`` to entities - purely as an extension. See :ref:`Extended Applications of [[nodiscard]] ` - for more information. +**_LIBCPP_ENABLE_NODISCARD_EXT**: + This macro allows the library to apply ``[[nodiscard]]`` to entities as an extension. + See :ref:`Extended Applications of [[nodiscard]] ` for more information. **_LIBCPP_DISABLE_DEPRECATION_WARNINGS**: This macro disables warnings when using deprecated components. For example, @@ -350,7 +340,7 @@ 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 +extension must be enabled by defining ``_LIBCPP_ENABLE_NODISCARD_EXT``. The extended applications of ``[[nodiscard]]`` takes two forms: 1. Backporting ``[[nodiscard]]`` to entities declared as such by the @@ -359,17 +349,6 @@ 2. Extended applications of ``[[nodiscard]]``, at the library's 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 in which 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``. - - Entities declared with ``_LIBCPP_NODISCARD_EXT`` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/libcxx/include/__config b/libcxx/include/__config --- a/libcxx/include/__config +++ b/libcxx/include/__config @@ -858,13 +858,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_ENABLE_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 _LIBCPP_STD_VER > 17 || defined(_LIBCPP_ENABLE_NODISCARD_EXT) # define _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_NODISCARD # else # define _LIBCPP_NODISCARD_AFTER_CXX17 diff --git a/libcxx/test/libcxx/diagnostics/enable_nodiscard_disable_after_cxx17.verify.cpp b/libcxx/test/libcxx/diagnostics/enable_nodiscard_disable_after_cxx17.verify.cpp deleted file mode 100644 --- a/libcxx/test/libcxx/diagnostics/enable_nodiscard_disable_after_cxx17.verify.cpp +++ /dev/null @@ -1,28 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -// UNSUPPORTED: c++03 - -// Test that _LIBCPP_DISABLE_NODISCARD_EXT only disables _LIBCPP_NODISCARD_EXT -// and not _LIBCPP_NODISCARD_AFTER_CXX17. - -// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_ENABLE_NODISCARD -// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_NODISCARD_AFTER_CXX17 -#include <__config> - - -_LIBCPP_NODISCARD_EXT int foo() { return 42; } -_LIBCPP_NODISCARD_AFTER_CXX17 int bar() { return 42; } - -int main(int, char**) { - foo(); // expected-warning-re{{ignoring return value of function declared with {{'nodiscard'|warn_unused_result}} attribute}} - bar(); // OK. - (void)foo(); // OK. - - return 0; -} diff --git a/libcxx/test/libcxx/diagnostics/enable_nodiscard_disable_nodiscard_ext.verify.cpp b/libcxx/test/libcxx/diagnostics/enable_nodiscard_disable_nodiscard_ext.verify.cpp deleted file mode 100644 --- a/libcxx/test/libcxx/diagnostics/enable_nodiscard_disable_nodiscard_ext.verify.cpp +++ /dev/null @@ -1,25 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -// UNSUPPORTED: c++03 - -// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_ENABLE_NODISCARD -// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_NODISCARD_EXT -#include <__config> - - -_LIBCPP_NODISCARD_EXT int foo() { return 42; } -_LIBCPP_NODISCARD_AFTER_CXX17 int bar() { return 42; } - -int main(int, char**) { - bar(); // expected-warning-re{{ignoring return value of function declared with {{'nodiscard'|warn_unused_result}} attribute}} - foo(); // OK. - (void)bar(); // OK. - - return 0; -} diff --git a/libcxx/test/libcxx/diagnostics/enable_nodiscard.verify.cpp b/libcxx/test/libcxx/diagnostics/enable_nodiscard_ext.verify.cpp rename from libcxx/test/libcxx/diagnostics/enable_nodiscard.verify.cpp rename to libcxx/test/libcxx/diagnostics/enable_nodiscard_ext.verify.cpp --- a/libcxx/test/libcxx/diagnostics/enable_nodiscard.verify.cpp +++ b/libcxx/test/libcxx/diagnostics/enable_nodiscard_ext.verify.cpp @@ -12,7 +12,7 @@ // UNSUPPORTED: c++03 -// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_ENABLE_NODISCARD +// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_ENABLE_NODISCARD_EXT #include <__config> diff --git a/libcxx/test/libcxx/diagnostics/nodiscard_aftercxx17.pass.cpp b/libcxx/test/libcxx/diagnostics/nodiscard_aftercxx17.pass.cpp deleted file mode 100644 --- a/libcxx/test/libcxx/diagnostics/nodiscard_aftercxx17.pass.cpp +++ /dev/null @@ -1,25 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -// Test that _LIBCPP_NODISCARD_AFTER_CXX17 is disabled whenever -// _LIBCPP_DISABLE_NODISCARD_AFTER_CXX17 is defined by the user. - -// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_NODISCARD_AFTER_CXX17 - -#include <__config> - -#include "test_macros.h" - -_LIBCPP_NODISCARD_AFTER_CXX17 int foo() { return 6; } - -int main(int, char**) -{ - foo(); // no error here! - - return 0; -} diff --git a/libcxx/test/libcxx/diagnostics/nodiscard_extensions.pass.cpp b/libcxx/test/libcxx/diagnostics/nodiscard_extensions.pass.cpp --- a/libcxx/test/libcxx/diagnostics/nodiscard_extensions.pass.cpp +++ b/libcxx/test/libcxx/diagnostics/nodiscard_extensions.pass.cpp @@ -7,13 +7,13 @@ //===----------------------------------------------------------------------===// // Test that entities declared [[nodiscard]] as at extension by libc++, are -// only actually declared such when _LIBCPP_ENABLE_NODISCARD is specified. +// only actually declared such when _LIBCPP_ENABLE_NODISCARD_EXT is specified. // This test intentionally leaks memory, so it is unsupported under ASAN. // UNSUPPORTED: asan // All entities to which libc++ applies [[nodiscard]] as an extension should -// be tested here and in nodiscard_extensions.fail.cpp. They should also +// be tested here and in nodiscard_extensions.verify.cpp. They should also // be listed in `UsingLibcxx.rst` in the documentation for the extension. // Disable any builtin recognition of std::* in the compiler, that might also diff --git a/libcxx/test/libcxx/diagnostics/nodiscard_extensions.verify.cpp b/libcxx/test/libcxx/diagnostics/nodiscard_extensions.verify.cpp --- a/libcxx/test/libcxx/diagnostics/nodiscard_extensions.verify.cpp +++ b/libcxx/test/libcxx/diagnostics/nodiscard_extensions.verify.cpp @@ -9,13 +9,13 @@ // UNSUPPORTED: c++03 // Test that entities declared [[nodiscard]] as an extension by libc++, are -// only actually declared such when _LIBCPP_ENABLE_NODISCARD is specified. +// only actually declared such when _LIBCPP_ENABLE_NODISCARD_EXT is specified. // All entities to which libc++ applies [[nodiscard]] as an extension should // be tested here and in nodiscard_extensions.pass.cpp. They should also // be listed in `UsingLibcxx.rst` in the documentation for the extension. -// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_ENABLE_NODISCARD +// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_ENABLE_NODISCARD_EXT // ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS #include diff --git a/libcxx/test/libcxx/thread/thread.lock/thread.lock.guard/nodiscard.verify.cpp b/libcxx/test/libcxx/thread/thread.lock/thread.lock.guard/nodiscard.verify.cpp --- a/libcxx/test/libcxx/thread/thread.lock/thread.lock.guard/nodiscard.verify.cpp +++ b/libcxx/test/libcxx/thread/thread.lock/thread.lock.guard/nodiscard.verify.cpp @@ -21,7 +21,7 @@ // Test that we properly apply [[nodiscard]] to lock_guard's constructors, // which is a libc++ extension. -// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_ENABLE_NODISCARD +// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_ENABLE_NODISCARD_EXT #include