PR libstdc++/85632 fix wraparound in filesystem::space
[official-gcc.git] / libstdc++-v3 / testsuite / 27_io / filesystem / operations / space.cc
blob3d64342fb8f3a5a3eb10b3e1c3ebcfe65f179019
1 // Copyright (C) 2017-2018 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 "-std=gnu++17 -lstdc++fs" }
19 // { dg-do run { target c++17 } }
20 // { dg-require-filesystem-ts "" }
22 // 30.10.14.3 Permissions [fs.op.space]
24 #include <filesystem>
25 #include <testsuite_fs.h>
26 #include <testsuite_hooks.h>
28 void
29 test01()
31 std::filesystem::space_info s = std::filesystem::space("/");
32 std::error_code ec = make_error_code(std::errc::invalid_argument);
33 s = std::filesystem::space("/", ec);
34 VERIFY( !ec );
36 s = std::filesystem::space(__gnu_test::nonexistent_path(), ec);
37 VERIFY( ec );
38 VERIFY( s.capacity == static_cast<uintmax_t>(-1) );
39 VERIFY( s.free == static_cast<uintmax_t>(-1) );
40 VERIFY( s.available == static_cast<uintmax_t>(-1) );
43 void
44 test02()
46 std::filesystem::space_info s = std::filesystem::space(".");
47 VERIFY( s.capacity >= s.free );
50 int
51 main()
53 test01();
54 test02();