Fix filesystem::path assignment from {}
Adding `path::operator=(string_type&&)` made the expression `p = {}`
ambiguous. This path fixes that ambiguity by making the `string&&`
overload a template so it ranks lower during overload resolution.
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@292345 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/experimental/filesystem b/include/experimental/filesystem
index 739918b..f934f7b 100644
--- a/include/experimental/filesystem
+++ b/include/experimental/filesystem
@@ -720,6 +720,7 @@
return *this;
}
+ template <class = void>
_LIBCPP_INLINE_VISIBILITY
path& operator=(string_type&& __s) _NOEXCEPT {
__pn_ = _VSTD::move(__s);
diff --git a/test/std/experimental/filesystem/class.path/path.member/path.assign/braced_init.pass.cpp b/test/std/experimental/filesystem/class.path/path.member/path.assign/braced_init.pass.cpp
new file mode 100644
index 0000000..c5da52f
--- /dev/null
+++ b/test/std/experimental/filesystem/class.path/path.member/path.assign/braced_init.pass.cpp
@@ -0,0 +1,32 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++98, c++03
+
+// <experimental/filesystem>
+
+// class path
+
+// path& operator=(path const&);
+
+#include <experimental/filesystem>
+#include <type_traits>
+#include <cassert>
+
+#include "test_macros.h"
+#include "count_new.hpp"
+
+namespace fs = std::experimental::filesystem;
+
+int main() {
+ using namespace fs;
+ path p("abc");
+ p = {};
+ assert(p.native() == "");
+}
diff --git a/test/std/experimental/filesystem/class.path/path.member/path.assign/source.pass.cpp b/test/std/experimental/filesystem/class.path/path.member/path.assign/source.pass.cpp
index 9e48cbf..987c873 100644
--- a/test/std/experimental/filesystem/class.path/path.member/path.assign/source.pass.cpp
+++ b/test/std/experimental/filesystem/class.path/path.member/path.assign/source.pass.cpp
@@ -15,6 +15,7 @@
// template <class Source>
// path& operator=(Source const&);
+// path& operator=(string_type&&);
// template <class Source>
// path& assign(Source const&);
// template <class InputIterator>
@@ -213,12 +214,29 @@
}
}
+void RunStringMoveTest(const char* Expect) {
+ using namespace fs;
+ std::string ss(Expect);
+ path p;
+ {
+ DisableAllocationGuard g; ((void)g);
+ path& pr = (p = std::move(ss));
+ assert(&pr == &p);
+ }
+ assert(p == Expect);
+ {
+ // Signature test
+ ASSERT_NOEXCEPT(p = std::move(ss));
+ }
+}
+
int main() {
for (auto const& MS : PathList) {
RunTestCase<char>(MS);
RunTestCase<wchar_t>(MS);
RunTestCase<char16_t>(MS);
RunTestCase<char32_t>(MS);
+ RunStringMoveTest(MS);
}
test_sfinae();
}