[libcxx] r261419 - Remove all usages of "const" node pointer typedefs in the assoc containers.

Eric Fiselier via cfe-commits cfe-commits at lists.llvm.org
Fri Feb 19 23:12:18 PST 2016


Author: ericwf
Date: Sat Feb 20 01:12:17 2016
New Revision: 261419

URL: http://llvm.org/viewvc/llvm-project?rev=261419&view=rev
Log:
Remove all usages of "const" node pointer typedefs in the assoc containers.

The "const" pointer typedefs such as "__node_const_pointer" and
"__node_base_const_pointer" are identical to their non-const pointer types.
This patch changes all usages of "const" pointer type names to their respective
non-const typedef.

Since "fancy pointers to const" cannot be converted back to a non-const pointer
type according to the allocator requirements it is important that we never
actually use "const" pointers.

Furthermore since "__node_const_pointer" and "__node_pointer" already
name the same type, it's very confusing to use both names. Especially
when defining const/non-const overloads for member functions.

Modified:
    libcxx/trunk/include/__tree
    libcxx/trunk/include/map
    libcxx/trunk/test/libcxx/test/config.py

Modified: libcxx/trunk/include/__tree
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__tree?rev=261419&r1=261418&r2=261419&view=diff
==============================================================================
--- libcxx/trunk/include/__tree (original)
+++ libcxx/trunk/include/__tree Sat Feb 20 01:12:17 2016
@@ -854,15 +854,12 @@ public:
 
     typedef typename _NodeTypes::__node_type           __node;
     typedef typename _NodeTypes::__node_pointer        __node_pointer;
-    typedef typename _NodeTypes::__node_pointer        __node_const_pointer;
 
     typedef typename _NodeTypes::__node_base_type      __node_base;
     typedef typename _NodeTypes::__node_base_pointer   __node_base_pointer;
-    typedef typename _NodeTypes::__node_base_pointer   __node_base_const_pointer;
 
     typedef typename _NodeTypes::__end_node_type       __end_node_t;
     typedef typename _NodeTypes::__end_node_pointer    __end_node_ptr;
-    typedef typename _NodeTypes::__end_node_pointer    __end_node_const_ptr;
 
     typedef typename __rebind_alloc_helper<__alloc_traits, __node>::type __node_allocator;
     typedef allocator_traits<__node_allocator>         __node_traits;
@@ -880,7 +877,7 @@ private:
                  "Allocator does not rebind pointers in a sane manner.");
 
 private:
-    __node_pointer                                          __begin_node_;
+    __node_pointer                                     __begin_node_;
     __compressed_pair<__end_node_t, __node_allocator>  __pair1_;
     __compressed_pair<size_type, value_compare>        __pair3_;
 
@@ -888,18 +885,18 @@ public:
     _LIBCPP_INLINE_VISIBILITY
     __node_pointer __end_node() _NOEXCEPT
     {
-        return static_cast<__node_pointer>
-               (
-                   pointer_traits<__end_node_ptr>::pointer_to(__pair1_.first())
-               );
+        return static_cast<__node_pointer>(
+                pointer_traits<__end_node_ptr>::pointer_to(__pair1_.first())
+        );
     }
     _LIBCPP_INLINE_VISIBILITY
