public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/41803] New: Compiler forcing iterator to const
@ 2009-10-22 22:46 dont_spam_james at yahoo dot com
2009-10-22 22:47 ` [Bug c++/41803] " dont_spam_james at yahoo dot com
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: dont_spam_james at yahoo dot com @ 2009-10-22 22:46 UTC (permalink / raw)
To: gcc-bugs
In the source code there are two classes, Point and Edge. A series of points
are stored in a std::multiset. Edges are formed between the points, referenced
by multiset iterators. The points are given pointers to the edge they are a
part of.
In the function Edge::splitEdge, an edge is broken up by a new point. The
point is added to the multiset, a new edge is created, the edge's iterators are
reset, and the Edge pointers are reset.
When resetting the Edge pointers, the compiler is insisting that the data
contained in std::multiset<Point>::iterator is a const Point.
If I change the Point member data Edge *dp_edge to mutable and make the
Point::setEdge function const, the code compiles.
--
Summary: Compiler forcing iterator to const
Product: gcc
Version: 4.2.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: dont_spam_james at yahoo dot com
GCC build triplet: x84_64-unknown-linux-gnu
GCC host triplet: x84_64-unknown-linux-gnu
GCC target triplet: x84_64-unknown-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41803
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/41803] Compiler forcing iterator to const
2009-10-22 22:46 [Bug c++/41803] New: Compiler forcing iterator to const dont_spam_james at yahoo dot com
@ 2009-10-22 22:47 ` dont_spam_james at yahoo dot com
2009-10-22 22:53 ` dont_spam_james at yahoo dot com
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: dont_spam_james at yahoo dot com @ 2009-10-22 22:47 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from dont_spam_james at yahoo dot com 2009-10-22 22:47 -------
Created an attachment (id=18873)
--> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=18873&action=view)
Simple C++ file showing the build error.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41803
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/41803] Compiler forcing iterator to const
2009-10-22 22:46 [Bug c++/41803] New: Compiler forcing iterator to const dont_spam_james at yahoo dot com
2009-10-22 22:47 ` [Bug c++/41803] " dont_spam_james at yahoo dot com
@ 2009-10-22 22:53 ` dont_spam_james at yahoo dot com
2009-10-22 22:57 ` [Bug libstdc++/41803] " pinskia at gcc dot gnu dot org
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: dont_spam_james at yahoo dot com @ 2009-10-22 22:53 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from dont_spam_james at yahoo dot com 2009-10-22 22:52 -------
Created an attachment (id=18875)
--> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=18875&action=view)
.ii file
Obtained using
g++ -v -save-temps -m32 -o -Wall -Werror -pedantic testLinuxBuildError.cpp
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41803
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug libstdc++/41803] Compiler forcing iterator to const
2009-10-22 22:46 [Bug c++/41803] New: Compiler forcing iterator to const dont_spam_james at yahoo dot com
2009-10-22 22:47 ` [Bug c++/41803] " dont_spam_james at yahoo dot com
2009-10-22 22:53 ` dont_spam_james at yahoo dot com
@ 2009-10-22 22:57 ` pinskia at gcc dot gnu dot org
2009-10-22 23:14 ` chris at bubblescope dot net
2009-10-22 23:22 ` paolo dot carlini at oracle dot com
4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2009-10-22 22:57 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from pinskia at gcc dot gnu dot org 2009-10-22 22:56 -------
Looks like a bug in multiset:
typedef typename _Rep_type::iterator const_iterator;
--
pinskia at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Component|c++ |libstdc++
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41803
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug libstdc++/41803] Compiler forcing iterator to const
2009-10-22 22:46 [Bug c++/41803] New: Compiler forcing iterator to const dont_spam_james at yahoo dot com
` (2 preceding siblings ...)
2009-10-22 22:57 ` [Bug libstdc++/41803] " pinskia at gcc dot gnu dot org
@ 2009-10-22 23:14 ` chris at bubblescope dot net
2009-10-22 23:22 ` paolo dot carlini at oracle dot com
4 siblings, 0 replies; 6+ messages in thread
From: chris at bubblescope dot net @ 2009-10-22 23:14 UTC (permalink / raw)
To: gcc-bugs
------- Comment #4 from chris at bubblescope dot net 2009-10-22 23:14 -------
The reason that in general changing the Point a std::multiset<Point>::iterator
refers to is forbidden is that doing so will break the invariant on which the
multiset is based, resulting in random crashes occuring later on.
The standard does say, in 23.1.4 paragraph 5 "Keys in an associative container
are immutable.". Seeing as you know that actually your changes won't break the
ordering, what you are doing is legal, and can be done in two ways:
1) Use mutable, as you were already suggesting.
2) Add a const_cast to the 'const point&' you get out.
I realise this is a little annoying, but it was considered the alternative was
too buggy, as most people would just changes things in (multi)sets without
realising in most cases it would lead to horribly broken code.
--
chris at bubblescope dot net changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |chris at bubblescope dot net
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41803
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug libstdc++/41803] Compiler forcing iterator to const
2009-10-22 22:46 [Bug c++/41803] New: Compiler forcing iterator to const dont_spam_james at yahoo dot com
` (3 preceding siblings ...)
2009-10-22 23:14 ` chris at bubblescope dot net
@ 2009-10-22 23:22 ` paolo dot carlini at oracle dot com
4 siblings, 0 replies; 6+ messages in thread
From: paolo dot carlini at oracle dot com @ 2009-10-22 23:22 UTC (permalink / raw)
To: gcc-bugs
------- Comment #5 from paolo dot carlini at oracle dot com 2009-10-22 23:21 -------
*** This bug has been marked as a duplicate of 14410 ***
--
paolo dot carlini at oracle dot com changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |DUPLICATE
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41803
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2009-10-22 23:22 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-10-22 22:46 [Bug c++/41803] New: Compiler forcing iterator to const dont_spam_james at yahoo dot com
2009-10-22 22:47 ` [Bug c++/41803] " dont_spam_james at yahoo dot com
2009-10-22 22:53 ` dont_spam_james at yahoo dot com
2009-10-22 22:57 ` [Bug libstdc++/41803] " pinskia at gcc dot gnu dot org
2009-10-22 23:14 ` chris at bubblescope dot net
2009-10-22 23:22 ` paolo dot carlini at oracle dot com
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).