Search code examples
c++constructorlanguage-lawyertrivially-copyable

Is std::istream_iterator<int> trivially copy constuctible?


Why does this program compile on MSVC but not on GCC and Clang? godbolt

#include <iterator>
#include <type_traits>

static_assert(std::is_trivially_copy_constructible_v<std::istream_iterator<int>>);

According to [istream.iterator.cons]/6, the constructor must be trivial. Does it relate to P0738 which moves the wording from Effects to Remarks?


Solution

  • Seems like there is a difference in implementation. The gcc library has a copy constructor

      istream_iterator(const istream_iterator& __obj)
      : _M_stream(__obj._M_stream), _M_value(__obj._M_value),
        _M_ok(__obj._M_ok)
      { }
    

    which is non-trivial.

    MSVC does not, and apparently relies on a compiler generated one.