-    __node_const_pointer __end_node() const _NOEXCEPT
-    {
-        return static_cast<__node_const_pointer>
-               (
-                   pointer_traits<__end_node_const_ptr>::pointer_to(const_cast<__end_node_t&>(__pair1_.first()))
-               );
+    __node_pointer __end_node() const _NOEXCEPT
+    {
+        return static_cast<__node_pointer>(
+            pointer_traits<__end_node_ptr>::pointer_to(
+                const_cast<__end_node_t&>(__pair1_.first())
+            )
+        );
     }
     _LIBCPP_INLINE_VISIBILITY
           __node_allocator& __node_alloc() _NOEXCEPT {return __pair1_.second();}
@@ -927,12 +924,10 @@ public:
     const value_compare& value_comp() const _NOEXCEPT
         {return __pair3_.second();}
 public:
+
     _LIBCPP_INLINE_VISIBILITY
-    __node_pointer __root() _NOEXCEPT
-        {return static_cast<__node_pointer>      (__end_node()->__left_);}
-    _LIBCPP_INLINE_VISIBILITY
-    __node_const_pointer __root() const _NOEXCEPT
-        {return static_cast<__node_const_pointer>(__end_node()->__left_);}
+    __node_pointer __root() const _NOEXCEPT
+        {return static_cast<__node_pointer>(__end_node()->__left_);}
 
     typedef __tree_iterator<value_type, __node_pointer, difference_type>             iterator;
     typedef __tree_const_iterator<value_type, __node_pointer, difference_type> const_iterator;
@@ -1069,8 +1064,8 @@ public:
             {return __lower_bound(__v, __root(), __end_node());}
     template <class _Key>
         const_iterator __lower_bound(const _Key& __v,
-                                     __node_const_pointer __root,
-                                     __node_const_pointer __result) const;
+                                     __node_pointer __root,
+                                     __node_pointer __result) const;
     template <class _Key>
         _LIBCPP_INLINE_VISIBILITY
         iterator upper_bound(const _Key& __v)
@@ -1085,8 +1080,8 @@ public:
             {return __upper_bound(__v, __root(), __end_node());}
     template <class _Key>
         const_iterator __upper_bound(const _Key& __v,
-                                     __node_const_pointer __root,
-                                     __node_const_pointer __result) const;
+                                     __node_pointer __root,
+                                     __node_pointer __result) const;
     template <class _Key>
         pair<iterator, iterator>
         __equal_range_unique(const _Key& __k);
@@ -2142,17 +2137,17 @@ template <class _Key>
 typename __tree<_Tp, _Compare, _Allocator>::size_type
 __tree<_Tp, _Compare, _Allocator>::__count_unique(const _Key& __k) const
 {
-    __node_const_pointer __result = __end_node();
-    __node_const_pointer __rt = __root();
+    __node_pointer __result = __end_node();
+    __node_pointer __rt = __root();
     while (__rt != nullptr)
     {
         if (value_comp()(__k, __rt->__value_))
         {
             __result = __rt;
-            __rt = static_cast<__node_const_pointer>(__rt->__left_);
+            __rt = static_cast<__node_pointer>(__rt->__left_);
         }
         else if (value_comp()(__rt->__value_, __k))
-            __rt = static_cast<__node_const_pointer>(__rt->__right_);
+            __rt = static_cast<__node_pointer>(__rt->__right_);
         else
             return 1;
     }
@@ -2164,21 +2159,21 @@ template <class _Key>
 typename __tree<_Tp, _Compare, _Allocator>::size_type
 __tree<_Tp, _Compare, _Allocator>::__count_multi(const _Key& __k) const
 {
-    __node_const_pointer __result = __end_node();
-    __node_const_pointer __rt = __root();
+    __node_pointer __result = __end_node();
+    __node_pointer __rt = __root();
     while (__rt != nullptr)
     {
         if (value_comp()(__k, __rt->__value_))
         {
             __result = __rt;
-            __rt = static_cast<__node_const_pointer>(__rt->__left_);
+            __rt = static_cast<__node_pointer>(__rt->__left_);
         }
         else if (value_comp()(__rt->__value_, __k))
-            __rt = static_cast<__node_const_pointer>(__rt->__right_);
+            __rt = static_cast<__node_pointer>(__rt->__right_);
         else
             return _VSTD::distance(
-                __lower_bound(__k, static_cast<__node_const_pointer>(__rt->__left_), __rt),
-                __upper_bound(__k, static_cast<__node_const_pointer>(__rt->__right_), __result)
+                __lower_bound(__k, static_cast<__node_pointer>(__rt->__left_), __rt),
+                __upper_bound(__k, static_cast<__node_pointer>(__rt->__right_), __result)
             );
     }
     return 0;
@@ -2208,18 +2203,18 @@ template <class _Tp, class _Compare, cla
 template <class _Key>
 typename __tree<_Tp, _Compare, _Allocator>::const_iterator
 __tree<_Tp, _Compare, _Allocator>::__lower_bound(const _Key& __v,
-                                                 __node_const_pointer __root,
-                                                 __node_const_pointer __result) const
+                                                 __node_pointer __root,
+                                                 __node_pointer __result) const
 {
     while (__root != nullptr)
     {
         if (!value_comp()(__root->__value_, __v))
         {
             __result = __root;
-            __root = static_cast<__node_const_pointer>(__root->__left_);
+            __root = static_cast<__node_pointer>(__root->__left_);
         }
         else
-            __root = static_cast<__node_const_pointer>(__root->__right_);
+            __root = static_cast<__node_pointer>(__root->__right_);
     }
     return const_iterator(__result);
 }
@@ -2248,18 +2243,18 @@ template <class _Tp, class _Compare, cla
 template <class _Key>
 typename __tree<_Tp, _Compare, _Allocator>::const_iterator
 __tree<_Tp, _Compare, _Allocator>::__upper_bound(const _Key& __v,
-                                                 __node_const_pointer __root,
-                                                 __node_const_pointer __result) const
+                                                 __node_pointer __root,
+                                                 __node_pointer __result) const
 {
     while (__root != nullptr)
     {
         if (value_comp()(__v, __root->__value_))
         {
             __result = __root;
-            __root = static_cast<__node_const_pointer>(__root->__left_);
+            __root = static_cast<__node_pointer>(__root->__left_);
         }
         else
-            __root = static_cast<__node_const_pointer>(__root->__right_);
+            __root = static_cast<__node_pointer>(__root->__right_);
     }
     return const_iterator(__result);
 }
