This is the mail archive of the mailing list for the libstdc++ 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, 2003-07-08 at 02:29, Gerald Pfeifer wrote:
> Mark, might this be a result of your recent parser changes? (And if so,
> is this a problem with these changes, or did they just uncover a latent
> problem in libstdc++?)
> If not, it's a recently introduced libstdc++ problem.
> The following simple program
>   #include <set>
>   using namespace std;
>   set<unsigned,less<unsigned> > V;
> now generates warnings when compiled with gccvs -Wcast-qual (mainline,
> about an hour ago):

That's a valid warning, i.e, if this is a change in behavior it
represents a progression in the compiler.

The code in question is:

      _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.

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

Mark Mitchell
CodeSourcery, LLC

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