samedi 26 novembre 2016

`push_back` vs. `emplace_back` sign warning

I noticed when using Apple's clang - release (703.0.31) - that pushing a [signed] int onto a std::vector<unsigned int> via the push_back method would raise a warning about implicit sign conversion. I was satisfied with this, given the warning flags, but surprised that replacing it with the emplace_back method did not produce a warning.

I tested this with godbolt, and clang 3.9.0 exhibits the same behaviour. gcc 6.2 does not produce a warning in either case.

Since an implicit sign conversion is not (AFAIK) required behaviour, I would hesitate to call it a bug, but I am curious if I'm overlooking some edge case that explains (or complicates!) the exhibited behaviour.

Aucun commentaire:

Enregistrer un commentaire