diff --git a/libcxx/test/support/filesystem_test_helper.h b/libcxx/test/support/filesystem_test_helper.h --- a/libcxx/test/support/filesystem_test_helper.h +++ b/libcxx/test/support/filesystem_test_helper.h @@ -296,14 +296,17 @@ // sharing the same cwd). However, it is fairly unlikely to happen as // we generally don't use scoped_test_env from multiple threads, so // this is deemed acceptable. + // The cwd.filename() itself isn't unique across all tests in the suite, + // so start the numbering from a hash of the full cwd, to avoid + // different tests interfering with each other. static inline fs::path available_cwd_path() { fs::path const cwd = utils::getcwd(); fs::path const tmp = fs::temp_directory_path(); - fs::path const base = tmp / cwd.filename(); - int i = 0; - fs::path p = base / ("static_env." + std::to_string(i)); + std::string base = cwd.filename().string(); + size_t i = std::hash()(cwd.string()); + fs::path p = tmp / (base + "-static_env." + std::to_string(i)); while (utils::exists(p.string())) { - p = fs::path(base) / ("static_env." + std::to_string(++i)); + p = tmp / (base + "-static_env." + std::to_string(++i)); } return p; }