Bug 23781 - Implicit conversion from NULL to list<T>::iterator
Summary: Implicit conversion from NULL to list<T>::iterator
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: libstdc++ (show other bugs)
Version: 3.3.5
: P2 normal
Target Milestone: 4.1.0
Assignee: Paolo Carlini
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-09-08 15:55 UTC by Marc Boyer
Modified: 2005-09-11 09:52 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 2.95.3 4.0.0 3.0.4 3.2.3 3.0.4
Last reconfirmed: 2005-09-08 21:06:28


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Marc Boyer 2005-09-08 15:55:22 UTC
This code compiles, and should not. 

#include <list>
int main( ) {
  std::list< float >::iterator   l_it= NULL ;
}

Replacing list per vector, it does no more compile, which is a better result.
I am not a C++ expert, but after a short reading of the slt_list.h file,
I guess that the problem is thet there is a constructor of a base class of
list<>::iterator that is not "explicit".
Comment 1 Andrew Pinski 2005-09-08 17:30:36 UTC
Note ICC also accepts this code too.
Comment 2 Gabriel Dos Reis 2005-09-08 20:55:35 UTC
Subject: Re:  Implicit conversion from NULL to list<T>::iterator

"pinskia at gcc dot gnu dot org" <gcc-bugzilla@gcc.gnu.org> writes:

| Note ICC also accepts this code too.

yes, but that is irrelevant.  
We don't accept
   
    #include <vector>
    #include <string>
  
    int main()
    {
       using namespace std;
       vector<string>::iterator p = NULL;
    }

for proper type checking.  The list iterator constructor accepting a
pointer should be explicit.

Thanks Marc,

-- Gaby
Comment 3 Paolo Carlini 2005-09-08 21:06:28 UTC
(In reply to comment #2)
> We don't accept
>    
>     #include <vector>
>     #include <string>
>   
>     int main()
>     {
>        using namespace std;
>        vector<string>::iterator p = NULL;
>     }
> 
> for proper type checking.  The list iterator constructor accepting a
> pointer should be explicit.

Agreed. Likewise for deque::iterator, I suppose. I will work on this.
Comment 4 Paolo Carlini 2005-09-08 21:11:44 UTC
(In reply to comment #3)
> Agreed. Likewise for deque::iterator, I suppose. I will work on this.

I meant set::iterator and map::iterator, actually: checked earlier today
and forgot that deque is not affected. Anyway, consistency with the
behavior of vector.

Comment 5 Gabriel Dos Reis 2005-09-08 22:47:45 UTC
Subject: Re:  Implicit conversion from NULL to list<T>::iterator

"pcarlini at suse dot de" <gcc-bugzilla@gcc.gnu.org> writes:

| Agreed. Likewise for deque::iterator, I suppose. I will work on this.

Thank you much Paolo.

-- Gaby
Comment 6 GCC Commits 2005-09-11 09:48:51 UTC
Subject: Bug 23781

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	paolo@gcc.gnu.org	2005-09-11 09:48:41

Modified files:
	libstdc++-v3   : ChangeLog 
	libstdc++-v3/include/ext: slist 
	libstdc++-v3/include/tr1: hashtable array 
	libstdc++-v3/include/bits: list.tcc stl_list.h stl_tree.h 
	libstdc++-v3/testsuite/23_containers/map/operators: 1_neg.cc 
	libstdc++-v3/testsuite/23_containers/set/operators: 1_neg.cc 
Added files:
	libstdc++-v3/testsuite/ext/slist: 23781.cc 
	libstdc++-v3/testsuite/tr1/6_containers/unordered: 23781.cc 
	libstdc++-v3/testsuite/23_containers/list: 23781.cc 
	libstdc++-v3/testsuite/23_containers/map: 23781.cc 
	libstdc++-v3/testsuite/23_containers/multimap: 23781.cc 
	libstdc++-v3/testsuite/23_containers/multiset: 23781.cc 
	libstdc++-v3/testsuite/23_containers/set: 23781.cc 

Log message:
	2005-09-11  Paolo Carlini  <pcarlini@suse.de>
	
	PR libstdc++/23781
	* include/bits/stl_list.h (_List_iterator<>::
	_List_iterator(_List_node_base*), _List_const_iterator<>::
	_List_const_iterator(const _List_node_base*)): Make explicit.
	(list<>::begin(), list<>::end(), list<>::pop_back()): Adjust
	consistently.
	* include/bits/list.tcc (list<>::insert, list<>::erase): Adjust
	consistently.
	* include/bits/stl_tree.h (_Rb_tree_iterator<>::
	_Rb_tree_iterator(_Link_type), _Rb_tree_const_iterator<>::
	_Rb_tree_const_iterator(_Link_type)): Make explicit.
	(_Rb_tree<>::begin(), _Rb_tree<>::end()): Adjust consistently.
	* include/ext/slist (_Slist_iterator<>::_Slist_iterator(_Node*)):
	Make explicit.
	(slist<>::erase(iterator), slist<>::erase(iterator, iterator)):
	Adjust consistently.
	* include/tr1/hashtable (hashtable_iterator<>::
	hashtable_iterator(hash_node<>**)): Make explicit.
	* testsuite/23_containers/list/23781.cc: New.
	* testsuite/23_containers/map/23781.cc: Likewise.
	* testsuite/23_containers/multimap/23781.cc: Likewise.
	* testsuite/23_containers/multiset/23781.cc: Likewise.
	* testsuite/23_containers/set/23781.cc: Likewise.
	* testsuite/ext/slist/23781.cc: Likewise.
	* testsuite/tr1/6_containers/unordered/23781.cc: Likewise.
	* testsuite/23_containers/map/operators/1_neg.cc: Adjust dg-error
	line numbers.
	* testsuite/23_containers/set/operators/1_neg.cc: Likewise.
	
	* include/tr1/array (array<>::begin(), array<>::end()): Adjust
	stylistically for consistency with the other containers.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/ChangeLog.diff?cvsroot=gcc&r1=1.3094&r2=1.3095
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/include/ext/slist.diff?cvsroot=gcc&r1=1.27&r2=1.28
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/include/tr1/hashtable.diff?cvsroot=gcc&r1=1.8&r2=1.9
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/include/tr1/array.diff?cvsroot=gcc&r1=1.7&r2=1.8
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/testsuite/ext/slist/23781.cc.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/testsuite/tr1/6_containers/unordered/23781.cc.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/include/bits/list.tcc.diff?cvsroot=gcc&r1=1.21&r2=1.22
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/include/bits/stl_list.h.diff?cvsroot=gcc&r1=1.51&r2=1.52
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/include/bits/stl_tree.h.diff?cvsroot=gcc&r1=1.47&r2=1.48
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/testsuite/23_containers/list/23781.cc.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/testsuite/23_containers/map/23781.cc.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/testsuite/23_containers/map/operators/1_neg.cc.diff?cvsroot=gcc&r1=1.7&r2=1.8
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/testsuite/23_containers/multimap/23781.cc.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/testsuite/23_containers/multiset/23781.cc.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/testsuite/23_containers/set/23781.cc.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/testsuite/23_containers/set/operators/1_neg.cc.diff?cvsroot=gcc&r1=1.7&r2=1.8

Comment 7 Paolo Carlini 2005-09-11 09:52:36 UTC
Fixed for 4.1.