@@ -2299,22 +2294,22 @@ pair<typename __tree<_Tp, _Compare, _All
 __tree<_Tp, _Compare, _Allocator>::__equal_range_unique(const _Key& __k) const
 {
     typedef pair<const_iterator, const_iterator> _Pp;
-    __node_const_pointer __result = __end_node();
-    __node_const_pointer __rt = __root();
+    __node_pointer __result = __end_node();
+    __node_pointer __rt = __root();
     while (__rt != nullptr)
     {
         if (value_comp()(__k, __rt->__value_))
         {
             __result = __rt;
-            __rt = static_cast<__node_const_pointer>(__rt->__left_);
+            __rt = static_cast<__node_pointer>(__rt->__left_);
         }
         else if (value_comp()(__rt->__value_, __k))
-            __rt = static_cast<__node_const_pointer>(__rt->__right_);
+            __rt = static_cast<__node_pointer>(__rt->__right_);
         else
             return _Pp(const_iterator(__rt),
                       const_iterator(
                           __rt->__right_ != nullptr ?
-                              static_cast<__node_const_pointer>(__tree_min(__rt->__right_))
+                              static_cast<__node_pointer>(__tree_min(__rt->__right_))
                             : __result));
     }
     return _Pp(const_iterator(__result), const_iterator(__result));
@@ -2352,20 +2347,20 @@ pair<typename __tree<_Tp, _Compare, _All
 __tree<_Tp, _Compare, _Allocator>::__equal_range_multi(const _Key& __k) const
 {
     typedef pair<const_iterator, const_iterator> _Pp;
-    __node_const_pointer __result = __end_node();
-    __node_const_pointer __rt = __root();
+    __node_pointer __result = __end_node();
+    __node_pointer __rt = __root();
     while (__rt != nullptr)
     {
         if (value_comp()(__k, __rt->__value_))
         {
             __result = __rt;
-            __rt = static_cast<__node_const_pointer>(__rt->__left_);
+            __rt = static_cast<__node_pointer>(__rt->__left_);
         }
         else if (value_comp()(__rt->__value_, __k))
-            __rt = static_cast<__node_const_pointer>(__rt->__right_);
+            __rt = static_cast<__node_pointer>(__rt->__right_);
         else
-            return _Pp(__lower_bound(__k, static_cast<__node_const_pointer>(__rt->__left_), __rt),
-                      __upper_bound(__k, static_cast<__node_const_pointer>(__rt->__right_), __result));
+            return _Pp(__lower_bound(__k, static_cast<__node_pointer>(__rt->__left_), __rt),
+                      __upper_bound(__k, static_cast<__node_pointer>(__rt->__right_), __result));
     }
     return _Pp(const_iterator(__result), const_iterator(__result));
 }

Modified: libcxx/trunk/include/map
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/map?rev=261419&r1=261418&r2=261419&view=diff
==============================================================================
--- libcxx/trunk/include/map (original)
+++ libcxx/trunk/include/map Sat Feb 20 01:12:17 2016
@@ -1326,9 +1326,8 @@ private:
     typedef typename __base::__node                    __node;
     typedef typename __base::__node_allocator          __node_allocator;
     typedef typename __base::__node_pointer            __node_pointer;
-    typedef typename __base::__node_const_pointer      __node_const_pointer;
     typedef typename __base::__node_base_pointer       __node_base_pointer;
-    typedef typename __base::__node_base_const_pointer __node_base_const_pointer;
+
     typedef __map_node_destructor<__node_allocator> _Dp;
     typedef unique_ptr<__node, _Dp> __node_holder;
 
@@ -1344,67 +1343,29 @@ private:
 #endif
     __node_holder __construct_node_with_key(const key_type& __k);
 
+    __node_base_pointer const&
+    __find_equal_key(__node_base_pointer& __parent, const key_type& __k) const;
+
+    _LIBCPP_INLINE_VISIBILITY
     __node_base_pointer&
-        __find_equal_key(__node_base_pointer& __parent, const key_type& __k);
-    __node_base_const_pointer
-        __find_equal_key(__node_base_const_pointer& __parent, const key_type& __k) const;
+    __find_equal_key(__node_base_pointer& __parent, const key_type& __k) {
+        map const* __const_this = this;
+        return const_cast<__node_base_pointer&>(
+            __const_this->__find_equal_key(__parent, __k));
+    }
 };
 
