https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113159
--- Comment #18 from Jan Engelhardt <jengelh at inai dot de> --- _GLIBCXX_DEBUG sounds good. Though, it can only be switched per TU so one would have to get even more creative to do something like void f(std::vector<int> &a, std::vector<int> &b) { // "I know I got this" std::sort(a.begin(), a.end(), [](int a, int b) { return a < b; }); // Trust no one auto uc = reinterpret_cast<bool (*)(int,int)>(dlsym(nullptr, "user_compare")); #define _GLIBCXX_DEBUG std::sort(b.begin(), b.end(), uc); #undef _GLIBCXX_DEBUG }