[Patch] PR11504: -Wcast-qual and general constness issues with stl_tree.h

Gawain Bolton gbolton@free.fr
Thu Jul 24 19:47:00 GMT 2003


Please find attached a patch which will solve PR11504 as well as fix 
other constness issues with stl_tree.h.  I have also gotten rid of 
C-style casts and replaced them with the appropriate C++-style casts.

There is only one const_cast required.  This is because the const and 
non-const iterators both inherit from _Rb_tree_base_iterator which has a 
non-const data member (_M_node).  Still, this is much better than before 
since the old C-style casts were often casting away constness.

Still there are two things I'm not too happy about - maybe someone can 
help out:

   1. I do not like the lack of symmetry with the casts for const vs.
      non-const functions.
      Non-const versions often require a reinterpret_cast whereas const
      versions can use static_cast.
   2. The "const" typedefs.
      Why do I have to define "const" versions of the typedefs?
      If I have "typedef _Rb_tree_node* _Link_type;" then why can't I
      use "const _Link_type" instead of having to define an explicit
      const typedef like "typedef const _Rb_tree_node* _const_Link_type;"?

Anyway, this patch has been tested on i686-pc-linux-gnu with std::set, 
std::multiset, std::map and std::multimap including the debug 
__rb_verify() function.

Cheers,


Gawain

-- 
Gawain Bolton
Coignieres, France
PGP Info: Key server: http://wwwkeys.pgp.net
          Key id: 6EBEDEA6
          Fingerprint: 65C0 0030 21D1 7A01 546A  E7DB D60F 47E0 6EBE DEA6

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: pr11504.patch.txt
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20030724/4748b76d/attachment.txt>


More information about the Libstdc++ mailing list