This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: -Wcast-qual broken(?) for libstdc++
On Thu, 2003-07-10 at 04:50, Gerald Pfeifer wrote:
> 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?
Hopefully one of the library people will get to it.
(I don't feel this is really a situation where my patch uncovered a
latent bug, since the problems are not in the compiler but in the
library, but maybe that's not fair. If, however, the consensus is that
I am obligated to fix the bug, I will honor that.)
--
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com