Skip to content

[libc++] Add nodiscard attribute to std::make_unique/std::make_shared #153115

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions libcxx/include/memory
Original file line number Diff line number Diff line change
Expand Up @@ -566,15 +566,15 @@ class bad_weak_ptr
};

template<class T, class... Args>
constexpr unique_ptr<T> make_unique(Args&&... args); // C++14, constexpr since C++23
[[nodiscard]] constexpr unique_ptr<T> make_unique(Args&&... args); // C++14, constexpr since C++23
template<class T>
constexpr unique_ptr<T> make_unique(size_t n); // C++14, constexpr since C++23
[[nodiscard]] constexpr unique_ptr<T> make_unique(size_t n); // C++14, constexpr since C++23
template<class T, class... Args> unspecified make_unique(Args&&...) = delete; // C++14, T == U[N]

template<class T>
constexpr unique_ptr<T> make_unique_for_overwrite(); // T is not array, C++20, constexpr since C++23
[[nodiscard]] constexpr unique_ptr<T> make_unique_for_overwrite(); // T is not array, C++20, constexpr since C++23
template<class T>
constexpr unique_ptr<T> make_unique_for_overwrite(size_t n); // T is U[], C++20, constexpr since C++23
[[nodiscard]] constexpr unique_ptr<T> make_unique_for_overwrite(size_t n); // T is U[], C++20, constexpr since C++23
template<class T, class... Args>
unspecified make_unique_for_overwrite(Args&&...) = delete; // T is U[N], C++20

Expand Down Expand Up @@ -702,39 +702,39 @@ template<class E, class T, class Y>
template<class D, class T> D* get_deleter(shared_ptr<T> const& p) noexcept;

template<class T, class... Args>
shared_ptr<T> make_shared(Args&&... args); // T is not an array
[[nodiscard]] shared_ptr<T> make_shared(Args&&... args); // T is not an array
template<class T, class A, class... Args>
shared_ptr<T> allocate_shared(const A& a, Args&&... args); // T is not an array
[[nodiscard]] shared_ptr<T> allocate_shared(const A& a, Args&&... args); // T is not an array

template<class T>
shared_ptr<T> make_shared(size_t N); // T is U[] (since C++20)
[[nodiscard]] shared_ptr<T> make_shared(size_t N); // T is U[] (since C++20)
template<class T, class A>
shared_ptr<T> allocate_shared(const A& a, size_t N); // T is U[] (since C++20)
[[nodiscard]] shared_ptr<T> allocate_shared(const A& a, size_t N); // T is U[] (since C++20)

template<class T>
shared_ptr<T> make_shared(); // T is U[N] (since C++20)
[[nodiscard]] shared_ptr<T> make_shared(); // T is U[N] (since C++20)
template<class T, class A>
shared_ptr<T> allocate_shared(const A& a); // T is U[N] (since C++20)
[[nodiscard]] shared_ptr<T> allocate_shared(const A& a); // T is U[N] (since C++20)

template<class T>
shared_ptr<T> make_shared(size_t N, const remove_extent_t<T>& u); // T is U[] (since C++20)
[[nodiscard]] shared_ptr<T> make_shared(size_t N, const remove_extent_t<T>& u); // T is U[] (since C++20)
template<class T, class A>
shared_ptr<T> allocate_shared(const A& a, size_t N, const remove_extent_t<T>& u); // T is U[] (since C++20)
[[nodiscard]] shared_ptr<T> allocate_shared(const A& a, size_t N, const remove_extent_t<T>& u); // T is U[] (since C++20)

template<class T> shared_ptr<T>
make_shared(const remove_extent_t<T>& u); // T is U[N] (since C++20)
[[nodiscard]] make_shared(const remove_extent_t<T>& u); // T is U[N] (since C++20)
template<class T, class A>
shared_ptr<T> allocate_shared(const A& a, const remove_extent_t<T>& u); // T is U[N] (since C++20)
[[nodiscard]] shared_ptr<T> allocate_shared(const A& a, const remove_extent_t<T>& u); // T is U[N] (since C++20)

template<class T>
shared_ptr<T> make_shared_for_overwrite(); // T is not U[], C++20
[[nodiscard]] shared_ptr<T> make_shared_for_overwrite(); // T is not U[], C++20
template<class T, class A>
shared_ptr<T> allocate_shared_for_overwrite(const A& a); // T is not U[], C++20
[[nodiscard]] shared_ptr<T> allocate_shared_for_overwrite(const A& a); // T is not U[], C++20

template<class T>
shared_ptr<T> make_shared_for_overwrite(size_t N); // T is U[], C++20
[[nodiscard]] shared_ptr<T> make_shared_for_overwrite(size_t N); // T is U[], C++20
template<class T, class A>
shared_ptr<T> allocate_shared_for_overwrite(const A& a, size_t N); // T is U[], C++20
[[nodiscard]] shared_ptr<T> allocate_shared_for_overwrite(const A& a, size_t N); // T is U[], C++20

template<class T>
class weak_ptr
Expand Down