xref: /freebsd-src/contrib/llvm-project/libcxx/include/__filesystem/filesystem_error.h (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
10eae32dcSDimitry Andric // -*- C++ -*-
20eae32dcSDimitry Andric //===----------------------------------------------------------------------===//
30eae32dcSDimitry Andric //
40eae32dcSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
50eae32dcSDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
60eae32dcSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
70eae32dcSDimitry Andric //
80eae32dcSDimitry Andric //===----------------------------------------------------------------------===//
90eae32dcSDimitry Andric 
100eae32dcSDimitry Andric #ifndef _LIBCPP___FILESYSTEM_FILESYSTEM_ERROR_H
110eae32dcSDimitry Andric #define _LIBCPP___FILESYSTEM_FILESYSTEM_ERROR_H
120eae32dcSDimitry Andric 
130eae32dcSDimitry Andric #include <__config>
140eae32dcSDimitry Andric #include <__filesystem/path.h>
150eae32dcSDimitry Andric #include <__memory/shared_ptr.h>
1606c3fb27SDimitry Andric #include <__system_error/error_code.h>
1706c3fb27SDimitry Andric #include <__system_error/system_error.h>
18bdd1243dSDimitry Andric #include <__utility/forward.h>
1906c3fb27SDimitry Andric #include <__verbose_abort>
2006c3fb27SDimitry Andric #include <string>
210eae32dcSDimitry Andric 
2281ad6265SDimitry Andric #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2381ad6265SDimitry Andric #  pragma GCC system_header
2481ad6265SDimitry Andric #endif
2581ad6265SDimitry Andric 
26*5f757f3fSDimitry Andric #if _LIBCPP_STD_VER >= 17
270eae32dcSDimitry Andric 
280eae32dcSDimitry Andric _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
290eae32dcSDimitry Andric 
3006c3fb27SDimitry Andric class _LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY _LIBCPP_EXPORTED_FROM_ABI filesystem_error : public system_error {
310eae32dcSDimitry Andric public:
3206c3fb27SDimitry Andric   _LIBCPP_HIDE_FROM_ABI filesystem_error(const string& __what, error_code __ec)
3306c3fb27SDimitry Andric       : system_error(__ec, __what), __storage_(make_shared<_Storage>(path(), path())) {
340eae32dcSDimitry Andric     __create_what(0);
350eae32dcSDimitry Andric   }
360eae32dcSDimitry Andric 
3706c3fb27SDimitry Andric   _LIBCPP_HIDE_FROM_ABI filesystem_error(const string& __what, const path& __p1, error_code __ec)
3806c3fb27SDimitry Andric       : system_error(__ec, __what), __storage_(make_shared<_Storage>(__p1, path())) {
390eae32dcSDimitry Andric     __create_what(1);
400eae32dcSDimitry Andric   }
410eae32dcSDimitry Andric 
4206c3fb27SDimitry Andric   _LIBCPP_HIDE_FROM_ABI filesystem_error(const string& __what, const path& __p1, const path& __p2, error_code __ec)
4306c3fb27SDimitry Andric       : system_error(__ec, __what), __storage_(make_shared<_Storage>(__p1, __p2)) {
440eae32dcSDimitry Andric     __create_what(2);
450eae32dcSDimitry Andric   }
460eae32dcSDimitry Andric 
4706c3fb27SDimitry Andric   _LIBCPP_HIDE_FROM_ABI const path& path1() const noexcept { return __storage_->__p1_; }
480eae32dcSDimitry Andric 
4906c3fb27SDimitry Andric   _LIBCPP_HIDE_FROM_ABI const path& path2() const noexcept { return __storage_->__p2_; }
500eae32dcSDimitry Andric 
5106c3fb27SDimitry Andric   _LIBCPP_HIDE_FROM_ABI filesystem_error(const filesystem_error&) = default;
520eae32dcSDimitry Andric   ~filesystem_error() override; // key function
530eae32dcSDimitry Andric 
54bdd1243dSDimitry Andric   _LIBCPP_HIDE_FROM_ABI_VIRTUAL
5506c3fb27SDimitry Andric   const char* what() const noexcept override { return __storage_->__what_.c_str(); }
560eae32dcSDimitry Andric 
570eae32dcSDimitry Andric   void __create_what(int __num_paths);
580eae32dcSDimitry Andric 
590eae32dcSDimitry Andric private:
600eae32dcSDimitry Andric   struct _LIBCPP_HIDDEN _Storage {
6106c3fb27SDimitry Andric     _LIBCPP_HIDE_FROM_ABI _Storage(const path& __p1, const path& __p2) : __p1_(__p1), __p2_(__p2) {}
620eae32dcSDimitry Andric 
630eae32dcSDimitry Andric     path __p1_;
640eae32dcSDimitry Andric     path __p2_;
650eae32dcSDimitry Andric     string __what_;
660eae32dcSDimitry Andric   };
670eae32dcSDimitry Andric   shared_ptr<_Storage> __storage_;
680eae32dcSDimitry Andric };
690eae32dcSDimitry Andric 
7006c3fb27SDimitry Andric #  ifndef _LIBCPP_HAS_NO_EXCEPTIONS
710eae32dcSDimitry Andric template <class... _Args>
7206c3fb27SDimitry Andric _LIBCPP_NORETURN inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY void
7306c3fb27SDimitry Andric __throw_filesystem_error(_Args&&... __args) {
74*5f757f3fSDimitry Andric   throw filesystem_error(std::forward<_Args>(__args)...);
750eae32dcSDimitry Andric }
760eae32dcSDimitry Andric #  else
7706c3fb27SDimitry Andric template <class... _Args>
7806c3fb27SDimitry Andric _LIBCPP_NORETURN inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY void
7906c3fb27SDimitry Andric __throw_filesystem_error(_Args&&...) {
8006c3fb27SDimitry Andric   _LIBCPP_VERBOSE_ABORT("filesystem_error was thrown in -fno-exceptions mode");
810eae32dcSDimitry Andric }
820eae32dcSDimitry Andric #  endif
830eae32dcSDimitry Andric 
840eae32dcSDimitry Andric _LIBCPP_END_NAMESPACE_FILESYSTEM
850eae32dcSDimitry Andric 
86*5f757f3fSDimitry Andric #endif // _LIBCPP_STD_VER >= 17
870eae32dcSDimitry Andric 
880eae32dcSDimitry Andric #endif // _LIBCPP___FILESYSTEM_FILESYSTEM_ERROR_H
89