Bug 14340 - libstdc++ Debug mode: failure to convert iterator to const_iterator
Summary: libstdc++ Debug mode: failure to convert iterator to const_iterator
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: libstdc++ (show other bugs)
Version: 4.0.0
: P2 normal
Target Milestone: 3.4.1
Assignee: Not yet assigned to anyone
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2004-02-29 03:08 UTC by phil.el
Modified: 2004-05-20 18:39 UTC (History)
1 user (show)

See Also:
Host: i686-pc-linux-gnu
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2004-02-29 03:55:43


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description phil.el 2004-02-29 03:08:20 UTC
#include <vector>
std::vector<int>::const_iterator find_arc()
{
	std::vector<int> v;
	std::vector<int>::const_iterator it = v.begin();
	std::vector<int>::const_iterator end = v.end();
	return it == end ? v.end() : it;
}


g++ -D_GLIBCXX_DEBUG -c debug-mode-1.cpp

debug-mode-1.cpp: In function
`__gnu_debug::_Safe_iterator<__gnu_cxx::__normal_iterator<const int*,
__gnu_norm::vector<int, std::allocator<int> > >, __gnu_debug_def::vector<int,
std::allocator<int> > > find_arc()':
debug-mode-1.cpp:10: error: operands to ?: have different types

the type are vector<int>::iterator and vector<int>::const_iterator but
a conversion should occur imho.

regards,
Phil
Comment 1 Andrew Pinski 2004-02-29 03:21:13 UTC
Well this has never worked from 3.0.4 to 3.5.0, even without Debug mode on or off (even though it was 
added just for 3.4.0).  Note for some reason 2.95.3 worked but I do not know if this is really a bug.  
Also note ICC 6.0 accepted the code.
Comment 2 phil.el 2004-02-29 03:51:23 UTC
ok sorry too many simplification to the test case: this one
work for 2.95.3/3.2.3/3.3.3 and tree-ssa, it fails only with
tree ssa and -D_GLIBCXX_DEBUG

#include <map>

typedef std::map<int, int> container;

container::const_iterator find_arc()
{
	container v;
	container::const_iterator it = v.begin();
	container::const_iterator end = v.end();
	return it == end ? v.end() : it;
}
Comment 3 Andrew Pinski 2004-02-29 03:55:43 UTC
Ok, I can confirm that one.
Comment 4 GCC Commits 2004-05-18 03:28:02 UTC
Subject: Bug 14340

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	bkoz@gcc.gnu.org	2004-05-18 03:27:57

Modified files:
	libstdc++-v3   : ChangeLog 
	libstdc++-v3/include/debug: safe_iterator.h 
	libstdc++-v3/testsuite: testsuite_hooks.h 
Added files:
	libstdc++-v3/testsuite/23_containers/deque: 14340.cc 
	libstdc++-v3/testsuite/23_containers/list: 14340.cc 
	libstdc++-v3/testsuite/23_containers/map: 14340.cc 
	libstdc++-v3/testsuite/23_containers/multimap: 14340.cc 
	libstdc++-v3/testsuite/23_containers/multiset: 14340.cc 
	libstdc++-v3/testsuite/23_containers/set: 14340.cc 
	libstdc++-v3/testsuite/23_containers/vector: 14340.cc 

Log message:
	2004-05-17  Benjamin Kosnik  <bkoz@redhat.com>
	
	* testsuite/testsuite_hooks.h (__gnu_test::conversion): New class.
	* testsuite/23_containers/deque/14340.cc: New.
	* testsuite/23_containers/list/14340.cc: New.
	* testsuite/23_containers/map/14340.cc: New.
	* testsuite/23_containers/multimap/14340.cc: New.
	* testsuite/23_containers/multiset/14340.cc: New.
	* testsuite/23_containers/set/14340.cc: New.
	* testsuite/23_containers/vector/14340.cc: New.
	
	2004-05-17  Douglas Gregor   <gregod@cs.rpi.edu>
	
	PR libstdc++/14340
	* include/debug/safe_iterator.h (_Safe_iterator converting
	constructor): Only allow declaration to instantiate when the
	incoming _Safe_iterator has exactly the right iterator type.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/ChangeLog.diff?cvsroot=gcc&r1=1.2479&r2=1.2480
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/include/debug/safe_iterator.h.diff?cvsroot=gcc&r1=1.3&r2=1.4
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/testsuite/testsuite_hooks.h.diff?cvsroot=gcc&r1=1.27&r2=1.28
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/testsuite/23_containers/deque/14340.cc.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/testsuite/23_containers/list/14340.cc.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/testsuite/23_containers/map/14340.cc.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/testsuite/23_containers/multimap/14340.cc.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/testsuite/23_containers/multiset/14340.cc.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/testsuite/23_containers/set/14340.cc.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/testsuite/23_containers/vector/14340.cc.diff?cvsroot=gcc&r1=NONE&r2=1.1

Comment 5 GCC Commits 2004-05-18 18:41:34 UTC
Subject: Bug 14340

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-3_4-branch
Changes by:	bkoz@gcc.gnu.org	2004-05-18 18:41:24

Modified files:
	libstdc++-v3   : ChangeLog 
	libstdc++-v3/include/debug: safe_iterator.h 
	libstdc++-v3/testsuite: testsuite_hooks.h 
Added files:
	libstdc++-v3/testsuite/23_containers/deque: 14340.cc 
	libstdc++-v3/testsuite/23_containers/list: 14340.cc 
	libstdc++-v3/testsuite/23_containers/map: 14340.cc 
	libstdc++-v3/testsuite/23_containers/multimap: 14340.cc 
	libstdc++-v3/testsuite/23_containers/multiset: 14340.cc 
	libstdc++-v3/testsuite/23_containers/set: 14340.cc 
	libstdc++-v3/testsuite/23_containers/vector: 14340.cc 

Log message:
	2004-05-18  Benjamin Kosnik  <bkoz@redhat.com>
	
	* testsuite/testsuite_hooks.h (__gnu_test::conversion): New class.
	* testsuite/23_containers/deque/14340.cc: New.
	* testsuite/23_containers/list/14340.cc: New.
	* testsuite/23_containers/map/14340.cc: New.
	* testsuite/23_containers/multimap/14340.cc: New.
	* testsuite/23_containers/multiset/14340.cc: New.
	* testsuite/23_containers/set/14340.cc: New.
	* testsuite/23_containers/vector/14340.cc: New.
	
	2004-05-18  Douglas Gregor   <gregod@cs.rpi.edu>
	
	PR libstdc++/14340
	* include/debug/safe_iterator.h (_Safe_iterator converting
	constructor): Only allow declaration to instantiate when the
	incoming _Safe_iterator has exactly the right iterator type.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.2224.2.106&r2=1.2224.2.107
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/include/debug/safe_iterator.h.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.2.8.1&r2=1.2.8.2
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/testsuite/testsuite_hooks.h.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.25.4.2&r2=1.25.4.3
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/testsuite/23_containers/deque/14340.cc.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=NONE&r2=1.1.2.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/testsuite/23_containers/list/14340.cc.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=NONE&r2=1.1.2.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/testsuite/23_containers/map/14340.cc.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=NONE&r2=1.1.2.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/testsuite/23_containers/multimap/14340.cc.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=NONE&r2=1.1.2.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/testsuite/23_containers/multiset/14340.cc.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=NONE&r2=1.1.2.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/testsuite/23_containers/set/14340.cc.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=NONE&r2=1.1.2.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/testsuite/23_containers/vector/14340.cc.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=NONE&r2=1.1.2.1

Comment 6 Benjamin Kosnik 2004-05-20 18:39:30 UTC
Fixed in 3.4/mainline.