Skip to content

Commit 075af33

Browse files
authored
CXX-2625 Address sign conversion warnings for literal argument to make_unique<T[]>() (#1044)
1 parent fce3a0e commit 075af33

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

src/bsoncxx/include/bsoncxx/v_noabi/bsoncxx/stdx/make_unique.hpp

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,25 @@ struct make_unique_impl<T&&> {};
102102
template <typename T,
103103
typename... Args,
104104
typename Impl = detail::make_unique_impl<T>,
105-
typename = decltype(Impl::make(std::true_type{}, std::declval<Args>()...))>
105+
typename std::enable_if<!std::is_array<T>::value,
106+
decltype(Impl::make(std::true_type{}, std::declval<Args>()...),
107+
void())>::type* = nullptr>
106108
std::unique_ptr<T> make_unique(Args&&... args) {
107109
return Impl::make(std::true_type{}, std::forward<Args>(args)...);
108110
}
109111

112+
/**
113+
* @copydoc bsoncxx::v_noabi::stdx::make_unique
114+
*/
115+
template <typename T,
116+
typename Impl = detail::make_unique_impl<T>,
117+
typename std::enable_if<std::is_array<T>::value,
118+
decltype(Impl::make(std::true_type{}, std::declval<std::size_t>()),
119+
void())>::type* = nullptr>
120+
std::unique_ptr<T> make_unique(std::size_t count) {
121+
return Impl::make(std::true_type{}, count);
122+
}
123+
110124
/**
111125
* @brief Create a new std::unique_ptr that points-to a default-initialized instance of the given
112126
* type.
@@ -125,11 +139,25 @@ std::unique_ptr<T> make_unique(Args&&... args) {
125139
template <typename T,
126140
typename... Args,
127141
typename Impl = detail::make_unique_impl<T>,
128-
typename = decltype(Impl::make(std::false_type{}, std::declval<Args>()...))>
142+
typename std::enable_if<!std::is_array<T>::value,
143+
decltype(Impl::make(std::false_type{}, std::declval<Args>()...),
144+
void())>::type* = nullptr>
129145
std::unique_ptr<T> make_unique_for_overwrite(Args&&... args) {
130146
return Impl::make(std::false_type{}, std::forward<Args>(args)...);
131147
}
132148

149+
/**
150+
* @copydoc bsoncxx::v_noabi::stdx::make_unique_for_overwrite
151+
*/
152+
template <typename T,
153+
typename Impl = detail::make_unique_impl<T>,
154+
typename std::enable_if<std::is_array<T>::value,
155+
decltype(Impl::make(std::false_type{}, std::declval<std::size_t>()),
156+
void())>::type* = nullptr>
157+
std::unique_ptr<T> make_unique_for_overwrite(std::size_t count) {
158+
return Impl::make(std::false_type{}, count);
159+
}
160+
133161
} // namespace stdx
134162
BSONCXX_INLINE_NAMESPACE_END
135163
} // namespace bsoncxx

0 commit comments

Comments
 (0)