diff --git a/src/cc/usdt/usdt.cc b/src/cc/usdt/usdt.cc index bd3f26517127..e3d0c4417e37 100644 --- a/src/cc/usdt/usdt.cc +++ b/src/cc/usdt/usdt.cc @@ -220,6 +220,10 @@ void Probe::add_location(uint64_t addr, const std::string &bin_path, const char } void Probe::finalize_locations() { + // The following comparator needs to establish a strict weak ordering relation. Such + // that when x < y == true, y < x == false. Otherwise it leads to undefined behavior. + // To guarantee this, it uses std::tie which allows the lambda to have a lexicographical + // comparison and hence, guarantee the strict weak ordering. std::sort(locations_.begin(), locations_.end(), [](const Location &a, const Location &b) { return std::tie(a.bin_path_, a.address_) < std::tie(b.bin_path_, b.address_);