[libcxx-commits] [libcxx] [libc++][memory] Applied `[[nodiscard]]` to smart pointers (PR #168483)

via libcxx-commits libcxx-commits at lists.llvm.org
Tue Nov 18 09:49:04 PST 2025


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff origin/main HEAD --extensions cpp,h -- libcxx/include/__memory/shared_ptr.h libcxx/include/__memory/unique_ptr.h libcxx/test/libcxx/utilities/smartptr/nodiscard.verify.cpp --diff_from_common_commit
``````````

:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/libcxx/include/__memory/unique_ptr.h b/libcxx/include/__memory/unique_ptr.h
index b5e2d79a3..a822c761b 100644
--- a/libcxx/include/__memory/unique_ptr.h
+++ b/libcxx/include/__memory/unique_ptr.h
@@ -675,7 +675,8 @@ operator<=>(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {
 #endif
 
 template <class _T1, class _D1>
-inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool operator==(const unique_ptr<_T1, _D1>& __x, nullptr_t) _NOEXCEPT {
+inline _LIBCPP_HIDE_FROM_ABI
+_LIBCPP_CONSTEXPR_SINCE_CXX23 bool operator==(const unique_ptr<_T1, _D1>& __x, nullptr_t) _NOEXCEPT {
   return !__x;
 }
 
diff --git a/libcxx/test/libcxx/utilities/smartptr/nodiscard.verify.cpp b/libcxx/test/libcxx/utilities/smartptr/nodiscard.verify.cpp
index 641ffcb01..7859b92e5 100644
--- a/libcxx/test/libcxx/utilities/smartptr/nodiscard.verify.cpp
+++ b/libcxx/test/libcxx/utilities/smartptr/nodiscard.verify.cpp
@@ -49,21 +49,21 @@ void test() {
     *sPtr;            // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
     sPtr.use_count(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
 #if TEST_STD_VER <= 20
-    sPtr.unique();    // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
+    sPtr.unique(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
 #endif
     // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
     sPtr.owner_before(std::shared_ptr<int>());
     // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
     sPtr.owner_before(std::weak_ptr<int>());
-#  if TEST_STD_VER >= 17
+#if TEST_STD_VER >= 17
     sPtr[0]; // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
-#  endif
+#endif
 
     // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
     std::allocate_shared<int>(std::allocator<int>(), 5);
     // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
     std::make_shared<int>();
-#  if TEST_STD_VER >= 20
+#if TEST_STD_VER >= 20
     // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
     std::allocate_shared_for_overwrite<int>(std::allocator<int>());
     // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
@@ -96,7 +96,7 @@ void test() {
     std::make_shared<int[]>(5, 82);
     // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
     std::make_shared_for_overwrite<int[]>(5);
-#  endif
+#endif
 
     // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
     std::static_pointer_cast<int[]>(sPtr);
@@ -116,10 +116,10 @@ void test() {
     std::reinterpret_pointer_cast<int[]>(sPtr);
     // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
     std::reinterpret_pointer_cast<int[]>(std::move(sPtr));
-#  if !defined(TEST_HAS_NO_RTTI)
+#if !defined(TEST_HAS_NO_RTTI)
     // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
     std::get_deleter<int[]>(sPtr);
-#  endif
+#endif
   }
   { // [util.smartptr.weak]
     std::weak_ptr<int> wPtr;
@@ -139,12 +139,12 @@ void test() {
 
     es.shared_from_this(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
     ces.shared_from_this(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
-#  if TEST_STD_VER >= 17
+#if TEST_STD_VER >= 17
     es.weak_from_this();  // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
     ces.weak_from_this(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
-#  endif
+#endif
   }
-#  if TEST_STD_VER >= 23
+#if TEST_STD_VER >= 23
   { // [smartptr.adapt]
     std::unique_ptr<int> uPtr;
     // [inout.ptr]
@@ -152,5 +152,5 @@ void test() {
     // [out.ptr]
     std::out_ptr(uPtr); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
   }
-#  endif
+#endif
 }

``````````

</details>


https://github.com/llvm/llvm-project/pull/168483


More information about the libcxx-commits mailing list