From 9aeb308aacfc779d2d8e0dada764481b1dc713cd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Christoph=20Gr=C3=BCninger?= <gruenich@dune-project.org>
Date: Thu, 10 Dec 2015 22:29:38 +0000
Subject: [PATCH] Merge branch 'feature/fix-shadow-warnings' into 'master'
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Feature/fix shadow warnings

If you have better name suggestions, please tell me and I change the names.

See merge request !21
(cherry picked from commit 394c5cde319282c53adff8b65788a8d995e2aff5)

Signed-off-by: Steffen Müthing <muething@dune-project.org>
---
 dune/common/bitsetvector.hh           | 16 ++++++++--------
 dune/common/parallel/communicator.hh  |  8 ++++----
 dune/common/parallel/indicessyncer.hh | 18 +++++++++---------
 dune/common/parallel/remoteindices.hh | 15 ++++++---------
 dune/common/test/dynmatrixtest.cc     | 10 +++++-----
 dune/common/test/fmatrixtest.cc       | 18 +++++++++---------
 dune/common/test/iteratortest.hh      |  6 ++++--
 dune/common/test/shared_ptrtest.cc    | 22 +++++++++++-----------
 8 files changed, 56 insertions(+), 57 deletions(-)

diff --git a/dune/common/bitsetvector.hh b/dune/common/bitsetvector.hh
index 3215b7b93..4fef17db0 100644
--- a/dune/common/bitsetvector.hh
+++ b/dune/common/bitsetvector.hh
@@ -38,10 +38,10 @@ namespace Dune {
     typedef Dune::BitSetVector<block_size, Alloc> BitSetVector;
     friend class Dune::BitSetVector<block_size, Alloc>;
 
-    BitSetVectorConstReference(const BitSetVector& blockBitField, int block_number) :
-      blockBitField(blockBitField),
-      block_number(block_number)
-    {};
+    BitSetVectorConstReference(const BitSetVector& blockBitField_, int block_number_) :
+      blockBitField(blockBitField_),
+      block_number(block_number_)
+    {}
 
     //! hide assignment operator
     BitSetVectorConstReference& operator=(const BitSetVectorConstReference & b);
@@ -212,10 +212,10 @@ namespace Dune {
 
     typedef Dune::BitSetVectorConstReference<block_size,Alloc> BitSetVectorConstReference;
 
-    BitSetVectorReference(BitSetVector& blockBitField, int block_number) :
-      BitSetVectorConstReference(blockBitField, block_number),
-      blockBitField(blockBitField)
-    {};
+    BitSetVectorReference(BitSetVector& blockBitField_, int block_number_) :
+      BitSetVectorConstReference(blockBitField_, block_number_),
+      blockBitField(blockBitField_)
+    {}
 
   public:
     typedef std::bitset<block_size> bitset;
diff --git a/dune/common/parallel/communicator.hh b/dune/common/parallel/communicator.hh
index f8654cf81..d5225807c 100644
--- a/dune/common/parallel/communicator.hh
+++ b/dune/common/parallel/communicator.hh
@@ -1095,8 +1095,8 @@ namespace Dune
           int messageLength;
           MPI_Error_string(status[i].MPI_ERROR, message, &messageLength);
           std::cerr<<" source="<<status[i].MPI_SOURCE<<" message: ";
-          for(int i=0; i< messageLength; i++)
-            std::cout<<message[i];
+          for(int j = 0; j < messageLength; j++)
+            std::cout << message[j];
         }
       std::cerr<<std::endl;
       success=0;
@@ -1113,8 +1113,8 @@ namespace Dune
           int messageLength;
           MPI_Error_string(status[i].MPI_ERROR, message, &messageLength);
           std::cerr<<" source="<<status[i].MPI_SOURCE<<" message: ";
-          for(int i=0; i< messageLength; i++)
-            std::cerr<<message[i];
+          for(int j = 0; j < messageLength; j++)
+            std::cerr << message[j];
         }
       std::cerr<<std::endl;
       success=0;
diff --git a/dune/common/parallel/indicessyncer.hh b/dune/common/parallel/indicessyncer.hh
index 2479ce922..23e7e22fb 100644
--- a/dune/common/parallel/indicessyncer.hh
+++ b/dune/common/parallel/indicessyncer.hh
@@ -776,13 +776,13 @@ namespace Dune
     std::size_t noOldNeighbours = remoteIndices_.neighbours();
     int* oldNeighbours = new int[noOldNeighbours];
     sendBufferSizes_ = new std::size_t[noOldNeighbours];
