diff --git a/ipc/glue/IPCMessageUtilsSpecializations.h b/ipc/glue/IPCMessageUtilsSpecializations.h index 0a80bc8cb863..43026594cbe9 100644 --- a/ipc/glue/IPCMessageUtilsSpecializations.h +++ b/ipc/glue/IPCMessageUtilsSpecializations.h @@ -536,20 +536,23 @@ struct ParamTraits> { struct VariantReader { using Next = VariantReader; - static bool Read(MessageReader* reader, Tag tag, paramType* result) { - // Since the VariantReader specializations start at N , we need to - // subtract one to look at N - 1, the first valid tag. This means our - // comparisons are off by 1. If we get to N = 0 then we have failed to - // find a match to the tag. - if (tag == N - 1) { - // Recall, even though the template parameter is N, we are - // actually interested in the N - 1 tag. - // Default construct our field within the result outparameter and - // directly deserialize into the variant. Note that this means that - // every type in Ts needs to be default constructible - return ReadParam(reader, &result->template emplace()); + // Since the VariantReader specializations start at N , we need to + // subtract one to look at N - 1, the first valid tag. This means our + // comparisons are off by 1. If we get to N = 0 then we have failed to + // find a match to the tag. + static constexpr size_t Idx = N - 1; + using T = typename mozilla::detail::Nth::Type; + + static ReadResult Read(MessageReader* reader, Tag tag) { + if (tag == Idx) { + auto p = ReadParam(reader); + if (p) { + return ReadResult( + std::in_place, mozilla::VariantIndex{}, std::move(*p)); + } + return {}; } else { - return Next::Read(reader, tag, result); + return Next::Read(reader, tag); } } @@ -560,17 +563,17 @@ struct ParamTraits> { // a matching tag. template struct VariantReader<0, dummy> { - static bool Read(MessageReader* reader, Tag tag, paramType* result) { - return false; + static ReadResult Read(MessageReader* reader, Tag tag) { + return {}; } }; - static bool Read(MessageReader* reader, paramType* result) { + static ReadResult Read(MessageReader* reader) { Tag tag; if (ReadParam(reader, &tag)) { - return VariantReader::Read(reader, tag, result); + return VariantReader::Read(reader, tag); } - return false; + return {}; } };