[libcxx-commits] [libcxx] [libc++] Add nodiscard attribute to std::make_unique/std::make_shared (PR #153115)
via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Aug 13 16:19:03 PDT 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 HEAD~1 HEAD --extensions h,cpp -- libcxx/test/libcxx/memory/nodiscard.verify.cpp libcxx/include/__memory/shared_ptr.h libcxx/include/__memory/unique_ptr.h
``````````
</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 7a2b4a507..87c46ecc9 100644
--- a/libcxx/include/__memory/unique_ptr.h
+++ b/libcxx/include/__memory/unique_ptr.h
@@ -755,7 +755,8 @@ operator<=>(const unique_ptr<_T1, _D1>& __x, nullptr_t) {
#if _LIBCPP_STD_VER >= 14
template <class _Tp, class... _Args, enable_if_t<!is_array<_Tp>::value, int> = 0>
-[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr<_Tp> make_unique(_Args&&... __args) {
+[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr<_Tp>
+make_unique(_Args&&... __args) {
return unique_ptr<_Tp>(new _Tp(std::forward<_Args>(__args)...));
}
@@ -778,7 +779,8 @@ template <class _Tp, enable_if_t<!is_array_v<_Tp>, int> = 0>
}
template <class _Tp, enable_if_t<is_unbounded_array_v<_Tp>, int> = 0>
-[[nodiscard]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr<_Tp> make_unique_for_overwrite(size_t __n) {
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr<_Tp>
+make_unique_for_overwrite(size_t __n) {
return unique_ptr<_Tp>(__private_constructor_tag(), new __remove_extent_t<_Tp>[__n], __n);
}
diff --git a/libcxx/test/libcxx/memory/nodiscard.verify.cpp b/libcxx/test/libcxx/memory/nodiscard.verify.cpp
index 316ce0b47..34f751fb5 100644
--- a/libcxx/test/libcxx/memory/nodiscard.verify.cpp
+++ b/libcxx/test/libcxx/memory/nodiscard.verify.cpp
@@ -20,14 +20,12 @@
#include <memory>
void f() {
+ std::make_unique<int>(1); // expected-warning {{ignoring return value of function}}
+ std::make_shared<int>(1); // expected-warning {{ignoring return value of function}}
- std::make_unique<int>(1); // expected-warning {{ignoring return value of function}}
- std::make_shared<int>(1); // expected-warning {{ignoring return value of function}}
-
- std::make_unique<int[]>(5); // expected-warning {{ignoring return value of function}}
- std::make_shared<int[]>(5); // expected-warning {{ignoring return value of function}}
-
- std::make_unique_for_overwrite<int>(); // expected-warning {{ignoring return value of function}}
- std::make_shared_for_overwrite<int>(); // expected-warning {{ignoring return value of function}}
+ std::make_unique<int[]>(5); // expected-warning {{ignoring return value of function}}
+ std::make_shared<int[]>(5); // expected-warning {{ignoring return value of function}}
+ std::make_unique_for_overwrite<int>(); // expected-warning {{ignoring return value of function}}
+ std::make_shared_for_overwrite<int>(); // expected-warning {{ignoring return value of function}}
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/153115
More information about the libcxx-commits
mailing list