Yet another GCC bug?

Правка en2, от lyyllyyl, 2016-09-09 19:12:13

I was learning some builtin functions in STL. And I wrote these code.

#include <bits/stdc++.h>

int main() {
  std::deque<int> tmp{1, 2, 3};
  std::transform(tmp.begin(), tmp.end(), std::back_insert_iterator<std::deque<int>>(tmp), std::negate<>());
  std::copy(tmp.begin(), tmp.end(), std::ostream_iterator<int> (std::cout, "\n"));

  std::vector<int> now{1, 2, 3};
  std::transform(now.begin(), now.end(), std::back_insert_iterator<std::vector<int>>(now), std::negate<>());
  std::copy(now.begin(), now.end(), std::ostream_iterator<int> (std::cout, "\n"));
  return 0;
}

And I compile this code, with GCC 6.1.1, option -Wall -std=c++14. The the output of the code was:

1 2 3 -1 -2 -3 1 2 3 -1 0 -3

In my opinion, the 0 in the output should be 2. Am I wrong? If I use the back_insert_iterator wrong, please point it out. Thank you. If not, is this a bug for GCC 6.1.1? Feel free to compile this code on your own computer with different compiler and share your result. Thank you for the help. :)

Теги gcc, bug, compiler, stl

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en5 Английский lyyllyyl 2016-09-09 19:48:33 10
en4 Английский lyyllyyl 2016-09-09 19:47:38 116 Tiny change: 'location. CLOSED\n\n' -
en3 Английский lyyllyyl 2016-09-09 19:12:58 1 Tiny change: 'should be 2. Am I wr' -> 'should be -2. Am I wr'
en2 Английский lyyllyyl 2016-09-09 19:12:13 127 (published)
en1 Английский lyyllyyl 2016-09-09 19:10:00 950 Initial revision (saved to drafts)