https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108221
--- Comment #16 from CVS Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Jonathan Wakely <r...@gcc.gnu.org>: https://gcc.gnu.org/g:769fae76dfd71045fe062e7b1edef0f59e50371d commit r13-5080-g769fae76dfd71045fe062e7b1edef0f59e50371d Author: Jonathan Wakely <jwak...@redhat.com> Date: Mon Jan 9 10:45:31 2023 +0000 libstdc++: Fix some algos for 16-bit size_t [PR108221] Some standard algorithms fail to compile when size_t or ptrdiff_t is narrower than int. The __lg helper function is ambiguous if ptrdiff_t is short or __int20, so replace it with a function template that works for those types as well as signed/unsigned int/long/long long. The helpers for stable_sort perform arithmetic on size values and assume the types won't change, which isn't true if the type promotes to int. libstdc++-v3/ChangeLog: PR libstdc++/108221 * include/bits/stl_algobase.h (__lg): Replace six overloads with a single function template for all integer types. * include/bits/stl_algo.h (__merge_adaptive_resize): Cast arithmetic results back to _Distance.