This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: -Wcast-qual broken(?) for libstdc++

On Tue, 8 Jul 2003, Mark Mitchell wrote:
> The code in question is:
>       _Link_type
>       _M_end() const { return (_Link_type) &this->_M_header; }
> _M_header has type _Rb_tree_node_base; _Link_type is  _Rb_tree_node*.
> The type of "this" is "const _Rb_tree*" since we are in a const member
> function.  The expression "this->_M_header" is decreed by the standard
> to be equivalent to "(*this)._M_header".  The type of "*this" is "const
> _Rb_tree".  The standard says that you combine cv-qualifiers on a "."
> expression; therefore, the the type of "(*this)._M_header" is "const
> _Rb_tree_node *".  Therefore, the cast discards cv-qualifiers.

The patch below fixes my original testcase, but the following still

  #include <set>
  using namespace std;

  typedef set<unsigned,less<unsigned> > S;
  S v;

  void f(const S &w) {

> (This is why functions like "vector<T>::end() const" return a
> "const_iterator".)

...and seems to require an approach similar to const_iterator.

Clearly, this is a regression.  Just, who is going to implement a more
complete fix then my patch below?


2003-07-10  Gerald Pfeifer  <>

	* include/bits/stl_tree.h (_Rb_tree): Add non-const version of _M_end().

Index: include/bits/stl_tree.h
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/bits/stl_tree.h,v
retrieving revision 1.26
diff -u -3 -p -r1.26 stl_tree.h
--- include/bits/stl_tree.h	9 Jul 2003 20:58:32 -0000	1.26
+++ include/bits/stl_tree.h	10 Jul 2003 11:45:37 -0000
@@ -378,6 +378,9 @@ namespace std

       _M_end() const { return (_Link_type) &this->_M_header; }
+      _Link_type
+      _M_end() { return (_Link_type) &this->_M_header; }

       static _Link_type&
       _S_left(_Link_type __x) { return (_Link_type&)(__x->_M_left); }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]