Relands #171489 which was reverted due to a test failure on GreenDragon. As suggested in https://github.com/llvm/llvm-project/pull/171489#issuecomment-3754098800, I'm checking for `std::string` on Darwin and `std::basic_string<char>` otherwise, however I can't test that locally.