================
@@ -110,7 +110,8 @@ std::map<SummaryName, JSONFormat::FormatInfo>
JSONFormat::initFormatInfos() {
std::map<SummaryName, FormatInfo> FormatInfos;
for (const auto &FormatInfoEntry : llvm::Registry<FormatInfo>::entries()) {
std::unique_ptr<FormatInfo> Info = FormatInfoEntry.instantiate();
- bool Inserted = FormatInfos.try_emplace(Info->ForSummary, *Info).second;
+ bool Inserted =
+ FormatInfos.try_emplace(Info->ForSummary, std::move(*Info)).second;
----------------
steakhal wrote:
I was looking at this `std::move` and I was worried about it.
In `try_emplace` the "key" is taken as a const ref. We also convert
(potentially consume) the "*Info" - the object that happens to be the target of
the const ref representing the key.
Consequently, if the code could move out the guts of "*Info" before the "key"
is used, we would end up with an empty string (because a moved-from std::string
is well-specified to be empty - that's our luck, otherwise it would be UB with
a user-after-move for other types).
I don't think any implementation would put the key into the map after moving in
the data - but technically they could how I read the standard. So I'd opt for
not having this `std::move` here.
https://github.com/llvm/llvm-project/pull/184037
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits