[libcxx] r292345 - Fix filesystem::path assignment from {}

Eric Fiselier via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 17 21:48:56 PST 2017


Author: ericwf
Date: Tue Jan 17 23:48:55 2017
New Revision: 292345

URL: http://llvm.org/viewvc/llvm-project?rev=292345&view=rev
Log:
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.

Added:
    libcxx/trunk/test/std/experimental/filesystem/class.path/path.member/path.assign/braced_init.pass.cpp
Modified:
    libcxx/trunk/include/experimental/filesystem
    libcxx/trunk/test/std/experimental/filesystem/class.path/path.member/path.assign/source.pass.cpp

Modified: libcxx/trunk/include/experimental/filesystem
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/experimental/filesystem?rev=292345&r1=292344&r2=292345&view=diff
==============================================================================
--- libcxx/trunk/include/experimental/filesystem (original)
+++ libcxx/trunk/include/experimental/filesystem Tue Jan 17 23:48:55 2017
@@ -720,6 +720,7 @@ public:
         return *this;
     }
 
+    template <class = void>
     _LIBCPP_INLINE_VISIBILITY
     path& operator=(string_type&& __s) _NOEXCEPT {
         __pn_ = _VSTD::move(__s);

Added: libcxx/trunk/test/std/experimental/filesystem/class.path/path.member/path.assign/braced_init.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/experimental/filesystem/class.path/path.member/path.assign/braced_init.pass.cpp?rev=292345&view=auto
==============================================================================
--- libcxx/trunk/test/std/experimental/filesystem/class.path/path.member/path.assign/braced_init.pass.cpp (added)
+++ libcxx/trunk/test/std/experimental/filesystem/class.path/path.member/path.assign/braced_init.pass.cpp Tue Jan 17 23:48:55 2017
@@ -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() == "");
+}

Modified: libcxx/trunk/test/std/experimental/filesystem/class.path/path.member/path.assign/source.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/experimental/filesystem/class.path/path.member/path.assign/source.pass.cpp?rev=292345&r1=292344&r2=292345&view=diff
==============================================================================
--- libcxx/trunk/test/std/experimental/filesystem/class.path/path.member/path.assign/source.pass.cpp (original)
+++ libcxx/trunk/test/std/experimental/filesystem/class.path/path.member/path.assign/source.pass.cpp Tue Jan 17 23:48:55 2017
@@ -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 test_sfinae() {
   }
 }
 
+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();
 }




More information about the cfe-commits mailing list