From: Wolfgang Bangerth Date: Wed, 15 Mar 2023 17:49:23 +0000 (-0600) Subject: Do not allow assigning to rvalue references of Tensor. X-Git-Tag: v9.5.0-rc1~468^2~2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f6d035119b91d618a81599b3e00412a87a1bf6d8;p=dealii.git Do not allow assigning to rvalue references of Tensor. --- diff --git a/include/deal.II/base/tensor.h b/include/deal.II/base/tensor.h index fe4ff27b41..1750f8b42d 100644 --- a/include/deal.II/base/tensor.h +++ b/include/deal.II/base/tensor.h @@ -291,7 +291,16 @@ public: */ template constexpr DEAL_II_HOST_DEVICE Tensor & - operator=(const OtherNumber &d); + operator=(const OtherNumber &d) &; + + /** + * Assign a scalar to the current object. This overload is used for + * rvalue references; because it does not make sense to assign + * something to a temporary, the function is deleted. + */ + template + constexpr DEAL_II_HOST_DEVICE Tensor & + operator=(const OtherNumber &d) && = delete; /** * Test for equality of two tensors. @@ -685,7 +694,15 @@ public: * t=0 to reset all elements of the tensor to zero. */ constexpr Tensor & - operator=(const Number &d); + operator=(const Number &d) &; + + /** + * Assign a scalar to the current object. This overload is used for + * rvalue references; because it does not make sense to assign + * something to a temporary, the function is deleted. + */ + constexpr DEAL_II_HOST_DEVICE Tensor & + operator=(const Number &d) && = delete; #ifdef DEAL_II_DELETED_MOVE_CONSTRUCTOR_BUG /** @@ -1095,7 +1112,7 @@ Tensor<0, dim, Number>::operator=(Tensor<0, dim, Number> &&other) noexcept template template constexpr DEAL_II_HOST_DEVICE_ALWAYS_INLINE Tensor<0, dim, Number> & -Tensor<0, dim, Number>::operator=(const OtherNumber &d) +Tensor<0, dim, Number>::operator=(const OtherNumber &d) & { value = internal::NumberType::value(d); return *this; @@ -1542,7 +1559,7 @@ Tensor::operator=(const Tensor &t) template constexpr inline DEAL_II_ALWAYS_INLINE Tensor & -Tensor::operator=(const Number &d) +Tensor::operator=(const Number &d) & { Assert(numbers::value_is_zero(d), ExcScalarAssignmentOnlyForZeroValue()); (void)d;