PR libstdc++/90634 reduce allocations in filesystem::path construction
[official-gcc.git] / libstdc++-v3 / testsuite / experimental / filesystem / path / construct / 90634.cc
blob6dce1df3d63b4ffcba07d48bbe20ec4b901490ee
1 // Copyright (C) 2019 Free Software Foundation, Inc.
2 //
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 3, or (at your option)
7 // any later version.
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
18 // { dg-options "-DUSE_FILESYSTEM_TS -lstdc++fs" }
19 // { dg-do run { target c++11 } }
20 // { dg-require-filesystem-ts "" }
22 #include <experimental/filesystem>
23 #include <cstdlib>
24 #include <testsuite_hooks.h>
26 std::size_t bytes_allocated = 0;
28 void* operator new(std::size_t n)
30 bytes_allocated += n;
31 return std::malloc(n);
34 void operator delete(void* p) noexcept { std::free(p); }
35 #if __cpp_sized_deallocation
36 void operator delete(void* p, std::size_t) noexcept { std::free(p); }
37 #endif
39 void
40 test01()
42 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
43 std::wstring s0;
44 std::wstring s1 = L"/";
45 std::wstring s2 = L"file";
46 std::wstring s3 = L"C:";
47 std::wstring s4 = L"\\";
48 #else
49 std::string s0;
50 std::string s1 = "/";
51 std::string s2 = "file";
52 std::string s3 = "C:";
53 std::string s4 = "\\";
54 #endif
56 using std::experimental::filesystem::path;
58 bytes_allocated = 0;
59 path p0 = std::move(s0);
60 VERIFY( bytes_allocated == 0 );
61 path p1 = std::move(s1);
62 VERIFY( bytes_allocated == 0 );
63 path p2 = std::move(s2);
64 VERIFY( bytes_allocated == 0 );
65 path p3 = std::move(s3);
66 VERIFY( bytes_allocated == 0 );
67 path p4 = std::move(s4);
68 VERIFY( bytes_allocated == 0 );
71 int
72 main()
74 test01();