-    std::size_t i=0;
+    std::size_t neighbourI = 0;
 
-    for(RemoteIterator remote = remoteIndices_.begin(); remote != end; ++remote, ++i) {
+    for(RemoteIterator remote = remoteIndices_.begin(); remote != end; ++remote, ++neighbourI) {
       typedef typename RemoteIndices::RemoteIndexList::const_iterator
       RemoteIndexIterator;
 
-      oldNeighbours[i]=remote->first;
+      oldNeighbours[neighbourI] = remote->first;
 
       // Make sure we only have one remote index list.
       assert(remote->second.first==remote->second.second);
@@ -824,7 +824,7 @@ namespace Dune
 
     Dune::dverb<<rank_<<": Neighbours: ";
 
-    for(i = 0; i<noOldNeighbours; ++i)
+    for(std::size_t i = 0; i<noOldNeighbours; ++i)
       Dune::dverb<<oldNeighbours[i]<<" ";
 
     Dune::dverb<<std::endl;
@@ -833,11 +833,11 @@ namespace Dune
     MPI_Status* statuses = new MPI_Status[noOldNeighbours];
 
     // Pack Message data and start the sends
-    for(i = 0; i<noOldNeighbours; ++i)
+    for(std::size_t i = 0; i<noOldNeighbours; ++i)
       packAndSend(oldNeighbours[i], sendBuffers_[i], sendBufferSizes_[i], requests[i]);
 
     // Probe for incoming messages, receive and unpack them
-    for(i = 0; i<noOldNeighbours; ++i)
+    for(std::size_t i = 0; i<noOldNeighbours; ++i)
       recvAndUnpack(numberer);
     //       }else{
     //  recvAndUnpack(oldNeighbours[i], numberer);
@@ -851,7 +851,7 @@ namespace Dune
     // Wait for completion of sends
     if(MPI_SUCCESS!=MPI_Waitall(noOldNeighbours, requests, statuses)) {
       std::cerr<<": MPI_Error occurred while sending message"<<std::endl;
-      for(i=0; i< noOldNeighbours; i++)
+      for(std::size_t i=0; i< noOldNeighbours; i++)
         if(MPI_SUCCESS!=statuses[i].MPI_ERROR)
           std::cerr<<"Destination "<<statuses[i].MPI_SOURCE<<" error code: "<<statuses[i].MPI_ERROR<<std::endl;
     }
@@ -961,9 +961,9 @@ namespace Dune
           assert(pairs <= infoSend_[destination].pairs);
           MPI_Pack(&process, 1, MPI_INT, buffer, bufferSize, &bpos,
                    remoteIndices_.communicator());
-          char attr = iterators->second.remoteIndex().attribute();
+          char attr2 = iterators->second.remoteIndex().attribute();
 
-          MPI_Pack(&attr, 1, MPI_CHAR, buffer, bufferSize, &bpos,
+          MPI_Pack(&attr2, 1, MPI_CHAR, buffer, bufferSize, &bpos,
                    remoteIndices_.communicator());
           --indices;
         }
diff --git a/dune/common/parallel/remoteindices.hh b/dune/common/parallel/remoteindices.hh
index e47cad69d..bf5c43fcb 100644
--- a/dune/common/parallel/remoteindices.hh
+++ b/dune/common/parallel/remoteindices.hh
@@ -1120,7 +1120,7 @@ namespace Dune {
 
   template<typename T, typename A>
   template<bool ignorePublic>
-  inline void RemoteIndices<T,A>::buildRemote(bool includeSelf)
+  inline void RemoteIndices<T,A>::buildRemote(bool includeSelf_)
   {
     // Processor configuration
     int rank, procs;
@@ -1134,7 +1134,7 @@ namespace Dune {
     // Do we need to send two index sets?
     char sendTwo = (source_ != target_);
 
-    if(procs==1 && !(sendTwo || includeSelf))
+    if(procs==1 && !(sendTwo || includeSelf_))
       // Nothing to communicate
       return;
 
@@ -1209,9 +1209,9 @@ namespace Dune {
 
 
     // Update remote indices for ourself
-    if(sendTwo|| includeSelf)
+    if(sendTwo|| includeSelf_)
       unpackCreateRemote(buffer[0], sourcePairs, destPairs, rank, sourcePublish,
-                         destPublish, bufferSize, sendTwo, includeSelf);
+                         destPublish, bufferSize, sendTwo, includeSelf_);
 
     neighbourIds.erase(rank);
 
@@ -1866,11 +1866,8 @@ namespace Dune {
       if(!rindex->second.second->empty()) {
         os<<rank<<": Prozess "<<rindex->first<<": "<<"receive: ";
 
-        const typename RList::const_iterator rend= rindex->second.second->end();
-
-        for(typename RList::const_iterator index = rindex->second.second->begin();
-            index != rend; ++index)
-          os<<*index<<" ";
+        for(const auto& index : *(rindex->second.second))
+          os << index << " ";
       }
       os<<std::endl<<std::flush;
     }
diff --git a/dune/common/test/dynmatrixtest.cc b/dune/common/test/dynmatrixtest.cc
index 3fc536ea8..5cfac028a 100644
--- a/dune/common/test/dynmatrixtest.cc
+++ b/dune/common/test/dynmatrixtest.cc
@@ -300,11 +300,11 @@ void test_matrix()
       DUNE_THROW(FMatrixError,"Axpy test failed!");
   }
   {
-    DynamicMatrix<K> A(n,n+1);
-    for(size_type i=0; i<A.N(); ++i)
-      for(size_type j=0; j<A.M(); ++j)
-        A[i][j] = i;
-    const DynamicMatrix<K>& Aref DUNE_UNUSED = A;
+    DynamicMatrix<K> A2(n,n+1);
+    for(size_type i=0; i<A2.N(); ++i)
+      for(size_type j=0; j<A2.M(); ++j)
+        A2[i][j] = i;
+    const DynamicMatrix<K>& Aref DUNE_UNUSED = A2;
 
 
     DynamicMatrix<K> B(n+1,n+1);
diff --git a/dune/common/test/fmatrixtest.cc b/dune/common/test/fmatrixtest.cc
index 31f8d3e8f..ff20aa643 100644
--- a/dune/common/test/fmatrixtest.cc
+++ b/dune/common/test/fmatrixtest.cc
@@ -294,11 +294,11 @@ void test_matrix()
       DUNE_THROW(FMatrixError,"Axpy test failed!");
   }
   {
-    FieldMatrix<K,n,n+1> A;
-    for(size_type i=0; i<A.N(); ++i)
-      for(size_type j=0; j<A.M(); ++j)
-        A[i][j] = i;
-    const FieldMatrix<K,n,n+1>& Aref = A;
+    FieldMatrix<K,n,n+1> A2;
+    for(size_type i=0; i<A2.N(); ++i)
+      for(size_type j=0; j<A2.M(); ++j)
+        A2[i][j] = i;
+    const FieldMatrix<K,n,n+1>& Aref = A2;
 
 
     FieldMatrix<K,n+1,n+1> B;
@@ -319,13 +319,13 @@ void test_matrix()
         if (std::abs(AB[i][j] - K(i*n*(n+1)/2)) > 1e-10)
           DUNE_THROW(FMatrixError,"Rightmultiplyany test failed!");
 
-    FieldMatrix<K,n,n+1> AB2 = A;
+    FieldMatrix<K,n,n+1> AB2 = A2;
     AB2.rightmultiply(B);
     AB2 -= AB;
     if (std::abs(AB2.infinity_norm()) > 1e-10)
       DUNE_THROW(FMatrixError,"Rightmultiply test failed!");
 
-    FieldMatrix<K,n,n+1> AB3 = Bref.leftmultiplyany(A);
+    FieldMatrix<K,n,n+1> AB3 = Bref.leftmultiplyany(A2);
     AB3 -= AB;
     if (std::abs(AB3.infinity_norm()) > 1e-10)
       DUNE_THROW(FMatrixError,"Leftmultiplyany test failed!");
@@ -336,13 +336,13 @@ void test_matrix()
         if (std::abs(CA[i][j] - K(i*n*(n-1)/2)) > 1e-10)
           DUNE_THROW(FMatrixError,"Leftmultiplyany test failed!");
 
-    FieldMatrix<K,n,n+1> CA2 = A;
+    FieldMatrix<K,n,n+1> CA2 = A2;
     CA2.leftmultiply(C);
     CA2 -= CA;
     if (std::abs(CA2.infinity_norm()) > 1e-10)
       DUNE_THROW(FMatrixError,"Leftmultiply test failed!");
 
-    FieldMatrix<K,n,n+1> CA3 = Cref.rightmultiplyany(A);
+    FieldMatrix<K,n,n+1> CA3 = Cref.rightmultiplyany(A2);
     CA3 -= CA;
     if (std::abs(CA3.infinity_norm()) > 1e-10)
       DUNE_THROW(FMatrixError,"Rightmultiplyany test failed!");
diff --git a/dune/common/test/iteratortest.hh b/dune/common/test/iteratortest.hh
index 9f101b2ba..5fd9913c5 100644
--- a/dune/common/test/iteratortest.hh
+++ b/dune/common/test/iteratortest.hh
@@ -177,7 +177,8 @@ int testRandomAccessIterator(Iter begin, Iter end, Opt opt){
                 <<"iterator and n is the difference type!" <<std::endl;
       ret++;
     }
-    for(int i=0; i< index; i++) ++test;
+    for(int j = 0; j < index; j++)
+      ++test;
 
     if(test != rand)
     {
@@ -196,7 +197,8 @@ int testRandomAccessIterator(Iter begin, Iter end, Opt opt){
                 <<"iterator and n is the difference type!" <<std::endl;
       ret++;
     }
-    for(int i=0; i< index; i++) --test;
+    for(int j = 0; j < index; j++)
+      --test;
 
     if(test != rand)
     {
diff --git a/dune/common/test/shared_ptrtest.cc b/dune/common/test/shared_ptrtest.cc
index 3b936754e..91b6d0227 100644
--- a/dune/common/test/shared_ptrtest.cc
+++ b/dune/common/test/shared_ptrtest.cc
@@ -96,11 +96,11 @@ int main(){
     // test custom deleter
     bool deleted = false;
     {
-      shared_ptr<int> foo(new int(1), Deleter<int>(deleted));
+      shared_ptr<int> bar(new int(1), Deleter<int>(deleted));
 
       //test if deleter is called
       deleted = false;
-      foo.reset(new int(2));        // this should call the deleter in the constructor
+      bar.reset(new int(2));        // this should call the deleter in the constructor
       if (not (deleted))
       {
         std::cout << "Custom deleter not called!" << std::endl;
@@ -109,7 +109,7 @@ int main(){
 
       //test if old deleter is not called
       deleted = false;
-      foo.reset();        // this should call no deleter
+      bar.reset();        // this should call no deleter
       if (deleted)
       {
         std::cout << "Old deleter was called!" << std::endl;
@@ -118,7 +118,7 @@ int main(){
 
       //test if old deleter is not called
       deleted = false;
-      foo.reset(new int(3), Deleter<int>(deleted));        // this should call no deleter
+      bar.reset(new int(3), Deleter<int>(deleted));        // this should call no deleter
       if (deleted)
       {
         std::cout << "Old deleter was called!" << std::endl;
@@ -132,9 +132,9 @@ int main(){
       ret=1;
     }
     {
-      shared_ptr<int> foo(new int(1), Deleter<int>(deleted));
+      shared_ptr<int> bar(new int(1), Deleter<int>(deleted));
 
-      foo.reset(new int(4));        // this should call the deleter...
+      bar.reset(new int(4));        // this should call the deleter...
 
       deleted = false;
       // ... but going out of scope should call no deleter
@@ -219,10 +219,10 @@ int main(){
     // test assignment from null ptr
     // (should trigger FS 936, needs valgrind to check)
     {
-      shared_ptr<int> foo = shared_ptr<int>(new int(42));
-      shared_ptr<int> bar;        //null ptr
+      shared_ptr<int> foobar = shared_ptr<int>(new int(42));
+      shared_ptr<int> foobaz;        //null ptr
 
-      foo = bar;        // should release memory held by foo
+      foobar = foobaz;        // should release memory held by foo
     }
 
     // test shared_ptr for stack allocation
@@ -233,8 +233,8 @@ int main(){
 
     // test shared_ptr for stack allocation with down cast
     {
-      B b;
-      shared_ptr<A> pa = stackobject_to_shared_ptr<A>(b);
+      B b2;
+      shared_ptr<A> pa = stackobject_to_shared_ptr<A>(b2);
 #ifdef SHARED_PTR_COMPILE_FAIL
       C c;
       pa = stackobject_to_shared_ptr<A>(c);       // A is an inaccessible base of C
-- 
GitLab