From: Wolfgang Bangerth Date: Sun, 5 Mar 2023 10:20:52 +0000 (-0700) Subject: Do not allow assigning to rvalue references of VectorizedArray. X-Git-Tag: v9.5.0-rc1~505^2~1 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ce4a204dccf5d706d2071b0044a75ad59ce8a189;p=dealii.git Do not allow assigning to rvalue references of VectorizedArray. --- diff --git a/include/deal.II/base/vectorization.h b/include/deal.II/base/vectorization.h index fd29a24f26..9aea1cb6a4 100644 --- a/include/deal.II/base/vectorization.h +++ b/include/deal.II/base/vectorization.h @@ -451,16 +451,24 @@ public: {} /** - * This function assigns a scalar to this class. + * This function assigns a scalar to the current object. */ DEAL_II_ALWAYS_INLINE VectorizedArray & - operator=(const Number scalar) + operator=(const Number scalar) & { data = scalar; return *this; } + /** + * 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. + */ + VectorizedArray & + operator=(const Number scalar) && = delete; + /** * Access operator (only valid with component 0 in the base class without * specialization). @@ -992,12 +1000,21 @@ public: */ DEAL_II_ALWAYS_INLINE VectorizedArray & - operator=(const double x) + operator=(const double x) & { data = _mm512_set1_pd(x); return *this; } + + /** + * 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. + */ + VectorizedArray & + operator=(const double scalar) && = delete; + /** * Access operator. */ @@ -1571,12 +1588,20 @@ public: */ DEAL_II_ALWAYS_INLINE VectorizedArray & - operator=(const float x) + operator=(const float x) & { data = _mm512_set1_ps(x); return *this; } + /** + * 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. + */ + VectorizedArray & + operator=(const float scalar) && = delete; + /** * Access operator. */ @@ -2232,12 +2257,20 @@ public: */ DEAL_II_ALWAYS_INLINE VectorizedArray & - operator=(const double x) + operator=(const double x) & { data = _mm256_set1_pd(x); return *this; } + /** + * 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. + */ + VectorizedArray & + operator=(const double scalar) && = delete; + /** * Access operator. */ @@ -2770,12 +2803,20 @@ public: */ DEAL_II_ALWAYS_INLINE VectorizedArray & - operator=(const float x) + operator=(const float x) & { data = _mm256_set1_ps(x); return *this; } + /** + * 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. + */ + VectorizedArray & + operator=(const float scalar) && = delete; + /** * Access operator. */ @@ -3328,12 +3369,20 @@ public: */ DEAL_II_ALWAYS_INLINE VectorizedArray & - operator=(const double x) + operator=(const double x) & { data = _mm_set1_pd(x); return *this; } + /** + * 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. + */ + VectorizedArray & + operator=(const double scalar) && = delete; + /** * Access operator. */ @@ -3794,12 +3843,20 @@ public: DEAL_II_ALWAYS_INLINE VectorizedArray & - operator=(const float x) + operator=(const float x) & { data = _mm_set1_ps(x); return *this; } + /** + * 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. + */ + VectorizedArray & + operator=(const float scalar) && = delete; + /** * Access operator. */ @@ -4274,11 +4331,11 @@ public: {} /** - * This function assigns a scalar to this class. + * This function assigns a scalar to the current object. */ DEAL_II_ALWAYS_INLINE VectorizedArray & - operator=(const double x) + operator=(const double x) & { data = vec_splats(x); @@ -4289,6 +4346,14 @@ public: return *this; } + /** + * 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. + */ + VectorizedArray & + operator=(const double scalar) && = delete; + /** * Access operator. The component must be either 0 or 1. */ @@ -4521,11 +4586,11 @@ public: {} /** - * This function assigns a scalar to this class. + * This function assigns a scalar to the current object. */ DEAL_II_ALWAYS_INLINE VectorizedArray & - operator=(const float x) + operator=(const float x) & { data = vec_splats(x); @@ -4536,6 +4601,14 @@ public: return *this; } + /** + * 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. + */ + VectorizedArray & + operator=(const float scalar) && = delete; + /** * Access operator. The component must be between 0 and 3. */