87 lines · c
1// -*- C++ -*-2//===----------------------------------------------------------------------===//3//4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.5// See https://llvm.org/LICENSE.txt for license information.6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception7//8//===----------------------------------------------------------------------===//9 10#ifndef _LIBCPP___FILESYSTEM_FILESYSTEM_ERROR_H11#define _LIBCPP___FILESYSTEM_FILESYSTEM_ERROR_H12 13#include <__config>14#include <__filesystem/path.h>15#include <__memory/shared_ptr.h>16#include <__system_error/error_code.h>17#include <__system_error/system_error.h>18#include <__utility/forward.h>19#include <__verbose_abort>20#include <string>21 22#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)23# pragma GCC system_header24#endif25 26#if _LIBCPP_STD_VER >= 1727 28_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM29 30class _LIBCPP_EXPORTED_FROM_ABI filesystem_error : public system_error {31public:32 _LIBCPP_HIDE_FROM_ABI filesystem_error(const string& __what, error_code __ec)33 : system_error(__ec, __what), __storage_(make_shared<_Storage>(path(), path())) {34 __create_what(0);35 }36 37 _LIBCPP_HIDE_FROM_ABI filesystem_error(const string& __what, const path& __p1, error_code __ec)38 : system_error(__ec, __what), __storage_(make_shared<_Storage>(__p1, path())) {39 __create_what(1);40 }41 42 _LIBCPP_HIDE_FROM_ABI filesystem_error(const string& __what, const path& __p1, const path& __p2, error_code __ec)43 : system_error(__ec, __what), __storage_(make_shared<_Storage>(__p1, __p2)) {44 __create_what(2);45 }46 47 _LIBCPP_HIDE_FROM_ABI const path& path1() const noexcept { return __storage_->__p1_; }48 49 _LIBCPP_HIDE_FROM_ABI const path& path2() const noexcept { return __storage_->__p2_; }50 51 _LIBCPP_HIDE_FROM_ABI filesystem_error(const filesystem_error&) = default;52 ~filesystem_error() override; // key function53 54 _LIBCPP_HIDE_FROM_ABI_VIRTUAL55 const char* what() const noexcept override { return __storage_->__what_.c_str(); }56 57 void __create_what(int __num_paths);58 59private:60 struct _LIBCPP_HIDDEN _Storage {61 _LIBCPP_HIDE_FROM_ABI _Storage(const path& __p1, const path& __p2) : __p1_(__p1), __p2_(__p2) {}62 63 path __p1_;64 path __p2_;65 string __what_;66 };67 shared_ptr<_Storage> __storage_;68};69 70# if _LIBCPP_HAS_EXCEPTIONS71template <class... _Args>72[[__noreturn__]] inline _LIBCPP_HIDE_FROM_ABI void __throw_filesystem_error(_Args&&... __args) {73 throw filesystem_error(std::forward<_Args>(__args)...);74}75# else76template <class... _Args>77[[__noreturn__]] inline _LIBCPP_HIDE_FROM_ABI void __throw_filesystem_error(_Args&&...) {78 _LIBCPP_VERBOSE_ABORT("filesystem_error was thrown in -fno-exceptions mode");79}80# endif81 82_LIBCPP_END_NAMESPACE_FILESYSTEM83 84#endif // _LIBCPP_STD_VER >= 1785 86#endif // _LIBCPP___FILESYSTEM_FILESYSTEM_ERROR_H87