From c5e023c5fb2e8cf6ac6c48f85391399d4358a965 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carsten=20Gr=C3=A4ser?= <graeser@dune-project.org>
Date: Wed, 19 Oct 2016 23:38:46 +0200
Subject: [PATCH] Remove unused methods based on unsave casts

These constructors and assignments from base class are
all using a downcast which may result in undefined behaviour.
Since this is potentially dangerous and not used anywhere
in the core modules, this patch removes those methods.
---
 dune/istl/basearray.hh | 27 ----------------
 dune/istl/bvector.hh   | 70 ------------------------------------------
 2 files changed, 97 deletions(-)

diff --git a/dune/istl/basearray.hh b/dune/istl/basearray.hh
index 8cdccd5ee..bc0d8a3ca 100644
--- a/dune/istl/basearray.hh
+++ b/dune/istl/basearray.hh
@@ -426,27 +426,6 @@ namespace Dune {
       for (size_type i=0; i<this->n; i++) this->p[i]=a.p[i];
     }
 
-    //! construct from base class object
-    base_array (const base_array_unmanaged<B,A>& _a)
-    {
-      const base_array& a = static_cast<const base_array&>(_a);
-
-      // allocate memory with same size as a
-      this->n = a.n;
-      if (this->n>0) {
-        this->p = allocator_.allocate(this->n);
-        new (this->p)B[this->n];
-      } else
-      {
-        this->n = 0;
-        this->p = 0;
-      }
-
-      // and copy elements
-      for (size_type i=0; i<this->n; i++) this->p[i]=a.p[i];
-    }
-
-
     //! free dynamic memory
     ~base_array ()
     {
@@ -510,12 +489,6 @@ namespace Dune {
       return *this;
     }
 
-    //! assign from base class object
-    base_array& operator= (const base_array_unmanaged<B,A>& a)
-    {
-      return this->operator=(static_cast<const base_array&>(a));
-    }
-
   protected:
 
     A allocator_;
diff --git a/dune/istl/bvector.hh b/dune/istl/bvector.hh
index cd988809b..4079bef4c 100644
--- a/dune/istl/bvector.hh
+++ b/dune/istl/bvector.hh
@@ -524,30 +524,6 @@ namespace Dune {
       for (size_type i=0; i<this->n; i++) this->p[i]=a.p[i];
     }
 
-    //! construct from base class object
-    BlockVector (const block_vector_unmanaged<B,A>& _a)
-    {
-      // upcast, because protected data inaccessible
-      const BlockVector& a = static_cast<const BlockVector&>(_a);
-
-      // allocate memory with same size as a
-      this->n = a.n;
-      capacity_ = a.capacity_;
-
-      if (capacity_>0) {
-        this->p = this->allocator_.allocate(capacity_);
-        new (this->p)B[capacity_];
-      } else
-      {
-        this->n = 0;
-        this->p = 0;
-        capacity_ = 0;
-      }
-
-      // and copy elements
-      for (size_type i=0; i<this->n; i++) this->p[i]=a.p[i];
-    }
-
     //! free dynamic memory
     ~BlockVector ()
     {
@@ -591,13 +567,6 @@ namespace Dune {
       return *this;
     }
 
-    //! assign from base class object
-    BlockVector& operator= (const block_vector_unmanaged<B,A>& a)
-    {
-      // forward to regular assignement operator
-      return this->operator=(static_cast<const BlockVector&>(a));
-    }
-
     //! assign from scalar
     BlockVector& operator= (const field_type& k)
     {
@@ -706,18 +675,6 @@ namespace Dune {
       this->p = a.p;
     }
 
-    //! construct from base class object with reference semantics!
-    BlockVectorWindow (const block_vector_unmanaged<B,A>& _a)
-    {
-      // cast needed to access protected data
-      const BlockVectorWindow& a = static_cast<const BlockVectorWindow&>(_a);
-
-      // make me point to the other's data
-      this->n = a.n;
-      this->p = a.p;
-    }
-
-
     //! assignment
     BlockVectorWindow& operator= (const BlockVectorWindow& a)
     {
@@ -734,13 +691,6 @@ namespace Dune {
       return *this;
     }
 
-    //! assign from base class object
-    BlockVectorWindow& operator= (const block_vector_unmanaged<B,A>& a)
-    {
-      // forward to regular assignment operator
-      return this->operator=(static_cast<const BlockVectorWindow&>(a));
-    }
-
     //! assign from scalar
     BlockVectorWindow& operator= (const field_type& k)
     {
@@ -1098,19 +1048,6 @@ namespace Dune {
       this->j = a.j;
     }
 
-    //! construct from base class object with reference semantics!
-    CompressedBlockVectorWindow (const compressed_block_vector_unmanaged<B,A>& _a)
-    {
-      // cast needed to access protected data (downcast)
-      const CompressedBlockVectorWindow& a = static_cast<const CompressedBlockVectorWindow&>(_a);
-
-      // make me point to the other's data
-      this->n = a.n;
-      this->p = a.p;
-      this->j = a.j;
-    }
-
-
     //! assignment
     CompressedBlockVectorWindow& operator= (const CompressedBlockVectorWindow& a)
     {
@@ -1128,13 +1065,6 @@ namespace Dune {
       return *this;
     }
 
-    //! assign from base class object
-    CompressedBlockVectorWindow& operator= (const compressed_block_vector_unmanaged<B,A>& a)
-    {
-      // forward to regular assignment operator
-      return this->operator=(static_cast<const CompressedBlockVectorWindow&>(a));
-    }
-
     //! assign from scalar
     CompressedBlockVectorWindow& operator= (const field_type& k)
     {
-- 
GitLab