move.pass.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is dual licensed under the MIT and the University of Illinois Open
  6. // Source Licenses. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. // UNSUPPORTED: c++98, c++03
  10. // <experimental/filesystem>
  11. // class path
  12. // path& operator=(path&&) noexcept
  13. #include <experimental/filesystem>
  14. #include <type_traits>
  15. #include <cassert>
  16. #include "test_macros.h"
  17. #include "count_new.hpp"
  18. namespace fs = std::experimental::filesystem;
  19. int main() {
  20. using namespace fs;
  21. static_assert(std::is_nothrow_move_assignable<path>::value, "");
  22. assert(globalMemCounter.checkOutstandingNewEq(0));
  23. const std::string s("we really really really really really really really "
  24. "really really long string so that we allocate");
  25. assert(globalMemCounter.checkOutstandingNewEq(1));
  26. path p(s);
  27. {
  28. DisableAllocationGuard g;
  29. path p2;
  30. path& pref = (p2 = std::move(p));
  31. assert(p2.native() == s);
  32. assert(p.native() != s); // Testing moved from state
  33. assert(&pref == &p2);
  34. }
  35. }