The class template semiregular-box<T> of [range.semi.wrap] is specified
to value-initialize the underlying object whenever its type is default
initializable. Our primary template for __detail::__box respects this
requirement, but the recently added partial specialization (for types
that are already semiregular) does not.
This patch fixes this issue, and additionally makes the corresponding in
place constructor explicit (as in the primary template).
libstdc++-v3/ChangeLog:
* include/std/ranges (__detail::__box): For the partial
specialization used by types that are already semiregular,
make the default constructor value-initialize the underlying
object instead of default-initializing it. Make its in place
constructor explicit.
* testsuite/std/ranges/adaptors/detail/semiregular_box.cc:
Augment test.
struct __box<_Tp>
{
private:
- [[no_unique_address]] _Tp _M_value;
+ [[no_unique_address]] _Tp _M_value = _Tp();
public:
__box() = default;
template<typename... _Args>
requires constructible_from<_Tp, _Args...>
- constexpr
+ constexpr explicit
__box(in_place_t, _Args&&... __args)
noexcept(is_nothrow_constructible_v<_Tp, _Args...>)
: _M_value{std::forward<_Args>(__args)...}
a.operator->();
a.has_value();
});
+
+constexpr bool
+test01()
+{
+ // Verify the default constructor value-initializes the underlying object.
+ __box<int> x;
+ __glibcxx_assert(*x == 0);
+ return true;
+}
+static_assert(test01());