Roughly, a bug in a compiler happens when it exhibits behavior that is forbidden by the standard (either explicitly or implicitly), or behavior that diverges from the documentation of said compiler.
The standard imposes no restrictions on the format of native path strings, except that the format should be accepted by the underlying operating system (quote below). How could it impose such restrictions? The language has no say in how paths are handled by the host OS, and to do it confidently it would have to know every single target it may be compiled to, which is clearly not feasible.
5 A pathname is a character string that represents the name of a path.
Pathnames are formatted according to the generic pathname format grammar ([fs.path.generic]) or according to an operating system dependent native pathname format accepted by the host operating system.
(Emphasis mine)
The documentation of MSVC implies that the forward slash is perfectly acceptable as a separator:
Common to both systems is the structure imposed on a pathname once you get past the root name. For the pathname c:/abc/xyz/def.ext:
- The root name is
c:
.
- The root directory is
/
.
- The root path is
c:/
.
- The relative path is
abc/xyz/def.ext
.
- The parent path is
c:/abc/xyz
.
- The filename is
def.ext
.
- The stem is
def
.
- The extension is
.ext
.
It does mention a preferred separator, but this really only implies the behavior of std::make_preferred
, and not of the default path output:
A minor difference is the preferred separator, between the sequence of directories in a pathname. Both operating systems let you write a forward slash /
, but in some contexts Windows prefers a backslash \
.
The question of whether this is a bug, then, is easy: Since the standard imposes no restrictions on the behavior, and the compiler's documentation implies no mandatory need for a backward slash, there can be no bug.
Left is the question of whether this is a quality of implementation issue. After all, compiler and library implementers are expected to know all quirks about their target, and implement features accordingly.
It's up for debate which slash ('\'
or '/'
) you should use in Windows, or whether it really matters at all, so there can be no authoritative answer. Any answer that advocates for one or the other must be very careful to not be too much opinion-based. Also, the mere existence of path::make_preferred
indicates that the native path is not necessarily the preferred one. Consider the zero-overhead principle: Making the path always be the preferred one would incur an overhead on the people who don't need to be that pedantic when handling paths.
Finally, the std::experimental
namespace is what it says on the box: You shouldn't expect the final standardized library to behave the same as its experimental version, or even expect that a final standardized library will exist at all. It's just the way it is, when dealing with experimental stuff.
std::filesystem
even supposed to support paths with forward-slashes on Windows? Can you provide an example in which the actually paths only have backslahes? – Bonita<filesystem>
is Microsoft specific as stated here. – Ifnistd::experimental
is that you're supposed to expect the final version to behave differently and be willing to live with the final differences. – Pryorpath::make_preferred()
to convert any foreslashes to backslashes. – Orffstd::filesystem
was not finalized (while there is no updated post yet, as far as I'm aware of). When compiling in VS15.8 withstd=c++17
, the included header states// filesystem standard header
. – Deliver\
as a path separator and/
as a command-line option prefix because most of the original MS-DOS utilities came from IBM, which used/
for command-line switches, and MS-DOS 1.0 (as PC-DOS 1.0) didn't support directories. In MS-DOS 2.0 & later, they kept/
for backwards compatibility, and introduced\
for paths because it was visually similar to the Unix/
; I think 2.0 also accepted\
as a path separator right from the start, but I'm not sure. Either way, whenever it was added, it was mainly for consistency with Unix syntax IIRC.) – Brackett/
path separator is pretty normal for filesystem paths in Windows. At some point they even started supporting Tab-competion for/
-separated paths in cmd.exe. – Ascent