1 // Copyright (C) 2018 Free Software Foundation, Inc.
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)
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 "-std=gnu++17 -lstdc++fs" }
19 // { dg-do run { target c++17 } }
20 // { dg-require-filesystem-ts "" }
23 #include <testsuite_hooks.h>
25 using std::filesystem::filesystem_error
;
28 static_assert(std::is_nothrow_copy_constructible_v
<filesystem_error
>);
29 static_assert(std::is_nothrow_copy_assignable_v
<filesystem_error
>);
34 const char* const str
= "error test";
35 const std::error_code ec
= make_error_code(std::errc::is_a_directory
);
36 const filesystem_error
e1(str
, ec
);
38 VERIFY( e2
.path1().empty() );
39 VERIFY( e2
.path2().empty() );
40 VERIFY( std::string_view(e2
.what()).find(str
) != std::string_view::npos
);
41 VERIFY( e2
.code() == ec
);
43 const filesystem_error
e3(str
, "test/path/one", ec
);
45 VERIFY( e4
.path1() == "test/path/one" );
46 VERIFY( e4
.path2().empty() );
47 VERIFY( std::string_view(e4
.what()).find(str
) != std::string_view::npos
);
48 VERIFY( e2
.code() == ec
);
50 const filesystem_error
e5(str
, "test/path/one", "/test/path/two", ec
);
52 VERIFY( e6
.path1() == "test/path/one" );
53 VERIFY( e6
.path2() == "/test/path/two" );
54 VERIFY( std::string_view(e6
.what()).find(str
) != std::string_view::npos
);
55 VERIFY( e2
.code() == ec
);
61 const char* const str
= "error test";
62 const std::error_code ec
= make_error_code(std::errc::is_a_directory
);
63 const filesystem_error
e1(str
, ec
);
64 filesystem_error
e2("", {});
66 VERIFY( e2
.path1().empty() );
67 VERIFY( e2
.path2().empty() );
68 VERIFY( std::string_view(e2
.what()).find(str
) != std::string_view::npos
);
69 VERIFY( e2
.code() == ec
);
71 const filesystem_error
e3(str
, "test/path/one", ec
);
72 filesystem_error
e4("", {});
74 VERIFY( e4
.path1() == "test/path/one" );
75 VERIFY( e4
.path2().empty() );
76 VERIFY( std::string_view(e4
.what()).find(str
) != std::string_view::npos
);
77 VERIFY( e2
.code() == ec
);
79 const filesystem_error
e5(str
, "test/path/one", "/test/path/two", ec
);
80 filesystem_error
e6("", {});
82 VERIFY( e6
.path1() == "test/path/one" );
83 VERIFY( e6
.path2() == "/test/path/two" );
84 VERIFY( std::string_view(e6
.what()).find(str
) != std::string_view::npos
);
85 VERIFY( e2
.code() == ec
);
91 filesystem_error
e("test", std::error_code());
92 VERIFY( e
.path1().empty() );
93 VERIFY( e
.path2().empty() );
94 auto e2
= std::move(e
);
95 // Observers must still be usable on moved-from object:
96 VERIFY( e
.path1().empty() );
97 VERIFY( e
.path2().empty() );
98 VERIFY( e
.what() != nullptr );
100 VERIFY( e
.path1().empty() );
101 VERIFY( e
.path2().empty() );
102 VERIFY( e
.what() != nullptr );