Is this bit of code safe?
int main() {
struct {
int foo;
int bar;
std::list<...>::iterator it;
} foobar;
memset(&foobar, 0, sizeof(foobar));
foobar.it = ...;
}
I’m thinking it’s safe because std::iterator doesn’t seem to override operator=. Is this a valid reasoning?
No. Assignment operator generally assumes that its left-hand side (recipient) operand has a valid state before assignment.
Meanwhile, you are steamrolling these zeros over possibly non-trivially constructed object of
std::list<...>::iteratortype. This can only work what you have intimate knowledge about the exact properties ofstd::list<...>::iteratorand you know that filling it with zeros produces a valid object.