Bug 17373 - std::set::erase(const_iterator) doesn't output error on compilation
Summary: std::set::erase(const_iterator) doesn't output error on compilation
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: libstdc++ (show other bugs)
Version: 3.4.1
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
: 17374 (view as bug list)
Depends on:
Blocks:
 
Reported: 2004-09-09 12:13 UTC by Romain Behar
Modified: 2006-04-25 13:33 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Romain Behar 2004-09-09 12:13:53 UTC
The following instructions compile without any warning; tested using g++ 2.95,
3.3 and 3.4:

	std::set<int> vs;
	const std::set<int>::const_iterator i = vs.begin();
	vs.erase(i);

it should stop compilation with an error, such as:
" error: invalid conversion from `const int* const' to `int*' "
Comment 1 Giovanni Bajo 2004-09-09 12:17:08 UTC
No, the code is OK. A const iterator cannot be used to directly modify the 
container, but you can pass it to erase() without any problems.
Comment 2 Giovanni Bajo 2004-09-09 12:18:05 UTC
Also FYI notice that iterators are almost *never* implemented as raw pointers 
(they are objects which implements operator* and operator-> and acts like 
pointers).
Comment 3 Giovanni Bajo 2004-09-09 12:18:37 UTC
*** Bug 17374 has been marked as a duplicate of this bug. ***
Comment 4 Falk Hueffner 2006-04-25 13:19:10 UTC
The standard doesn't mention set::erase with "iterator" argument, only with
"const_iterator". Maybe it is legal for g++ to allow it anyway (even if I
cannot find anything in the standard allowing it at the moment), but other
compilers don't, so it is a rather useless extension. So I'll reopen this
bug.
Comment 5 Falk Hueffner 2006-04-25 13:20:43 UTC
(In reply to comment #4)
> The standard doesn't mention set::erase with "iterator" argument, only with
> "const_iterator".  

erm. the other way round, of course.
Comment 6 Richard Biener 2006-04-25 13:23:03 UTC
  template<class _Key, class _Compare, class _Alloc>
    class set 
    {
...
      // _GLIBCXX_RESOLVE_LIB_DEFECTS
      // DR 103. set::iterator is required to be modifiable,
      // but this allows modification of keys.
      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;

all iterators are const...
Comment 7 Paolo Carlini 2006-04-25 13:33:43 UTC
Yes, we are simply implementing the resolution of DR 103: set<>::iterator is a constant iterator type