[Container] --begin() on empty deque crashes
Hi there, The code below would simply crash on g++ 4.7.1/MinGW with default optimization level, it doesn't shown with -O/1/2/3 ---------------------------------------- boost::container::deque<int> d; --d.begin(); ---------------------------------------- I took a look into the impl, seems that it dereferences from (this->m_node - 1) which is invalid at the time. I guess it's the problem. Thoughts?
El 19/01/2013 13:06, TONGARI escribió:
Hi there,
The code below would simply crash on g++ 4.7.1/MinGW with default optimization level, it doesn't shown with -O/1/2/3 ---------------------------------------- boost::container::deque<int> d; --d.begin(); ----------------------------------------
The problem is that decrementing a begin iterator is not a valid operator, since it would point out of the container. Ion
2013/1/20 Ion Gaztañaga
El 19/01/2013 13:06, TONGARI escribió:
Hi there,
The code below would simply crash on g++ 4.7.1/MinGW with default optimization level, it doesn't shown with -O/1/2/3 ------------------------------**---------- boost::container::deque<int> d; --d.begin(); ------------------------------**----------
The problem is that decrementing a begin iterator is not a valid operator, since it would point out of the container.
But wouldn't it be a valid operation as long as we don't dereference from it?
On Jan 19, 2013, at 8:23 PM, TONGARI
2013/1/20 Ion Gaztañaga
El 19/01/2013 13:06, TONGARI escribió: Hi there,
The code below would simply crash on g++ 4.7.1/MinGW with default optimization level, it doesn't shown with -O/1/2/3 ---------------------------------------- boost::container::deque<int> d; --d.begin(); ----------------------------------------
The problem is that decrementing a begin iterator is not a valid operator, since it would point out of the container.
But wouldn't it be a valid operation as long as we don't dereference from it?
I don't believe so. If it was a pointer, then yes. The closest I could find in the standard was section 24.2.6 (talking about bidirectional iterators), it says that a precondition for --r is: there exists s such that r == ++s -- Marshall Marshall Clow Idio Software mailto:mclow.lists@gmail.com A.D. 1517: Martin Luther nails his 95 Theses to the church door and is promptly moderated down to (-1, Flamebait). -- Yu Suzuki
2013/1/20 Marshall Clow
On Jan 19, 2013, at 8:23 PM, TONGARI
wrote: 2013/1/20 Ion Gaztañaga
El 19/01/2013 13:06, TONGARI escribió:
Hi there,
The code below would simply crash on g++ 4.7.1/MinGW with default optimization level, it doesn't shown with -O/1/2/3 ------------------------------**---------- boost::container::deque<int> d; --d.begin(); ------------------------------**----------
The problem is that decrementing a begin iterator is not a valid operator, since it would point out of the container.
But wouldn't it be a valid operation as long as we don't dereference from it?
I don't believe so. If it was a pointer, then yes.
The closest I could find in the standard was section 24.2.6 (talking about bidirectional iterators), it says that a precondition for --r is: there exists s such that r == ++s
OK, thanks. According to the requirement it's invalid indeed, I thought that we have ++end() a valid op so it must apply to --begin() as well, but that's not true.
2013/1/20 TONGARI
2013/1/20 Marshall Clow
On Jan 19, 2013, at 8:23 PM, TONGARI
wrote: 2013/1/20 Ion Gaztañaga
El 19/01/2013 13:06, TONGARI escribió:
Hi there,
The code below would simply crash on g++ 4.7.1/MinGW with default optimization level, it doesn't shown with -O/1/2/3 ------------------------------**---------- boost::container::deque<int> d; --d.begin(); ------------------------------**----------
The problem is that decrementing a begin iterator is not a valid operator, since it would point out of the container.
But wouldn't it be a valid operation as long as we don't dereference from it?
I don't believe so. If it was a pointer, then yes.
The closest I could find in the standard was section 24.2.6 (talking about bidirectional iterators), it says that a precondition for --r is: there exists s such that r == ++s
OK, thanks. According to the requirement it's invalid indeed, I thought that we have ++end() a valid op so it must apply to --begin() as well, but that's not true.
Ah, wrong again, ++end() is invalid, sorry for the noise.
participants (3)
-
Ion Gaztañaga
-
Marshall Clow
-
TONGARI