Re:Don’t blindly prefer emplace_back to push_back
by CJefferson on Thursday March 04, 2021 @11:14AM
(#26344237)
In that case, push_back to emplace_back changed the semantics (as construct + push_back made a move construction, whereas emplace_back did not).
Re:Don’t blindly prefer emplace_back to push_back
by shawnz on Thursday March 04, 2021 @11:19AM
(#26344319)
Good point, it doesn't seem to be any bigger of a change than the original suggestion. Perhaps they mistakenly thought nobody would call emplace_back in that way by accident.
Re:Don’t blindly prefer emplace_back to push_back
by oleganza on Thursday March 04, 2021 @11:18AM
(#26344288)
The warning was not explicit enough to ask you to remove the constructor as well as changing the method name. If it called for "hey, you can remove the constructor and emplace_back would automagically call it for you in place!" and then checked that the constructor is not spelled out there, then there would not be such issue and the tool would be 100% helpful.
Re:Don’t blindly prefer emplace_back to push_back
by shawnz on Thursday March 04, 2021 @11:20AM
(#26344327)
It did ask to remove the constructor as well as changing the method (note which parts are covered by tildes).
My question is, after having incorrectly only done one of those things, how could it have known that the user was only halfway though a two-part operation and didn't actually mean for it to be that way? Clang doesn't know how the code was in the past.
The student accidentally changed the semantics by adding the extra call to the copy contstructor, and therefore Clang didn't know anymore that it could be removed