P0418R2 removed some preconditions from std::atomic::compare_exchange_* but we still enforce them via __glibcxx_assert. This removes those assertions. Signed-off-by: Jonathan Wakely libstdc++-v3/ChangeLog: PR c++/102177 * include/bits/atomic_base.h (__is_valid_cmpexch_failure_order): New function to check if a memory order is valid for the failure case of compare exchange operations. (__atomic_base::compare_exchange_weak): Simplify assertions by using __is_valid_cmpexch_failure_order. (__atomic_base::compare_exchange_strong): Likewise. (__atomic_base::compare_exchange_weak): Likewise. (__atomic_base::compare_exchange_strong): Likewise. (__atomic_impl::compare_exchange_weak): Add assertion. (__atomic_impl::compare_exchange_strong): Likewise. * include/std/atomic (atomic::compare_exchange_weak): Likewise. (atomic::compare_exchange_strong): Likewise. Tested x86_64-linux. Committed to trunk. I think we should backport this to gcc-11 too, as it was a C++17 change and these assertions fail for valid (if questionable) C++17 programs.