public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/14410] New: Bug with implementation of set for const iterators in g++ ...
@ 2004-03-03 16:11 areza123 at yahoo dot com
  2004-03-03 16:20 ` [Bug libstdc++/14410] " bangerth at dealii dot org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: areza123 at yahoo dot com @ 2004-03-03 16:11 UTC (permalink / raw)
  To: gcc-bugs

On g++ compiler extracted from cygwin, I found the following inconsistencies in 
the implementation of set.  If I have a const container, then the compiler 
should flag of a compilation *error* on an attempt to access elements using a 
non-const iterator. Hence, if I instantiate the print_elements method (which 
uses a non const iterator ) pos, I expect it to be *flagged*  of as a 
compilation error. This is not what happens. 

#include <iostream>
#include <set>
using namespace std;

template <typename T>
void print_elements(const T & t, const char * print_header)
{
  cout << print_header << endl;
  typename T::iterator pos;
  for (pos = t.begin(); pos != t.end(); ++pos) {
    cout << *pos << endl;
  }
}

This works perfectly fine if I instantiate using T as set<int> shown below. 
This is *incorrect*. 

int main()
{
  set<int> col1;
  for (int i = 0; i <=5; ++i) {
    col1.insert(i);
  }
  print_elements(col1, "initialized: ");
  return 0;
}

Could somebody explain ? 

BTW - compiler behaves as expected *flagging* off errors for other container's 
like deque, etc.
gcc --version 2.95.3-5
system type - Windows 2000 Professional
complete command line that triggers the bug - g++ bugged_prog.cc

-- 
           Summary: Bug with implementation of set for const iterators in
                    g++ ...
           Product: gcc
           Version: 2.95.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: areza123 at yahoo dot com
                CC: areza123 at yahoo dot com,gcc-bugs at gcc dot gnu dot
                    org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14410


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug libstdc++/14410] Bug with implementation of set for const iterators in g++ ...
  2004-03-03 16:11 [Bug c++/14410] New: Bug with implementation of set for const iterators in g++ areza123 at yahoo dot com
@ 2004-03-03 16:20 ` bangerth at dealii dot org
  2004-03-04  0:45 ` reichelt at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: bangerth at dealii dot org @ 2004-03-03 16:20 UTC (permalink / raw)
  To: gcc-bugs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|c++                         |libstdc++


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14410


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug libstdc++/14410] Bug with implementation of set for const iterators in g++ ...
  2004-03-03 16:11 [Bug c++/14410] New: Bug with implementation of set for const iterators in g++ areza123 at yahoo dot com
  2004-03-03 16:20 ` [Bug libstdc++/14410] " bangerth at dealii dot org
@ 2004-03-04  0:45 ` reichelt at gcc dot gnu dot org
  2004-03-04  1:12 ` pcarlini at suse dot de
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: reichelt at gcc dot gnu dot org @ 2004-03-04  0:45 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From reichelt at gcc dot gnu dot org  2004-03-04 00:45 -------
Confirmed. Even in mainline's bits/stl_set.h we have

      typedef typename _Rep_type::const_iterator iterator;
      typedef typename _Rep_type::const_iterator const_iterator;
      typedef typename _Rep_type::const_reverse_iterator reverse_iterator;
      typedef typename _Rep_type::const_reverse_iterator const_reverse_iterator;

which doesn't look right :-(
BTW, the same lines are in bits/stl_multiset.h.

If no-one beats me, I'll prepare a patch tomorrow.


-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |reichelt at gcc dot gnu dot
                   |                            |org
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|                            |1
   Last reconfirmed|0000-00-00 00:00:00         |2004-03-04 00:45:21
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14410


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug libstdc++/14410] Bug with implementation of set for const iterators in g++ ...
  2004-03-03 16:11 [Bug c++/14410] New: Bug with implementation of set for const iterators in g++ areza123 at yahoo dot com
  2004-03-03 16:20 ` [Bug libstdc++/14410] " bangerth at dealii dot org
  2004-03-04  0:45 ` reichelt at gcc dot gnu dot org
@ 2004-03-04  1:12 ` pcarlini at suse dot de
  2004-03-05  8:51 ` reichelt at igpm dot rwth-aachen dot de
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pcarlini at suse dot de @ 2004-03-04  1:12 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pcarlini at suse dot de  2004-03-04 01:12 -------
The issue was already presented in the past, for instance in:

   http://gcc.gnu.org/ml/gcc-bugs/2003-02/msg01402.html

Basically, in the light of the resolution of DR 103 [WP], "...For associative
containers where the value type is the same as the key type, both iterator and
const_iterator are constant iterators...". Therefore, our current implementation
is conforming.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14410


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug libstdc++/14410] Bug with implementation of set for const iterators in g++ ...
  2004-03-03 16:11 [Bug c++/14410] New: Bug with implementation of set for const iterators in g++ areza123 at yahoo dot com
                   ` (2 preceding siblings ...)
  2004-03-04  1:12 ` pcarlini at suse dot de
