Index: libcxx/src/filesystem/operations.cpp =================================================================== --- libcxx/src/filesystem/operations.cpp +++ libcxx/src/filesystem/operations.cpp @@ -1590,6 +1590,8 @@ --PP; if (PP.RawEntry.data() == __pn_.data()) return {}; + if (PP.State == PathParser::PS_InTrailingSep) + --PP; --PP; return createView(__pn_.data(), &PP.RawEntry.back()); } Index: libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.create_directories/create_directories.pass.cpp =================================================================== --- libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.create_directories/create_directories.pass.cpp +++ libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.create_directories/create_directories.pass.cpp @@ -150,6 +150,18 @@ fs::create_directories(path{})); } +TEST_CASE(dest_is_with_trailing_sep) { + scoped_test_env env; + const std::string dir_name = "dir1/dir2/dir3/"; + const path dir = env.make_env_path(dir_name); + TEST_CHECK(*dir.string().crbegin() == '/'); + TEST_CHECK(!exists(dir)); + std::error_code ec = GetTestEC(); + TEST_CHECK(fs::create_directories(dir, ec) == true); + TEST_CHECK(!ec); + TEST_CHECK(exists(dir)); +} + #ifdef _WIN32 TEST_CASE(nonexistent_root) {