[libcxx-commits] [PATCH] D91138: [6/N] [libcxx] Handle backslash as path separator on windows

Martin Storsjö via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Tue Dec 1 23:10:10 PST 2020


mstorsjo added inline comments.


================
Comment at: libcxx/include/filesystem:1122
+#if defined(_LIBCPP_WIN32API)
+    std::replace(__pn_.begin(), __pn_.end(), '/', '\\');
+#endif
----------------
amccarth wrote:
> 1.  It looks like most places are using `preferred_separator`, so is there a ever case where you'd have slashes instead of backslashes?
> 
> 2.  If I've read correctly, the Windows version always uses wide characters, so maybe the character literals should be `L'/'` and `L'\\'` so that they naturally match the value type of the iterator.
1. Yes, the thing is that when a user constructs a path from a string that itself contains path separators, forward slashes are always considered a path separator (as platform agnostic separator), and backslashes work as separator too, on windows only. The filesystem::path internal representation of a path keeps them in whatever form they were input, but this modifier converts the path to the preferred (native) form. FWIW this is exactly what MS STL's version of make_preferred() does too.
2. Sure, that'd work. For these cases, the plain char form doesn't produce any warnings, but I can change it to wide char literals just for clarity.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D91138/new/

https://reviews.llvm.org/D91138



More information about the libcxx-commits mailing list