This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: -Wcast-qual broken(?) for libstdc++
- From: Mark Mitchell <mark at codesourcery dot com>
- To: Gerald Pfeifer <pfeifer at dbai dot tuwien dot ac dot at>
- Cc: gcc at gcc dot gnu dot org, libstdc++ at gcc dot gnu dot org
- Date: 08 Jul 2003 08:35:27 -0700
- Subject: Re: -Wcast-qual broken(?) for libstdc++
- References: <Pine.BSF.4.56.0307081122500.13730@acrux.dbai.tuwien.ac.at>
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:
_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.
(This is why functions like "vector<T>::end() const" return a
"const_iterator".)
--
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com