Skip to content

Commit db9ac24

Browse files
Remove non-Standard <experimental/filesystem> (#5765)
1 parent ce071fc commit db9ac24

File tree

18 files changed

+110
-107
lines changed

18 files changed

+110
-107
lines changed

stl/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ set(HEADERS
7373
${CMAKE_CURRENT_LIST_DIR}/inc/execution
7474
${CMAKE_CURRENT_LIST_DIR}/inc/expected
7575
${CMAKE_CURRENT_LIST_DIR}/inc/experimental/coroutine
76-
${CMAKE_CURRENT_LIST_DIR}/inc/experimental/filesystem
7776
${CMAKE_CURRENT_LIST_DIR}/inc/experimental/generator
7877
${CMAKE_CURRENT_LIST_DIR}/inc/experimental/resumable
7978
${CMAKE_CURRENT_LIST_DIR}/inc/filesystem

stl/inc/__msvc_all_public_headers.hpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
#endif // !defined(_SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING)
3030

3131
#define _SILENCE_CXX20_CISO646_REMOVED_WARNING
32-
#define _SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING
3332

3433
// Core STL Headers
3534
#include <bit>
@@ -155,9 +154,6 @@
155154
#include <cstdbool>
156155
#include <ctgmath>
157156

158-
// Non-Core Experimental Headers
159-
#include <experimental/filesystem>
160-
161157
#endif // !defined(_CORE_HEADERS_ONLY)
162158

163159
#ifndef _MSVC_TESTING_NVCC

stl/inc/__msvc_filebuf.hpp

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ _STL_DISABLE_CLANG_WARNINGS
1818
#pragma push_macro("new")
1919
#undef new
2020

21-
// TRANSITION, ABI: The _Path_ish functions accepting filesystem::path or experimental::filesystem::path are templates
21+
// TRANSITION, ABI: The _Path_ish functions accepting filesystem::path are templates
2222
// which always use the same types as a workaround for user code deriving from iostreams types and
2323
// __declspec(dllexport)ing the derived types. Adding member functions to iostreams broke the ABI of such DLLs.
2424
// Deriving and __declspec(dllexport)ing standard library types is not supported, but in this particular case
@@ -31,36 +31,6 @@ namespace filesystem {
3131
}
3232
#endif // _HAS_CXX17
3333

34-
#ifndef _FSTREAM_SUPPORTS_EXPERIMENTAL_FILESYSTEM
35-
#ifdef _M_CEE
36-
#define _FSTREAM_SUPPORTS_EXPERIMENTAL_FILESYSTEM 0
37-
#else // ^^^ defined(_M_CEE) / !defined(_M_CEE) vvv
38-
#define _FSTREAM_SUPPORTS_EXPERIMENTAL_FILESYSTEM 1
39-
#endif // ^^^ !defined(_M_CEE) ^^^
40-
#endif // _FSTREAM_SUPPORTS_EXPERIMENTAL_FILESYSTEM
41-
42-
#if _FSTREAM_SUPPORTS_EXPERIMENTAL_FILESYSTEM
43-
namespace experimental {
44-
namespace filesystem {
45-
inline namespace v1 {
46-
class path;
47-
}
48-
} // namespace filesystem
49-
} // namespace experimental
50-
#endif // _FSTREAM_SUPPORTS_EXPERIMENTAL_FILESYSTEM
51-
52-
template <class _Ty>
53-
constexpr bool _Is_any_path = _Is_any_of_v<_Ty
54-
#if _FSTREAM_SUPPORTS_EXPERIMENTAL_FILESYSTEM
55-
,
56-
experimental::filesystem::path
57-
#endif // _FSTREAM_SUPPORTS_EXPERIMENTAL_FILESYSTEM
58-
#if _HAS_CXX17
59-
,
60-
filesystem::path
61-
#endif // _HAS_CXX17
62-
>;
63-
6434
extern "C++" _CRTIMP2_PURE FILE* __CLRCALL_PURE_OR_CDECL _Fiopen(const char*, ios_base::openmode, int);
6535
extern "C++" _CRTIMP2_PURE FILE* __CLRCALL_PURE_OR_CDECL _Fiopen(const wchar_t*, ios_base::openmode, int);
6636

@@ -325,15 +295,6 @@ class basic_filebuf : public basic_streambuf<_Elem, _Traits> { // stream buffer
325295
return open(_Str.c_str(), _Mode, _Prot);
326296
}
327297

328-
#if _FSTREAM_SUPPORTS_EXPERIMENTAL_FILESYSTEM
329-
template <class _Path_ish = experimental::filesystem::path>
330-
basic_filebuf* open(
331-
const _Identity_t<_Path_ish>& _Path, ios_base::openmode _Mode, int _Prot = ios_base::_Default_open_prot) {
332-
// _Prot is an extension
333-
return open(_Path.c_str(), _Mode, _Prot);
334-
}
335-
#endif // _FSTREAM_SUPPORTS_EXPERIMENTAL_FILESYSTEM
336-
337298
#if _HAS_CXX17
338299
template <int = 0, class _Path_ish = filesystem::path>
339300
basic_filebuf* open(

stl/inc/fstream

Lines changed: 9 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,12 @@ public:
5454
const wstring& _Str, ios_base::openmode _Mode = ios_base::in, int _Prot = ios_base::_Default_open_prot)
5555
: basic_ifstream(_Str.c_str(), _Mode, _Prot) {} // extension
5656

57-
template <class _Ty, enable_if_t<_Is_any_path<_Ty>, int> = 0>
57+
#if _HAS_CXX17
58+
template <class _Ty, enable_if_t<is_same_v<_Ty, filesystem::path>, int> = 0>
5859
explicit basic_ifstream(
5960
const _Ty& _Path, ios_base::openmode _Mode = ios_base::in, int _Prot = ios_base::_Default_open_prot)
6061
: basic_ifstream(_Path.c_str(), _Mode, _Prot) {} // _Prot is an extension
62+
#endif // _HAS_CXX17
6163

6264
explicit basic_ifstream(FILE* _File) : _Mybase(_STD addressof(_Filebuffer)), _Filebuffer(_File) {} // extension
6365

@@ -102,15 +104,6 @@ public:
102104
open(_Str.c_str(), _Mode, _Prot);
103105
}
104106

105-
#if _FSTREAM_SUPPORTS_EXPERIMENTAL_FILESYSTEM
106-
template <class _Path_ish = experimental::filesystem::path>
107-
void open(const _Identity_t<_Path_ish>& _Path, ios_base::openmode _Mode = ios_base::in,
108-
int _Prot = ios_base::_Default_open_prot) {
109-
// _Prot is an extension
110-
open(_Path.c_str(), _Mode, _Prot);
111-
}
112-
#endif // _FSTREAM_SUPPORTS_EXPERIMENTAL_FILESYSTEM
113-
114107
#if _HAS_CXX17
115108
template <int = 0, class _Path_ish = filesystem::path>
116109
void open(const _Identity_t<_Path_ish>& _Path, ios_base::openmode _Mode = ios_base::in,
@@ -207,10 +200,12 @@ public:
207200
const wstring& _Str, ios_base::openmode _Mode = ios_base::out, int _Prot = ios_base::_Default_open_prot)
208201
: basic_ofstream(_Str.c_str(), _Mode, _Prot) {} // extension
209202

210-
template <class _Ty, enable_if_t<_Is_any_path<_Ty>, int> = 0>
203+
#if _HAS_CXX17
204+
template <class _Ty, enable_if_t<is_same_v<_Ty, filesystem::path>, int> = 0>
211205
explicit basic_ofstream(
212206
const _Ty& _Path, ios_base::openmode _Mode = ios_base::out, int _Prot = ios_base::_Default_open_prot)
213207
: basic_ofstream(_Path.c_str(), _Mode, _Prot) {} // _Prot is an extension
208+
#endif // _HAS_CXX17
214209

215210
explicit basic_ofstream(FILE* _File) : _Mybase(_STD addressof(_Filebuffer)), _Filebuffer(_File) {} // extension
216211

@@ -255,15 +250,6 @@ public:
255250
open(_Str.c_str(), _Mode, _Prot);
256251
}
257252

