Skip to content

CXX-2625 Address sign conversion warnings for literal argument to make_unique<T[]>() #1044

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

Merged
merged 1 commit into from
Oct 23, 2023
Merged
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,25 @@ struct make_unique_impl<T&&> {};
template <typename T,
typename... Args,
typename Impl = detail::make_unique_impl<T>,
typename = decltype(Impl::make(std::true_type{}, std::declval<Args>()...))>
typename std::enable_if<!std::is_array<T>::value,
decltype(Impl::make(std::true_type{}, std::declval<Args>()...),
void())>::type* = nullptr>
std::unique_ptr<T> make_unique(Args&&... args) {
return Impl::make(std::true_type{}, std::forward<Args>(args)...);
}

/**
* @copydoc bsoncxx::v_noabi::stdx::make_unique
*/
template <typename T,
typename Impl = detail::make_unique_impl<T>,
typename std::enable_if<std::is_array<T>::value,
decltype(Impl::make(std::true_type{}, std::declval<std::size_t>()),
void())>::type* = nullptr>
std::unique_ptr<T> make_unique(std::size_t count) {
return Impl::make(std::true_type{}, count);
}

/**
* @brief Create a new std::unique_ptr that points-to a default-initialized instance of the given
* type.
Expand All @@ -125,11 +139,25 @@ std::unique_ptr<T> make_unique(Args&&... args) {
template <typename T,
typename... Args,
typename Impl = detail::make_unique_impl<T>,
typename = decltype(Impl::make(std::false_type{}, std::declval<Args>()...))>
typename std::enable_if<!std::is_array<T>::value,
decltype(Impl::make(std::false_type{}, std::declval<Args>()...),
void())>::type* = nullptr>
std::unique_ptr<T> make_unique_for_overwrite(Args&&... args) {
return Impl::make(std::false_type{}, std::forward<Args>(args)...);
}

/**
* @copydoc bsoncxx::v_noabi::stdx::make_unique_for_overwrite
*/
template <typename T,
typename Impl = detail::make_unique_impl<T>,
typename std::enable_if<std::is_array<T>::value,
decltype(Impl::make(std::false_type{}, std::declval<std::size_t>()),
void())>::type* = nullptr>
std::unique_ptr<T> make_unique_for_overwrite(std::size_t count) {
return Impl::make(std::false_type{}, count);
}

} // namespace stdx
BSONCXX_INLINE_NAMESPACE_END
} // namespace bsoncxx
Expand Down