Debian Codegraph @

libstdc++-v3/testsuite/27_io/filesystem/path/construct/90634.cc

raw
1 // Copyright (C) 2019-2025 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.
8
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.
13
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/>.
17
18 // { dg-do run { target c++17 } }
19
20 #include <filesystem>
21 #include <cstdlib>
22 #include <testsuite_hooks.h>
23
24 std::size_t bytes_allocated = 0;
25
26 void* operator new(std::size_t n)
27 {
28 bytes_allocated += n;
29 return std::malloc(n);
30 }
31
32 void operator delete(void* p) noexcept { std::free(p); }
33 #if __cpp_sized_deallocation
34 void operator delete(void* p, std::size_t) noexcept { std::free(p); }
35 #endif
36
37 void
38 test01()
39 {
40 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
41 std::wstring s0;
42 std::wstring s1 = L"/";
43 std::wstring s2 = L"///";
44 std::wstring s3 = L"file";
45 std::wstring s4 = L"C:";
46 std::wstring s5 = L"\\";
47 #else
48 std::string s0;
49 std::string s1 = "/";
50 std::string s2 = "///";
51 std::string s3 = "file";
52 std::string s4 = "C:";
53 std::string s5 = "\\";
54 #endif
55
56 using std::filesystem::path;
57
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 );
69 path p5 = std::move(s5);
70 VERIFY( bytes_allocated == 0 );
71 }
72
73 int
74 main()
75 {
76 test01();
77 }