This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/14410] New: Bug with implementation of set for const iterators in g++ ...
- From: "areza123 at yahoo dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 3 Mar 2004 16:11:12 -0000
- Subject: [Bug c++/14410] New: Bug with implementation of set for const iterators in g++ ...
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
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