ut
ut copied to clipboard
`expect()` does not work with non-copiable types
Expected Behavior
#include <boost/ut.hpp>
#include <memory>
using namespace boost::ut;
int main() {
"test"_test = []() {
std::unique_ptr<int> p;
expect(that % p == nullptr);
};
}
Should compile.
Actual Behavior
Does not compile:
In file included from test.cpp:1:
../boost/ut.hpp: In instantiation of ‘constexpr auto boost::ext::ut::v1_1_8::expect(const TExpr&, const boost::ext::ut::v1_1_8::reflection::source_location&) [with TExpr = boost::ext::ut::v1_1_8::detail::eq_<std::unique_ptr<int>, std::nullptr_t>; typename boost::ext::ut::v1_1_8::type_traits::requires_<(is_op_v<TExpr> || is_convertible_v<TExpr, bool>)>::type <anonymous> = 0]’:
test.cpp:9:31: required from here
../boost/ut.hpp:2080:50: error: use of deleted function ‘boost::ext::ut::v1_1_8::detail::eq_<std::unique_ptr<int>, std::nullptr_t>::eq_(const boost::ext::ut::v1_1_8::detail::eq_<std::unique_ptr<int>, std::nullptr_t>&)’
2080 | return detail::expect_<TExpr>{detail::on<TExpr>(
| ~~~~~~~~~~~~~~~~~^
2081 | events::assertion<TExpr>{.expr = expr, .location = sl})};
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../boost/ut.hpp:648:8: note: ‘boost::ext::ut::v1_1_8::detail::eq_<std::unique_ptr<int>, std::nullptr_t>::eq_(const boost::ext::ut::v1_1_8::detail::eq_<std::unique_ptr<int>, std::nullptr_t>&)’ is implicitly deleted because the default definition would be ill-formed:
648 | struct eq_ : op {
| ^~~
../boost/ut.hpp:648:8: error: use of deleted function ‘std::unique_ptr<_Tp, _Dp>::unique_ptr(const std::unique_ptr<_Tp, _Dp>&) [with _Tp = int; _Dp = std::default_delete<int>]’
In file included from /usr/include/c++/10/memory:83,
from test.cpp:2:
/usr/include/c++/10/bits/unique_ptr.h:468:7: note: declared here
468 | unique_ptr(const unique_ptr&) = delete;
| ^~~~~~~~~~
In file included from test.cpp:1:
../boost/ut.hpp:2081:62: error: no matching function for call to ‘boost::ext::ut::v1_1_8::detail::expect_<boost::ext::ut::v1_1_8::detail::eq_<std::unique_ptr<int>, std::nullptr_t> >::expect_(<brace-enclosed initializer list>)’
2081 | events::assertion<TExpr>{.expr = expr, .location = sl})};
| ^
../boost/ut.hpp:1568:22: note: candidate: ‘constexpr boost::ext::ut::v1_1_8::detail::expect_<T>::expect_(bool) [with T = boost::ext::ut::v1_1_8::detail::eq_<std::unique_ptr<int>, std::nullptr_t>]’
1568 | constexpr explicit expect_(bool value) : value_{value} { cfg::wip = {}; }
| ^~~~~~~
../boost/ut.hpp:1568:22: note: conversion of argument 1 would be ill-formed:
../boost/ut.hpp:1567:8: note: candidate: ‘constexpr boost::ext::ut::v1_1_8::detail::expect_<boost::ext::ut::v1_1_8::detail::eq_<std::unique_ptr<int>, std::nullptr_t> >::expect_(const boost::ext::ut::v1_1_8::detail::expect_<boost::ext::ut::v1_1_8::detail::eq_<std::unique_ptr<int>, std::nullptr_t> >&)’
1567 | struct expect_ {
| ^~~~~~~
../boost/ut.hpp:1567:8: note: conversion of argument 1 would be ill-formed:
../boost/ut.hpp:1567:8: note: candidate: ‘constexpr boost::ext::ut::v1_1_8::detail::expect_<boost::ext::ut::v1_1_8::detail::eq_<std::unique_ptr<int>, std::nullptr_t> >::expect_(boost::ext::ut::v1_1_8::detail::expect_<boost::ext::ut::v1_1_8::detail::eq_<std::unique_ptr<int>, std::nullptr_t> >&&)’
../boost/ut.hpp:1567:8: note: conversion of argument 1 would be ill-formed:
../boost/ut.hpp: In instantiation of ‘constexpr boost::ext::ut::v1_1_8::detail::that_::expr<T>::expr(const T&) [with T = std::unique_ptr<int>]’:
../boost/ut.hpp:1540:18: required from ‘constexpr auto boost::ext::ut::v1_1_8::detail::that_::operator%(const T&) const [with T = std::unique_ptr<int>]’
test.cpp:9:19: required from here
../boost/ut.hpp:1497:47: error: use of deleted function ‘std::unique_ptr<_Tp, _Dp>::unique_ptr(const std::unique_ptr<_Tp, _Dp>&) [with _Tp = int; _Dp = std::default_delete<int>]’
1497 | constexpr explicit expr(const T& t) : t_{t} {}
| ^
In file included from /usr/include/c++/10/memory:83,
from test.cpp:2:
/usr/include/c++/10/bits/unique_ptr.h:468:7: note: declared here
468 | unique_ptr(const unique_ptr&) = delete;
| ^~~~~~~~~~
In file included from test.cpp:1:
../boost/ut.hpp: In instantiation of ‘constexpr boost::ext::ut::v1_1_8::detail::eq_<TLhs, TRhs>::eq_(const TLhs&, const TRhs&) [with TLhs = std::unique_ptr<int>; TRhs = std::nullptr_t]’:
../boost/ut.hpp:1503:25: required from ‘constexpr auto boost::ext::ut::v1_1_8::detail::that_::expr<T>::operator==(const TRhs&) const [with TRhs = std::nullptr_t; T = std::unique_ptr<int>]’
test.cpp:9:24: required from here
../boost/ut.hpp:668:12: error: use of deleted function ‘std::unique_ptr<_Tp, _Dp>::unique_ptr(const std::unique_ptr<_Tp, _Dp>&) [with _Tp = int; _Dp = std::default_delete<int>]’
668 | }()} {}
| ^
In file included from /usr/include/c++/10/memory:83,
from test.cpp:2:
/usr/include/c++/10/bits/unique_ptr.h:468:7: note: declared here
468 | unique_ptr(const unique_ptr&) = delete;
| ^~~~~~~~~~
Steps to Reproduce the Problem
- Attempt to compile the code above
Specifications
- Version: 1.1.9
- Platform: Linux x86_64
- Subsystem: g++ v10.3.0