https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70029
--- Comment #4 from Marek Polacek <mpolacek at gcc dot gnu.org> --- In other words, build_ref_qualified_type creates method_type T with TYPE_CANONICAL (t) = t; but TYPE_MAIN_VARIANT (t) is not t (it differs because the main variant doesn't have FUNCTION_RVALUE_QUALIFIED and FUNCTION_REF_QUALIFIED flags set and has a different canonical type). Using build_distinct_type_copy instead of build_variant_type_copy fixes the ICE but causes another ICEs, so that is wrong, but I don't know what to do with this.