-// Find place to insert if __k doesn't exist
-// Set __parent to parent of null leaf
-// Return reference to null leaf
-// If __k exists, set parent to node of __k and return reference to node of __k
-template <class _Key, class _Tp, class _Compare, class _Allocator>
-typename map<_Key, _Tp, _Compare, _Allocator>::__node_base_pointer&
-map<_Key, _Tp, _Compare, _Allocator>::__find_equal_key(__node_base_pointer& __parent,
-                                                       const key_type& __k)
-{
-    __node_pointer __nd = __tree_.__root();
-    if (__nd != nullptr)
-    {
-        while (true)
-        {
-            if (__tree_.value_comp().key_comp()(__k, __nd->__value_.__cc.first))
-            {
-                if (__nd->__left_ != nullptr)
-                    __nd = static_cast<__node_pointer>(__nd->__left_);
-                else
-                {
-                    __parent = static_cast<__node_base_pointer>(__nd);
-                    return __parent->__left_;
-                }
-            }
-            else if (__tree_.value_comp().key_comp()(__nd->__value_.__cc.first, __k))
-            {
-                if (__nd->__right_ != nullptr)
-                    __nd = static_cast<__node_pointer>(__nd->__right_);
-                else
-                {
-                    __parent = static_cast<__node_base_pointer>(__nd);
-                    return __parent->__right_;
-                }
-            }
-            else
-            {
-                __parent = static_cast<__node_base_pointer>(__nd);
-                return __parent;
-            }
-        }
-    }
-    __parent = static_cast<__node_base_pointer>(__tree_.__end_node());
-    return __parent->__left_;
-}
 
 // Find __k
 // Set __parent to parent of null leaf and
 //    return reference to null leaf iv __k does not exist.
 // If __k exists, set parent to node of __k and return reference to node of __k
 template <class _Key, class _Tp, class _Compare, class _Allocator>