258-
#if _FSTREAM_SUPPORTS_EXPERIMENTAL_FILESYSTEM
259-
template <class _Path_ish = experimental::filesystem::path>
260-
void open(const _Identity_t<_Path_ish>& _Path, ios_base::openmode _Mode = ios_base::out,
261-
int _Prot = ios_base::_Default_open_prot) {
262-
// _Prot is an extension
263-
open(_Path.c_str(), _Mode, _Prot);
264-
}
265-
#endif // _FSTREAM_SUPPORTS_EXPERIMENTAL_FILESYSTEM
266-
267253
#if _HAS_CXX17
268254
template <int = 0, class _Path_ish = filesystem::path>
269255
void open(const _Identity_t<_Path_ish>& _Path, ios_base::openmode _Mode = ios_base::out,
@@ -365,10 +351,12 @@ public:
365351
int _Prot = ios_base::_Default_open_prot)
366352
: basic_fstream(_Str.c_str(), _Mode, _Prot) {} // extension
367353

368-
template <class _Ty, enable_if_t<_Is_any_path<_Ty>, int> = 0>
354+
#if _HAS_CXX17
355+
template <class _Ty, enable_if_t<is_same_v<_Ty, filesystem::path>, int> = 0>
369356
explicit basic_fstream(const _Ty& _Path, ios_base::openmode _Mode = ios_base::in | ios_base::out,
370357
int _Prot = ios_base::_Default_open_prot)
371358
: basic_fstream(_Path.c_str(), _Mode, _Prot) {} // _Prot is an extension
359+
#endif // _HAS_CXX17
372360

