Debian Codegraph @

libstdc++-v3/testsuite/experimental/filesystem/path/concat/120029.cc

raw
1 // { dg-options "-DUSE_FILESYSTEM_TS -lstdc++fs" }
2 // { dg-do run { target c++11 } }
3 // { dg-require-filesystem-ts "" }
4
5 // Bug libstdc++/120029
6 // Dangling iterator usage in path::operator+=(const path& p) when this == p
7
8 #include <experimental/filesystem>
9 #include <testsuite_hooks.h>
10
11 namespace fs = std::experimental::filesystem;
12
13 void
14 test_root_dir()
15 {
16 fs::path p = "/";
17 p += p;
18 p += p;
19 VERIFY( p == "////" );
20 p += p.filename();
21 VERIFY( p == "////////" );
22 p += *std::prev(p.end());
23 VERIFY( p == "////////////////" );
24 }
25
26 void
27 test_root_name()
28 {
29 fs::path p = "C:/";
30 p += p;
31 p += p;
32 VERIFY( p == "C:/C:/C:/C:/" );
33 p += p.filename(); // For Filesystem TS the filename is "."
34 VERIFY( p == "C:/C:/C:/C:/." );
35 p += *std::prev(p.end());
36 VERIFY( p == "C:/C:/C:/C:/.." );
37 }
38
39 void
40 test_filename()
41 {
42 fs::path p = "file";
43 p += p;
44 p += p;
45 VERIFY( p == "filefilefilefile" );
46 p += p.filename();
47 VERIFY( p == "filefilefilefilefilefilefilefile" );
48 p += *std::prev(p.end());
49 VERIFY( p == "filefilefilefilefilefilefilefilefilefilefilefilefilefilefilefile" );
50 }
51
52 void
53 test_multi()
54 {
55 fs::path p = "/home/username/Documents/mu";
56 p += p;
57 p += p;
58 VERIFY( p == "/home/username/Documents/mu/home/username/Documents/mu/home/username/Documents/mu/home/username/Documents/mu" );
59 p += p.filename();
60 VERIFY( p == "/home/username/Documents/mu/home/username/Documents/mu/home/username/Documents/mu/home/username/Documents/mumu" );
61 p += *std::prev(p.end());
62 VERIFY( p == "/home/username/Documents/mu/home/username/Documents/mu/home/username/Documents/mu/home/username/Documents/mumumumu" );
63 auto n = std::distance(p.begin(), p.end());
64 for (int i = 0; i < n; ++i)
65 p += *std::next(p.begin(), i);
66 }
67
68 int main()
69 {
70 test_root_dir();
71 test_root_name();
72 test_filename();
73 test_multi();
74 }