diff --git a/stl/inc/filesystem b/stl/inc/filesystem index a2f4bd1dd09..da6f941f9c6 100644 --- a/stl/inc/filesystem +++ b/stl/inc/filesystem @@ -3750,6 +3750,11 @@ namespace filesystem { // FUNCTION create_directories inline bool create_directories(const path& _Path, error_code& _Ec) { + if (_Path.empty()) { + _Ec = _Make_ec(__std_win_error::_Path_not_found); + return false; + } + _Ec.clear(); // for exception safety const wstring& _Text = _Path.native(); wstring _Tmp; diff --git a/tests/std/tests/P0218R1_filesystem/test.cpp b/tests/std/tests/P0218R1_filesystem/test.cpp index df813ffa2a1..0ff4f084c32 100644 --- a/tests/std/tests/P0218R1_filesystem/test.cpp +++ b/tests/std/tests/P0218R1_filesystem/test.cpp @@ -3669,6 +3669,11 @@ void test_create_dirs_and_remove_all() { remove_all(badPath, ec); EXPECT(good(ec)); + // test GH-1283 create_directories() should throw for empty paths + EXPECT(throws_filesystem_error([] { create_directories(path{}); }, "create_directories", path{})); + EXPECT(create_directories(path{}, ec) == false); + EXPECT(bad(ec)); + // test that normalization isn't done first auto dots = r / L"a/../b/../c"sv; EXPECT(create_directories(dots));