From 451547ef1d8c51fe1a203f26305875143f79b83e Mon Sep 17 00:00:00 2001 From: Matthias Maier Date: Sun, 6 Sep 2015 21:35:26 -0500 Subject: [PATCH] Bugfix: Dissallow access to an object of type Tensor Well, there is no sane way of accessing such an object. Unfortunately, the "degeneration" operator[](void) is not part of the C++ language... So, dissallow any access to the value but allow creation and comparison of this object... --- include/deal.II/base/tensor.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/include/deal.II/base/tensor.h b/include/deal.II/base/tensor.h index ec33830578..a1e3d6eafe 100644 --- a/include/deal.II/base/tensor.h +++ b/include/deal.II/base/tensor.h @@ -360,6 +360,8 @@ public: */ typedef typename Tensor::array_type array_type[(dim != 0) ? dim : 1]; + // ... avoid a compiler warning in case of dim == 0 and ensure that the + // array always has positive size. /** * Constructor. Initialize all entries to zero if @@ -567,6 +569,8 @@ private: * Array of tensors holding the subelements. */ Tensor values[(dim != 0) ? dim : 1]; + // ... avoid a compiler warning in case of dim == 0 and ensure that the + // array always has positive size. /** * Help function for unroll. @@ -631,6 +635,7 @@ template inline Tensor<0,dim,Number>::operator Number &() { + Assert(dim != 0, ExcMessage("Cannot access an object of type Tensor<0,0,Number>")); return value; } @@ -639,6 +644,7 @@ template inline Tensor<0,dim,Number>::operator const Number &() const { + Assert(dim != 0, ExcMessage("Cannot access an object of type Tensor<0,0,Number>")); return value; } @@ -733,6 +739,7 @@ inline typename Tensor<0,dim,Number>::real_type Tensor<0,dim,Number>::norm () const { + Assert(dim != 0, ExcMessage("Cannot access an object of type Tensor<0,0,Number>")); return numbers::NumberTraits::abs (value); } @@ -742,6 +749,7 @@ inline typename Tensor<0,dim,Number>::real_type Tensor<0,dim,Number>::norm_square () const { + Assert(dim != 0, ExcMessage("Cannot access an object of type Tensor<0,0,Number>")); return numbers::NumberTraits::abs_square (value); } @@ -753,6 +761,7 @@ void Tensor<0, dim, Number>::unroll_recursion (Vector &result, unsigned int &index) const { + Assert(dim != 0, ExcMessage("Cannot unroll an object of type Tensor<0,0,Number>")); result[index] = value; ++index; } @@ -875,6 +884,7 @@ inline typename Tensor::value_type & Tensor::operator[] (const unsigned int i) { + Assert(dim != 0, ExcMessage("Cannot access an object of type Tensor")); Assert (i::value_type & Tensor::operator[] (const unsigned int i) const { + Assert(dim != 0, ExcMessage("Cannot access an object of type Tensor")); Assert (i::operator[] (const TableIndices &indices) const { + Assert(dim != 0, ExcMessage("Cannot access an object of type Tensor")); Assert (indices[0]::extract(*this, indices); } @@ -905,6 +917,7 @@ inline Number & Tensor::operator[] (const TableIndices &indices) { + Assert(dim != 0, ExcMessage("Cannot access an object of type Tensor")); Assert (indices[0]::extract(*this, indices); } -- 2.39.5