-typename map<_Key, _Tp, _Compare, _Allocator>::__node_base_const_pointer
-map<_Key, _Tp, _Compare, _Allocator>::__find_equal_key(__node_base_const_pointer& __parent,
+typename map<_Key, _Tp, _Compare, _Allocator>::__node_base_pointer const&
+map<_Key, _Tp, _Compare, _Allocator>::__find_equal_key(__node_base_pointer& __parent,
                                                        const key_type& __k) const
 {
-    __node_const_pointer __nd = __tree_.__root();
+    __node_pointer __nd = __tree_.__root();
     if (__nd != nullptr)
     {
         while (true)
@@ -1416,7 +1377,7 @@ map<_Key, _Tp, _Compare, _Allocator>::__
                 else
                 {
                     __parent = static_cast<__node_base_pointer>(__nd);
-                    return const_cast<const __node_base_const_pointer&>(__parent->__left_);
+                    return __parent->__left_;
                 }
             }
             else if (__tree_.value_comp().key_comp()(__nd->__value_.__cc.first, __k))
@@ -1426,7 +1387,7 @@ map<_Key, _Tp, _Compare, _Allocator>::__
                 else
                 {
                     __parent = static_cast<__node_base_pointer>(__nd);
-                    return const_cast<const __node_base_const_pointer&>(__parent->__right_);
+                    return __parent->__right_;
                 }
             }
             else
@@ -1437,7 +1398,7 @@ map<_Key, _Tp, _Compare, _Allocator>::__
         }
     }
     __parent = static_cast<__node_base_pointer>(__tree_.__end_node());
-    return const_cast<const __node_base_const_pointer&>(__parent->__left_);
+    return __parent->__left_;
 }
 
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
@@ -1581,13 +1542,13 @@ template <class _Key, class _Tp, class _
 const _Tp&
 map<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k) const
 {
-    __node_base_const_pointer __parent;
-    __node_base_const_pointer __child = __find_equal_key(__parent, __k);
+    __node_base_pointer __parent;
+    __node_base_pointer __child = __find_equal_key(__parent, __k);
 #ifndef _LIBCPP_NO_EXCEPTIONS
     if (__child == nullptr)
         throw out_of_range("map::at:  key not found");
 #endif  // _LIBCPP_NO_EXCEPTIONS
-    return static_cast<__node_const_pointer>(__child)->__value_.__cc.second;
+    return static_cast<__node_pointer>(__child)->__value_.__cc.second;
 }
 
 #if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
@@ -2071,7 +2032,7 @@ private:
     typedef typename __base::__node                    __node;
     typedef typename __base::__node_allocator          __node_allocator;
     typedef typename __base::__node_pointer            __node_pointer;
-    typedef typename __base::__node_const_pointer      __node_const_pointer;
+
     typedef __map_node_destructor<__node_allocator> _Dp;
     typedef unique_ptr<__node, _Dp> __node_holder;
 

Modified: libcxx/trunk/test/libcxx/test/config.py
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/libcxx/test/config.py?rev=261419&r1=261418&r2=261419&view=diff
==============================================================================
--- libcxx/trunk/test/libcxx/test/config.py (original)
+++ libcxx/trunk/test/libcxx/test/config.py Sat Feb 20 01:12:17 2016
@@ -515,7 +515,7 @@ class Configuration(object):
         if enable_warnings:
             self.cxx.compile_flags += [
                 '-D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER',
-                '-Wall', '-Werror'
+                '-Wall', '-Wextra', '-Werror'
             ]
             self.cxx.addWarningFlagIfSupported('-Wno-attributes')
             self.cxx.addWarningFlagIfSupported('-Wno-pessimizing-move')
@@ -525,6 +525,8 @@ class Configuration(object):
             # compiles clean with them.
             self.cxx.addWarningFlagIfSupported('-Wno-unused-local-typedef')
             self.cxx.addWarningFlagIfSupported('-Wno-unused-variable')
+            self.cxx.addWarningFlagIfSupported('-Wno-unused-parameter')
+            self.cxx.addWarningFlagIfSupported('-Wno-sign-compare')
             std = self.get_lit_conf('std', None)
             if std in ['c++98', 'c++03']:
                 # The '#define static_assert' provided by libc++ in C++03 mode




More information about the cfe-commits mailing list