This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: gcc, 'discards qualifers' error using templates
- From: Oliver Kullmann <O dot Kullmann at Swansea dot ac dot uk>
- To: "Petersen, Ulf" <Ulf dot Petersen at nittan dot consilium dot se>, gcc-help at gcc dot gnu dot org
- Date: Thu, 23 Oct 2003 12:36:02 +0100
- Subject: Re: gcc, 'discards qualifers' error using templates
- References: <498492661807FB488C71436914DEB631087A0F@gotexchange.consilium.net>
> Hi all.
>
> I'm having a problem when compiling code for an embedded Linux
> platform (I'm limited to using gcc 2.95.3) and was hoping somebody could
> offer some ideas on the matter...
>
> I get the 'discards qualifers' error when running gcc. The entir error message
> and an extract of the code is included.
>
> The code compiles and runs perfectly with MS (yes I actually wrote it out loud)
> Visual C++ 6.0.
>
Hi,
as you find in
@Book{Jo1999,
author = {Nicolai M. Josuttis},
title = {The C++ Standard Library: A Tutorial and Reference},
publisher = {Addison-Wesley},
year = 1999,
address = {Boston},
note = {ISBN 0-201-37926-0; QA76.73.C153J69 1999},
annote = {Vorhanden.}
}
page 177:
"However, automatic sorting also imposes an important constraint on sets and multisets:
You may *not* change the value of an element because this might compromise the correct
order. ...
Indirect access via iterators has the constraint that, from the iterator's point of view,
the element is constant."
Now with
itZ->m_loopUnitDefs.insert(*it); //ERROR
you change the elements itZ points to, which is in a set,
and thus may loose its integrity when any element is "just"
changed.
So it seems that gcc is right, and your code is ill-formed.
Moreover, it is also logically at fault.
D'accord?
Oliver
> Any help would be much appreciated.
>
> Sincerly Ulf
>
> --------------------------
> ERROR message:
>
> passing `const P_LOOP_UNIT_DEFS' as `this' argument of
> `struct _STL::pair<_STL::_Rb_tree_iterator<CLoopUnitDef *,_STL::_Const_traits<CLoopUnitDef *> >,bool> _STL::set<CLoopUnitDef *,_STL::less<CLoopUnitDef *>,_STL::allocator<CLoopUnitDef *> >
> ::insert(CLoopUnitDef *const &)' discards qualifiers
>
> ------------------------
> CODE:
>
> #include <set>
> using namespace std;
>
> class CLoopUnitDef
> {
> ...
> };
>
> typedef set<CLoopUnitDef*> P_LOOP_UNIT_DEFS;
>
> class CZoneDef
> {
> ...
> public:
> int m_zone;
> P_LOOP_UNIT_DEFS m_loopUnitDefs;
> };
> typedef set<CZoneDef> ZONE_DEFS;
>
>
> class CConfiguration
> {
> public:
> ...
> bool GetXmlDef(CStdString defFile)
> {
> ...
> if(m_zoneDefs.size() && m_loopUnitDefs.size())
> {
> for(P_LOOP_UNIT_DEFS::iterator it=m_loopUnitDefs.begin(); it != m_loopUnitDefs.end(); it++)
> {
> ZONE_DEFS::iterator itZ = m_zoneDefs.find((*it)->m_zone);
>
> if(itZ != m_zoneDefs.end())
> itZ->m_loopUnitDefs.insert(*it); //ERROR
> }
> }
> };
>
> private:
> ZONE_DEFS m_zoneDefs;
> P_LOOP_UNIT_DEFS m_loopUnitDefs;
> };
>
>
--
Dr. Oliver Kullmann
Computer Science Department
University of Wales Swansea
Faraday Building, Singleton Park
Swansea SA2 8PP, UK
http://cs-svr1.swan.ac.uk/~csoliver/