373361
explicit basic_fstream(FILE* _File) : _Mybase(_STD addressof(_Filebuffer)), _Filebuffer(_File) {} // extension
374362

@@ -414,15 +402,6 @@ public:
414402
open(_Str.c_str(), _Mode, _Prot);
415403
}
416404

417-
#if _FSTREAM_SUPPORTS_EXPERIMENTAL_FILESYSTEM
418-
template <class _Path_ish = experimental::filesystem::path>
419-
void open(const _Identity_t<_Path_ish>& _Path, ios_base::openmode _Mode = ios_base::in | ios_base::out,
420-
int _Prot = ios_base::_Default_open_prot) {
421-
// extension
422-
open(_Path.c_str(), _Mode, _Prot);
423-
}
424-
#endif // _FSTREAM_SUPPORTS_EXPERIMENTAL_FILESYSTEM
425-
426405
#if _HAS_CXX17
427406
template <int = 0, class _Path_ish = filesystem::path>
428407
void open(const _Identity_t<_Path_ish>& _Path, ios_base::openmode _Mode = ios_base::in | ios_base::out,
@@ -487,8 +466,6 @@ void swap(basic_fstream<_Elem, _Traits>& _Left, basic_fstream<_Elem, _Traits>& _
487466
}
488467
_STD_END
489468

490-
#undef _FSTREAM_SUPPORTS_EXPERIMENTAL_FILESYSTEM
491-
492469
#pragma pop_macro("new")
493470
_STL_RESTORE_CLANG_WARNINGS
494471
#pragma warning(pop)

stl/inc/yvals_core.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1911,8 +1911,6 @@ _EMIT_STL_ERROR(STL1004, "C++98 unexpected() is incompatible with C++23 unexpect
19111911
#define __cpp_lib_variant 202102L // P2162R2 Inheriting From variant
19121912
#endif
19131913

1914-
#define __cpp_lib_experimental_filesystem 201406L
1915-
19161914
#ifdef _RTC_CONVERSION_CHECKS_ENABLED
19171915
#ifndef _ALLOW_RTCc_IN_STL
19181916
#error /RTCc rejects conformant code, so it is not supported by the C++ Standard Library. Either remove this \

stl/src/filesys.cpp

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,32 @@
44
// filesys.cpp -- <experimental/filesystem> implementation
55
// (see filesystem.cpp for C++17 <filesystem> implementation)
66

7-
#define _SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING
7+
// TRANSITION, ABI: Everything in this file is preserved for binary compatibility.
88

99
#include <yvals.h>
1010

11+
#include <cstdint>
1112
#include <cstring>
1213
#include <direct.h>
13-
#include <experimental/filesystem>
1414
#include <io.h>
15+
#include <string>
1516

1617
#include <Windows.h>
1718

19+
#define _MAX_FILESYS_NAME 260 // longest Windows or Posix filename + 1
20+
21+
#define _FS_BEGIN \
22+
_STD_BEGIN \
23+
namespace experimental { \
24+
namespace filesystem { \
25+
inline namespace v1 {
26+
27+
#define _FS_END \
28+
} \
29+
} \
30+
} \
31+
_STD_END
32+
1833
#ifdef _M_CEE_PURE
1934
#define __crtGetTempPath2W(BufferLength, Buffer) GetTempPathW(BufferLength, Buffer)
2035
#else // vvv !defined(_M_CEE_PURE) vvv
@@ -23,6 +38,53 @@ extern "C" _Success_(return > 0 && return < BufferLength) DWORD __stdcall __crtG
2338
#endif // ^^^ !defined(_M_CEE_PURE) ^^^
2439

2540
_FS_BEGIN
41+
42+
enum class file_type { // names for file types
43+
not_found = -1,
44+
none,
45+
regular,
46+
directory,
47+
symlink,
48+
block,
49+
character,
50+
fifo,
51+
socket,
52+
unknown
53+
};
54+
55+
enum class perms { // names for permissions
56+
none = 0,
57+
owner_read = 0400, // S_IRUSR
58+
owner_write = 0200, // S_IWUSR
59+
owner_exec = 0100, // S_IXUSR
60+
owner_all = 0700, // S_IRWXU
61+
group_read = 040, // S_IRGRP
62+
group_write = 020, // S_IWGRP
63+
group_exec = 010, // S_IXGRP
64+
group_all = 070, // S_IRWXG
65+
others_read = 04, // S_IROTH
66+
others_write = 02, // S_IWOTH
67+
others_exec = 01, // S_IXOTH
68+
others_all = 07, // S_IRWXO
69+
all = 0777,
70+
set_uid = 04000, // S_ISUID
71+
set_gid = 02000, // S_ISGID
72+
sticky_bit = 01000, // S_ISVTX
73+
mask = 07777,
74+
unknown = 0xFFFF,
75+
add_perms = 0x10000,
76+
remove_perms = 0x20000,
77+
resolve_symlinks = 0x40000
78+
};
79+
80+
_BITMASK_OPS(_EMPTY_ARGUMENT, perms)
81+
82+
struct space_info { // space information for a file
83+
uintmax_t capacity;
84+
uintmax_t free;
85+
uintmax_t available;
86+
};
87+
2688
static file_type _Map_mode(int _Mode) { // map Windows file attributes to file_status
2789
constexpr int _File_attribute_regular =
2890
FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_COMPRESSED | FILE_ATTRIBUTE_ENCRYPTED | FILE_ATTRIBUTE_HIDDEN

stl/src/filesystem.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
33

44
// filesystem.cpp -- C++17 <filesystem> implementation
5-
// (see filesys.cpp for <experimental/filesystem> implementation)
65

76
#include <clocale>
87
#include <corecrt_terminate.h>

stl/inc/experimental/filesystem renamed to tests/std/include/experimental_filesystem.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
// Copyright (c) Microsoft Corporation.
44
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
55

6+
// ********************************************************************************************************************
7+
// * This was previously shipped in product code as <experimental/filesystem>. *
8+
// * It's now preserved in cryostasis for test code to exercise functions that are retained for binary compatibility. *
9+
// * This file should generally not be changed, except to fix compiler warnings/errors and to update clang-format. *
10+
// ********************************************************************************************************************
11+
612
#ifndef _EXPERIMENTAL_FILESYSTEM_
713
#define _EXPERIMENTAL_FILESYSTEM_
814
#include <yvals_core.h>
Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,31 @@
11
// Copyright (c) Microsoft Corporation.
22
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
33

4+
#define _SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING
5+
46
#include <__msvc_all_public_headers.hpp>
57
#include <cassert>
68

7-
namespace fs = std::experimental::filesystem;
9+
#include "experimental_filesystem.hpp"
810

911
int meow();
1012

11-
inline bool test_wchar_t_minus() {
12-
// Test for DevDiv-1004799: <filesystem>: /Zc:wchar_t- fails. Calling file_size
13-
// should cause the failure to occur if we are wchar_t incorrect. Test is disabled
14-
// (i.e. always passes) if compiled with /clr:pure and /Zc:wchar_t-, as it triggers
15-
// LNK2031: calling convention missing in metadata errors, which are irrelevant here.
16-
#if defined(_M_CEE_PURE) && !defined(_NATIVE_WCHAR_T_DEFINED)
17-
return true;
18-
#else // ^^^ /clr:pure /Zc:wchar_t- / Other vvv
19-
return fs::file_size(fs::current_path() / "Dev09_172666_tr1_tuple_odr.exe") != 0u;
20-
#endif // defined(_M_CEE_PURE) && !defined(_NATIVE_WCHAR_T_DEFINED)
21-
}
22-
2313
int main() {
2414
assert(meow() == 1729);
25-
assert(test_wchar_t_minus());
15+
16+
// Test for DevDiv-1004799: <filesystem>: /Zc:wchar_t- fails.
17+
// Calling file_size should cause the failure to occur if we are wchar_t incorrect.
18+
#if defined(_M_CEE_PURE) && !defined(_NATIVE_WCHAR_T_DEFINED)
19+
// Test is disabled if compiled with /clr:pure and /Zc:wchar_t-, as it triggers
20+
// LNK2031: calling convention missing in metadata errors, which are irrelevant here.
21+
#else // ^^^ workaround / no workaround vvv
22+
{
23+
namespace fs = std::experimental::filesystem;
24+
assert(fs::file_size(fs::current_path() / "Dev09_172666_tr1_tuple_odr.exe") != 0u);
25+
}
26+
27+
#if _HAS_CXX17
28+
assert(std::filesystem::file_size(std::filesystem::current_path() / "Dev09_172666_tr1_tuple_odr.exe") != 0u);
29+
#endif // _HAS_CXX17
30+
#endif // ^^^ no workaround ^^^
2631
}

tests/std/tests/Dev11_0000000_null_forward_iterators/test.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#include <cassert>
99
#include <cstring>
1010
#include <deque>
11-
#include <experimental/filesystem>
1211
#include <forward_list>
1312
#include <iterator>
1413
#include <list>
@@ -31,6 +30,8 @@
3130
#include <span>
3231
#endif // _HAS_CXX20
3332

33+
#include "experimental_filesystem.hpp"
34+
3435
using namespace std;
3536

3637
// N3797 24.2.5 [forward.iterators]/2:

0 commit comments

Comments
 (0)