From 11749095a1e9a9e5296676fbc4b174faeb04765e Mon Sep 17 00:00:00 2001 From: Danila Kutenin Date: Thu, 9 Dec 2021 21:07:29 +0000 Subject: [PATCH] Make idl_parser deterministic (#6976) * Make idl_parser deterministic Some golden tests even exercise this [logic](https://github.com/google/flatbuffers/blob/df2df21ec1be2468106fed10c1533eacc1cf0d2e/tests/prototest/test.golden#L8). Let's make the parser fully stable not depending on the implementation of std::sort * Retry the ci --- src/idl_parser.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/idl_parser.cpp b/src/idl_parser.cpp index d51dc3827..9684fbfde 100644 --- a/src/idl_parser.cpp +++ b/src/idl_parser.cpp @@ -2152,10 +2152,16 @@ void EnumDef::SortByValue() { auto &v = vals.vec; if (IsUInt64()) std::sort(v.begin(), v.end(), [](const EnumVal *e1, const EnumVal *e2) { + if (e1->GetAsUInt64() == e2->GetAsUInt64()) { + return e1->name < e2->name; + } return e1->GetAsUInt64() < e2->GetAsUInt64(); }); else std::sort(v.begin(), v.end(), [](const EnumVal *e1, const EnumVal *e2) { + if (e1->GetAsInt64() == e2->GetAsInt64()) { + return e1->name < e2->name; + } return e1->GetAsInt64() < e2->GetAsInt64(); }); }