diff --git a/src/tensorwrapper/tensor/tensor_class.cpp b/src/tensorwrapper/tensor/tensor_class.cpp index c13ab842..d40c94e3 100644 --- a/src/tensorwrapper/tensor/tensor_class.cpp +++ b/src/tensorwrapper/tensor/tensor_class.cpp @@ -75,6 +75,7 @@ void Tensor::swap(Tensor& other) noexcept { m_pimpl_.swap(other.m_pimpl_); } bool Tensor::operator==(const Tensor& rhs) const noexcept { if(has_pimpl_() != rhs.has_pimpl_()) return false; + if(!has_pimpl_()) return true; // Both don't have a PIMPL return (*m_pimpl_) == (*rhs.m_pimpl_); } diff --git a/tests/cxx/unit_tests/tensorwrapper/tensor/tensor_class.cpp b/tests/cxx/unit_tests/tensorwrapper/tensor/tensor_class.cpp index 6ea5da1f..3a2b1e0a 100644 --- a/tests/cxx/unit_tests/tensorwrapper/tensor/tensor_class.cpp +++ b/tests/cxx/unit_tests/tensorwrapper/tensor/tensor_class.cpp @@ -122,6 +122,8 @@ TEST_CASE("Tensor") { } SECTION("operator==") { + REQUIRE(defaulted == Tensor{}); + Tensor other_scalar(testing::smooth_scalar()); Tensor other_vector(testing::smooth_vector()); REQUIRE(scalar == other_scalar);