You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
array.sort behavior can differ between MSVC and GCC compilers #1347
I've noticed this behaved differently between the compilers.
On MSVC, sorting results in [0,0,1000,null,800,801,802,850,850,900,1000,1001,10000,10000,10000], but on GCC the same array instead becomes [0,0,850,1000,null,800,801,802,850,900,1000,1001,10000,10000,10000].
It's a minimal recreation of how objects in a game's scene are ordered, which also caused a bug.
While it uncovers a flaw with how the game's sorting objects, I considered that the discrepancy in how the sorting behaved between compilers could be a bug.
This will be because your comparison function doesn't adhere to "weak strict ordering", under the hood hxcpp's array sort uses std::sort which has this requirement. Using a comparison function which doesn't follow this is undefined behaviour per the cpp spec, this can result in inconsistent results, random values in the results, or crashes.
We discovered this during some coroutine work and I think we decided to make haxe follow the same requirements, but seems we forgot to update the docs.
Activity
Aidan63 commentedon Jun 8, 2026
This will be because your comparison function doesn't adhere to "weak strict ordering", under the hood hxcpp's array sort uses
std::sortwhich has this requirement. Using a comparison function which doesn't follow this is undefined behaviour per the cpp spec, this can result in inconsistent results, random values in the results, or crashes.https://en.cppreference.com/cpp/named_req/Compare
We discovered this during some coroutine work and I think we decided to make haxe follow the same requirements, but seems we forgot to update the docs.
tobil4sk commentedon Oct 30, 2026
Looks like this PR was related: #1416. Seems haxe docs have still not been updated
Also, for more context, here was the hxcoro discussion: Aidan63/haxe#154 (comment)
This is also a duplicate of #961.