1

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?

cppbest
  • 59
  • 8

1 Answers1

2

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.

BoP
  • 2,310
  • 1
  • 15
  • 24
  • Does it mean that GCC and Clang are non-conforming? If so, are there any bug reports? – cppbest Sep 19 '22 at 14:03
  • @cppbest: For there to be bug reports, someone would have to actually *use* the `istream_iterator` types. And on top of that, they'd have to write some code that actually cares about the triviality of this type. So a vanishingly small percentage of a vanishingly small percentage of programmers. – Nicol Bolas Sep 19 '22 at 14:15
  • 2
    @cppbest See [LWG3600](https://cplusplus.github.io/LWG/issue3600). The maintainers of libstdc++ thought that the current requirements is unimplementable without ABI break, so they refused to make such change. – F.v.S. Sep 28 '22 at 04:06