From e5d8ddf6be0945cf108e2e36360fe7bffadef10a Mon Sep 17 00:00:00 2001 From: Sebastian Proell Date: Fri, 3 Mar 2023 15:42:06 +0100 Subject: [PATCH] SymmetricTensor access returns const reference --- include/deal.II/base/symmetric_tensor.h | 2 +- tests/tensors/symmetric_tensor_46.cc | 43 ++++++++++++++++++++++++ tests/tensors/symmetric_tensor_46.output | 2 ++ 3 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 tests/tensors/symmetric_tensor_46.cc create mode 100644 tests/tensors/symmetric_tensor_46.output diff --git a/include/deal.II/base/symmetric_tensor.h b/include/deal.II/base/symmetric_tensor.h index 4a8397a6d0..9ba9418450 100644 --- a/include/deal.II/base/symmetric_tensor.h +++ b/include/deal.II/base/symmetric_tensor.h @@ -421,7 +421,7 @@ namespace internal { using tensor_type = const ::dealii::SymmetricTensor; - using reference = Number; + using reference = const Number &; }; /** diff --git a/tests/tensors/symmetric_tensor_46.cc b/tests/tensors/symmetric_tensor_46.cc new file mode 100644 index 0000000000..a361211ae9 --- /dev/null +++ b/tests/tensors/symmetric_tensor_46.cc @@ -0,0 +1,43 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2023 by the deal.II authors +// +// This file is part of the deal.II library. +// +// The deal.II library is free software; you can use it, redistribute +// it, and/or modify it under the terms of the GNU Lesser General +// Public License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// The full text of the license can be found in the file LICENSE.md at +// the top level directory of deal.II. +// +// --------------------------------------------------------------------- + + +// Test that a const SymmetricTensor is not assignable, i.e., the accessors +// return a const reference + +#include +#include +#include + +#include "../tests.h" + +int +main() +{ + initlog(); + + { + const SymmetricTensor<2, 3, double> st{}; + static_assert(std::is_same::value); + } + + { + const SymmetricTensor<2, 3, VectorizedArray> stv{}; + static_assert(std::is_same &>::value); + } + + deallog << "OK" << std::endl; +} diff --git a/tests/tensors/symmetric_tensor_46.output b/tests/tensors/symmetric_tensor_46.output new file mode 100644 index 0000000000..0fd8fc12f0 --- /dev/null +++ b/tests/tensors/symmetric_tensor_46.output @@ -0,0 +1,2 @@ + +DEAL::OK -- 2.39.5