Protect from comma operator overload

Message ID e21ee73e-fa91-2c95-2c0e-8648b299216b@gmail.com
State New
Headers show
Series
  • Protect from comma operator overload
Related show

Commit Message

François Dumont April 16, 2018, 7:52 p.m.
Hi

     While working on something else on libstdc++ I started having a 
test failing because of the missing comma overload protection in 
deque.tcc. So I looked for other similar places in the code and here is 
a patch to fix the places I found.

     Let me know if it is still time to commit.

François

Comments

Jonathan Wakely April 16, 2018, 8:08 p.m. | #1
On 16 April 2018 at 20:52, François Dumont wrote:
> Hi
>
>     While working on something else on libstdc++ I started having a test
> failing because of the missing comma overload protection in deque.tcc. So I
> looked for other similar places in the code and here is a patch to fix the
> places I found.
>
>     Let me know if it is still time to commit.

The changes look right, but please add new tests to demonstrate the
code that used to fail.

You can use <testsuite_iterators.h> because the iterator types defined
in there have deleted comma operators that should cause errors in
these places.
Jonathan Wakely April 16, 2018, 8:16 p.m. | #2
On 16 April 2018 at 21:08, Jonathan Wakely wrote:
> On 16 April 2018 at 20:52, François Dumont wrote:
>> Hi
>>
>>     While working on something else on libstdc++ I started having a test
>> failing because of the missing comma overload protection in deque.tcc. So I
>> looked for other similar places in the code and here is a patch to fix the
>> places I found.
>>
>>     Let me know if it is still time to commit.
>
> The changes look right, but please add new tests to demonstrate the
> code that used to fail.
>
> You can use <testsuite_iterators.h> because the iterator types defined
> in there have deleted comma operators that should cause errors in
> these places.

Something like this (but in four separate tests):

#include <deque>
#include <list>
#include <vector>
#include <testsuite_iterators.h>

int main()
{
  using namespace __gnu_test;
  int a[1] = {};
  test_container<int, input_iterator_wrapper> t(a, a+1);

  std::deque<int> d;
  d.assign(t.begin(), t.end());

  std::list<int> l;
  l.assign(t.begin(), t.end());

  std::vector<int> v;
  v.assign(t.begin(), t.end());

  std::vector<bool> b;
  b.assign(t.begin(), t.end());
}


Given how rare it is for real code to overload the comma operator, and
that nobody has reported these bugs, I think this can wait for after
GCC 8.

Patch

diff --git a/libstdc++-v3/include/bits/deque.tcc b/libstdc++-v3/include/bits/deque.tcc
index fe96330..1337394 100644
--- a/libstdc++-v3/include/bits/deque.tcc
+++ b/libstdc++-v3/include/bits/deque.tcc
@@ -297,7 +297,7 @@  _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
 		    std::input_iterator_tag)
       {
         iterator __cur = begin();
-        for (; __first != __last && __cur != end(); ++__cur, ++__first)
+        for (; __first != __last && __cur != end(); ++__cur, (void)++__first)
           *__cur = *__first;
         if (__first == __last)
           _M_erase_at_end(__cur);
diff --git a/libstdc++-v3/include/bits/list.tcc b/libstdc++-v3/include/bits/list.tcc
index 22538c9..e90d957 100644
--- a/libstdc++-v3/include/bits/list.tcc
+++ b/libstdc++-v3/include/bits/list.tcc
@@ -312,7 +312,7 @@  _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
         iterator __first1 = begin();
         iterator __last1 = end();
         for (; __first1 != __last1 && __first2 != __last2;
-	     ++__first1, ++__first2)
+	     ++__first1, (void)++__first2)
           *__first1 = *__first2;
         if (__first2 == __last2)
           erase(__first1, __last1);
diff --git a/libstdc++-v3/include/bits/stl_bvector.h b/libstdc++-v3/include/bits/stl_bvector.h
index 05e9ff2..4b52c17 100644
--- a/libstdc++-v3/include/bits/stl_bvector.h
+++ b/libstdc++-v3/include/bits/stl_bvector.h
@@ -1229,7 +1229,7 @@  _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
 		      std::input_iterator_tag)
 	{
 	  iterator __cur = begin();
-	  for (; __first != __last && __cur != end(); ++__cur, ++__first)
+	  for (; __first != __last && __cur != end(); ++__cur, (void)++__first)
 	    *__cur = *__first;
 	  if (__first == __last)
 	    _M_erase_at_end(__cur);
diff --git a/libstdc++-v3/include/bits/vector.tcc b/libstdc++-v3/include/bits/vector.tcc
index 2516e35..f33da03 100644
--- a/libstdc++-v3/include/bits/vector.tcc
+++ b/libstdc++-v3/include/bits/vector.tcc
@@ -273,7 +273,7 @@  _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
       {
 	pointer __cur(this->_M_impl._M_start);
 	for (; __first != __last && __cur != this->_M_impl._M_finish;
-	     ++__cur, ++__first)
+	     ++__cur, (void)++__first)
 	  *__cur = *__first;
 	if (__first == __last)
 	  _M_erase_at_end(__cur);