@ 2004-03-05  8:51 ` reichelt at igpm dot rwth-aachen dot de
  2004-03-05  9:04 ` pcarlini at suse dot de
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: reichelt at igpm dot rwth-aachen dot de @ 2004-03-05  8:51 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From reichelt at igpm dot rwth-aachen dot de  2004-03-05 08:51 -------
Subject: Re:  Bug with implementation of set for const
 iterators in g++ ...

On  4 Mar, pcarlini at suse dot de wrote:
> 
> ------- Additional Comments From pcarlini at suse dot de  2004-03-04 01:12 -------
> The issue was already presented in the past, for instance in:
> 
>    http://gcc.gnu.org/ml/gcc-bugs/2003-02/msg01402.html
> 
> Basically, in the light of the resolution of DR 103 [WP], "...For associative
> containers where the value type is the same as the key type, both iterator and
> const_iterator are constant iterators...". Therefore, our current implementation
> is conforming.

Oops! Sorry for the confusion.
But to prevent that from happening again, shouldn't we add a comment
like "DR 103" to the typedefs of the iterators in question?




-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14410


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug libstdc++/14410] Bug with implementation of set for const iterators in g++ ...
  2004-03-03 16:11 [Bug c++/14410] New: Bug with implementation of set for const iterators in g++ areza123 at yahoo dot com
                   ` (3 preceding siblings ...)
  2004-03-05  8:51 ` reichelt at igpm dot rwth-aachen dot de
@ 2004-03-05  9:04 ` pcarlini at suse dot de
  2004-03-20 21:58 ` reichelt at gcc dot gnu dot org
  2005-01-17 12:07 ` pcarlini at suse dot de
  6 siblings, 0 replies; 8+ messages in thread
From: pcarlini at suse dot de @ 2004-03-05  9:04 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pcarlini at suse dot de  2004-03-05 09:04 -------
Subject: Re:  Bug with implementation of set for const
 iterators in g++ ...

Volker Reichelt wrote:

>Oops! Sorry for the confusion.
>But to prevent that from happening again, shouldn't we add a comment
>like "DR 103" to the typedefs of the iterators in question?
>
In this specific case, I agree. But it's something that must be decided 
case by
case: we don't really want to add DR XXX for every DR that we implement
correctly, since many are trivial and/or have been always right.

Paolo.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14410


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug libstdc++/14410] Bug with implementation of set for const iterators in g++ ...
  2004-03-03 16:11 [Bug c++/14410] New: Bug with implementation of set for const iterators in g++ areza123 at yahoo dot com
                   ` (4 preceding siblings ...)
  2004-03-05  9:04 ` pcarlini at suse dot de
@ 2004-03-20 21:58 ` reichelt at gcc dot gnu dot org
  2005-01-17 12:07 ` pcarlini at suse dot de
  6 siblings, 0 replies; 8+ messages in thread
From: reichelt at gcc dot gnu dot org @ 2004-03-20 21:58 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From reichelt at gcc dot gnu dot org  2004-03-20 21:58 -------
Just for the record: Paolo added the suggested comment, see

http://gcc.gnu.org/ml/libstdc++-cvs/2004-q1/msg00636.html


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14410


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug libstdc++/14410] Bug with implementation of set for const iterators in g++ ...
  2004-03-03 16:11 [Bug c++/14410] New: Bug with implementation of set for const iterators in g++ areza123 at yahoo dot com
                   ` (5 preceding siblings ...)
  2004-03-20 21:58 ` reichelt at gcc dot gnu dot org
@ 2005-01-17 12:07 ` pcarlini at suse dot de
  6 siblings, 0 replies; 8+ messages in thread
From: pcarlini at suse dot de @ 2005-01-17 12:07 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pcarlini at suse dot de  2005-01-17 12:07 -------
*** Bug 19480 has been marked as a duplicate of this bug. ***

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |malessa at de dot ibm dot
                   |                            |com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14410


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2005-01-17 12:07 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-03-03 16:11 [Bug c++/14410] New: Bug with implementation of set for const iterators in g++ areza123 at yahoo dot com
2004-03-03 16:20 ` [Bug libstdc++/14410] " bangerth at dealii dot org
2004-03-04  0:45 ` reichelt at gcc dot gnu dot org
2004-03-04  1:12 ` pcarlini at suse dot de
2004-03-05  8:51 ` reichelt at igpm dot rwth-aachen dot de
2004-03-05  9:04 ` pcarlini at suse dot de
2004-03-20 21:58 ` reichelt at gcc dot gnu dot org
2005-01-17 12:07 ` pcarlini at suse dot de

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