To implement my own std::forward_iterator I must provide a default constructor for the type, since it must satisfy concept std::sentinel_for -> std::semiregular -> std::default_initializable, but actually this constructor is never used by ranges library and compiler even optimizes it out.
Am I correct in thinking that the default constructed iterator could contain any garbage, including inconsistent state of the object, since this object will never be constructed and its usage is always leads to undefined behaviour or there are some specific requirements to such iterators (like “to be valid”, “point to end()”, etc.)?
My problem is that for my iterator I can’t create consistent state if is default initialized.
It would be nice to have some reference to documentation to be sure that this is safe of not safe.
In general, you need to ensure that all default-constructed forward iterators compare equal to each other.
[iterator.concept.forward]:
For a class with a user-defined default constructor, value-initialization is equivalent to default-initialization. Otherwise, value-initialization is equivalent to zero-initialization followed by default-initialization. ([dcl.init.general]/9)