Debian Codegraph @

libstdc++-v3/testsuite/27_io/filesystem/directory_entry/86597.cc

raw
1 // Copyright (C) 2018-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 // { dg-require-filesystem-ts "" }
20
21 #include <filesystem>
22 #include <system_error>
23 #include <testsuite_hooks.h>
24 #include <testsuite_fs.h>
25
26 // PR libstdc++/86597
27
28 void
29 test01()
30 {
31 const auto bad_ec = make_error_code(std::errc::address_in_use);
32 std::error_code ec;
33 std::filesystem::directory_entry ent(".");
34
35 ec = bad_ec;
36 VERIFY( ent.exists(ec) );
37 VERIFY( !ec );
38
39 ec = bad_ec;
40 VERIFY( ent.is_directory(ec) );
41 VERIFY( !ec );
42
43 ec = bad_ec;
44 VERIFY( !ent.is_regular_file(ec) );
45 VERIFY( !ec );
46 }
47
48 void
49 test02()
50 {
51 const auto bad_ec = make_error_code(std::errc::address_in_use);
52 std::error_code ec;
53 std::filesystem::directory_entry ent(__gnu_test::nonexistent_path());
54
55 ec = bad_ec;
56 VERIFY( !ent.exists(ec) );
57 VERIFY( !ec );
58
59 ec = bad_ec;
60 VERIFY( !ent.is_directory(ec) );
61 VERIFY( !ec );
62
63 ec = bad_ec;
64 VERIFY( !ent.is_regular_file(ec) );
65 VERIFY( !ec );
66 }
67
68 int
69 main()
70 {
71 test01();
72 test02();
73 }