Subject: fix various GCC 4.7 compilation errors and warnings

 * Explicitly qualify more dependent names originating in base templates.
 * Directly #include headers as needed.
 * Use modern syntax for making protected base members public.
 * Add forward declarations as needed.

Author: Aaron M. Ucko <ucko@debian.org>
Last-Update: 2012-04-13
--- a/c++/include/connect/ncbi_conn_stream.hpp
+++ b/c++/include/connect/ncbi_conn_stream.hpp
@@ -259,7 +259,7 @@
 class CConn_IOStreamSetReadTimeout : protected CConn_IOStreamSetTimeout
 {
 public:
-    CConn_IOStreamSetTimeout::GetTimeout;
+    using CConn_IOStreamSetTimeout::GetTimeout;
 
 protected:
     CConn_IOStreamSetReadTimeout(const STimeout* timeout)
@@ -289,7 +289,7 @@
 class CConn_IOStreamSetWriteTimeout : protected CConn_IOStreamSetTimeout
 {
 public:
-    CConn_IOStreamSetTimeout::GetTimeout;
+    using CConn_IOStreamSetTimeout::GetTimeout;
 
 protected:
     CConn_IOStreamSetWriteTimeout(const STimeout* timeout)
--- a/c++/include/corelib/ncbiexpt.hpp
+++ b/c++/include/corelib/ncbiexpt.hpp
@@ -852,7 +852,7 @@
     exception_class(const exception_class& other) \
        : base_class(other) \
     { \
-        x_Assign(other); \
+        this->x_Assign(other); \
     } \
 public: \
     virtual ~exception_class(void) throw() {} \
@@ -1172,7 +1172,7 @@
         : TBase( other)
     {
         m_Errno = other.m_Errno;
-        x_Assign(other);
+        this->x_Assign(other);
     }
 
     /// Destructor.
--- a/c++/include/corelib/ncbimisc.hpp
+++ b/c++/include/corelib/ncbimisc.hpp
@@ -39,6 +39,7 @@
 #ifdef HAVE_SYS_TYPES_H
 #  include <sys/types.h>
 #endif
+#include <cstdlib>
 #ifdef NCBI_COMPILER_ICC
 // Preemptively pull in <cctype>, which breaks if we've already
 // repointed is* at NCBI_is*.
--- a/c++/include/corelib/ncbistl.hpp
+++ b/c++/include/corelib/ncbistl.hpp
@@ -37,6 +37,7 @@
 
 #include <common/ncbi_export.h>
 
+#include <algorithm>
 
 // Get rid of some warnings in MSVC++
 #if (_MSC_VER >= 1200)
--- a/c++/include/corelib/ncbistr.hpp
+++ b/c++/include/corelib/ncbistr.hpp
@@ -3039,7 +3039,7 @@
         : TBase(other)
     {
         m_Pos = other.m_Pos;
-        x_Assign(other);
+        this->x_Assign(other);
     }
 
     /// Destructor.
--- a/c++/include/serial/impl/stltypes.hpp
+++ b/c++/include/serial/impl/stltypes.hpp
@@ -412,6 +412,7 @@
     typedef StlIterator TStlIterator;
     typedef TypeInfoIterator TTypeInfoIterator;
     typedef typename TTypeInfoIterator::TObjectPtr TObjectPtr;
+    typedef CStlClassInfoFunctions<Container> CParent;
 
     static TStlIterator& It(TTypeInfoIterator& iter)
         {
@@ -437,7 +438,8 @@
         }
     static bool InitIterator(TTypeInfoIterator& iter)
         {
-            TStlIterator stl_iter = Get(iter.GetContainerPtr()).begin();
+            TStlIterator stl_iter
+                = CParent::Get(iter.GetContainerPtr()).begin();
             if ( sizeof(TStlIterator) <= sizeof(iter.m_IteratorData) ) {
                 void* data = &iter.m_IteratorData;
                 new (data) TStlIterator(stl_iter);
@@ -445,7 +447,7 @@
             else {
                 iter.m_IteratorData = new TStlIterator(stl_iter);
             }
-            return stl_iter != Get(iter.GetContainerPtr()).end();
+            return stl_iter != CParent::Get(iter.GetContainerPtr()).end();
         }
     static void ReleaseIterator(TTypeInfoIterator& iter)
         {
@@ -466,7 +468,7 @@
 
     static bool NextElement(TTypeInfoIterator& iter)
         {
-            return ++It(iter) != Get(iter.GetContainerPtr()).end();
+            return ++It(iter) != CParent::Get(iter.GetContainerPtr()).end();
         }
     static TObjectPtr GetElementPtr(const TTypeInfoIterator& iter)
         {
@@ -503,7 +505,7 @@
     
     static bool EraseElement(TTypeInfoIterator& iter)
         {
-            TStlIterator& it = It(iter);
+            TStlIterator& it = CParent::It(iter);
             Container* c = static_cast<Container*>(iter.GetContainerPtr());
             it = c->erase(it);
             return it != c->end();
@@ -511,7 +513,7 @@
     static void EraseAllElements(TTypeInfoIterator& iter)
         {
             Container* c = static_cast<Container*>(iter.GetContainerPtr());
-            c->erase(It(iter), c->end());
+            c->erase(CParent::It(iter), c->end());
         }
 
     static void SetIteratorFunctions(CStlOneArgTemplate* info)
@@ -542,7 +544,7 @@
         }
     static bool EraseElement(TTypeInfoIterator& iter)
         {
-            TStlIterator& it = It(iter);
+            TStlIterator& it = CParent::It(iter);
             Container* c = static_cast<Container*>(iter.GetContainerPtr());
             TStlIterator erase = it++;
             c->erase(erase);
@@ -551,7 +553,7 @@
     static void EraseAllElements(TTypeInfoIterator& iter)
         {
             Container* c = static_cast<Container*>(iter.GetContainerPtr());
-            c->erase(It(iter), c->end());
+            c->erase(CParent::It(iter), c->end());
         }
 
     static void SetIteratorFunctions(CStlOneArgTemplate* info)
--- a/c++/include/serial/iterator.hpp
+++ b/c++/include/serial/iterator.hpp
@@ -520,13 +520,13 @@
     CTypeIteratorBase(TTypeInfo needType, const TBeginInfo& beginInfo)
         : m_NeedType(needType)
         {
-            Init(beginInfo);
+            this->Init(beginInfo);
         }
     CTypeIteratorBase(TTypeInfo needType, const TBeginInfo& beginInfo,
                       const string& filter)
         : m_NeedType(needType)
         {
-            Init(beginInfo, filter);
+            this->Init(beginInfo, filter);
         }
 
     virtual bool CanSelect(const CConstObjectInfo& object)
--- a/c++/include/util/bitset/bmfunc.h
+++ b/c++/include/util/bitset/bmfunc.h
@@ -39,6 +39,13 @@
 namespace bm
 {
 
+bm::id_t bit_block_any_range(const bm::word_t* block,
+                             bm::word_t left,
+                             bm::word_t right);
+
+bm::id_t bit_block_calc_count_range(const bm::word_t* block,
+                                    bm::word_t left,
+                                    bm::word_t right);
 
 /*!
     @brief Structure with statistical information about bitset's memory 
--- a/c++/include/util/bitset/bmserial.h
+++ b/c++/include/util/bitset/bmserial.h
@@ -1381,7 +1381,7 @@
     case set_block_arrgap: 
     case set_block_arrgap_egamma:
         {
-        	unsigned arr_len = read_id_list(dec, btype, this->id_array_);
+            unsigned arr_len = this->read_id_list(dec, btype, this->id_array_);
             gap_len = gap_set_array(gap_temp_block_, this->id_array_, arr_len);
             break;
         }
@@ -1390,7 +1390,7 @@
             (sizeof(gap_word_t) == 2 ? dec.get_16() : dec.get_32());
     case set_block_arrgap_egamma_inv:
     case set_block_arrgap_inv:
-        gap_len = read_gap_block(dec, btype, gap_temp_block_, gap_head);
+        gap_len = this->read_gap_block(dec, btype, gap_temp_block_, gap_head);
         break;
     default:
         BM_ASSERT(0);
--- a/c++/include/util/linkedset.hpp
+++ b/c++/include/util/linkedset.hpp
@@ -268,10 +268,10 @@
             pair<iterator, bool> ins = m_Container.insert(value);
             if ( ins.second ) {
                 if ( ins.first == begin() )
-                    insertToStart(*ins.first);
+                    this->insertToStart(*ins.first);
                 else {
                     iterator prev = ins.first;
-                    insertAfter(*--prev, *ins.first);
+                    this->insertAfter(*--prev, *ins.first);
                 }
             }
             return ins;
@@ -280,10 +280,10 @@
     void erase(iterator iter)
         {
             if ( iter == begin() )
-                removeFromStart(*iter);
+                this->removeFromStart(*iter);
             else {
                 iterator prev = iter;
-                removeAfter(*--prev, *iter);
+                this->removeAfter(*--prev, *iter);
             }
             m_Container.erase(iter);
         }
@@ -422,10 +422,10 @@
         {
             iterator iter = m_Container.insert(value);
             if ( iter == begin() )
-                insertToStart(get(iter));
+                this->insertToStart(get(iter));
             else {
                 iterator prev = iter;
-                insertAfter(get(--prev), get(iter));
+                this->insertAfter(get(--prev), get(iter));
             }
             return iter;
         }
@@ -433,10 +433,10 @@
     void erase(iterator iter)
         {
             if ( iter == begin() )
-                removeFromStart(get(iter));
+                this->removeFromStart(get(iter));
             else {
                 iterator prev = iter;
-                removeAfter(get(--prev), get(iter));
+                this->removeAfter(get(--prev), get(iter));
             }
             m_Container.erase(iter);
         }
--- a/c++/include/util/rangemap.hpp
+++ b/c++/include/util/rangemap.hpp
@@ -578,7 +578,7 @@
             // get level
 
             // insert element
-            TSelectMapI selectIter = insertLevel(selectKey);
+            TSelectMapI selectIter = this->insertLevel(selectKey);
             pair<TLevelMapI, bool> levelIns = selectIter->second.insert(value);
             
             pair<iterator, bool> ret;
@@ -640,7 +640,7 @@
             // insert element
             iterator ret;
             ret.m_Range = range_type::GetWhole();
-            ret.m_SelectIter = insertLevel(selectKey);
+            ret.m_SelectIter = this->insertLevel(selectKey);
             ret.m_SelectIterEnd = this->m_SelectMap.end();
             ret.m_LevelIter = ret.m_SelectIter->second.insert(value);
             return ret;
--- a/c++/src/serial/stdtypes.cpp
+++ b/c++/src/serial/stdtypes.cpp
@@ -720,7 +720,7 @@
             if ( IsSigned() ) {
                 // signed -> unsigned
                 // check for negative value
-                if ( IsNegative(value) )
+                if ( CParent::IsNegative(value) )
                     ThrowIntegerOverflow();
             }
             if ( sizeof(value) > sizeof(result) ) {
@@ -751,7 +751,7 @@
                 // unsigned -> signed
                 if ( sizeof(value) == sizeof(result) ) {
                     // same size - check for sign change only
-                    if ( IsNegative(result) )
+                    if ( CParent::IsNegative(result) )
                         ThrowIntegerOverflow();
                 }
             }
@@ -786,7 +786,7 @@
             if ( IsSigned() ) {
                 // signed -> unsigned
                 // check for negative value
-                if ( IsNegative(value) )
+                if ( CParent::IsNegative(value) )
                     ThrowIntegerOverflow();
             }
             if ( sizeof(value) > sizeof(result) ) {
@@ -817,7 +817,7 @@
                 // unsigned -> signed
                 if ( sizeof(value) == sizeof(result) ) {
                     // same size - check for sign change only
-                    if ( IsNegative(result) )
+                    if ( CParent::IsNegative(result) )
                         ThrowIntegerOverflow();
                 }
             }
