This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
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
fails...
#include <set>
using namespace std;
typedef set<unsigned,less<unsigned> > S;
S v;
void f(const S &w) {
v.find(2);
w.find(2);
}
> (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?
Gerald
2003-07-10 Gerald Pfeifer <pfeifer@dbai.tuwien.ac.at>
* 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
_Link_type
_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); }