diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt --- a/libcxx/include/CMakeLists.txt +++ b/libcxx/include/CMakeLists.txt @@ -7,6 +7,7 @@ __config __debug __errc + __format/format_error.h __function_like.h __functional_03 __functional_base diff --git a/libcxx/include/__format/format_error.h b/libcxx/include/__format/format_error.h new file mode 100644 --- /dev/null +++ b/libcxx/include/__format/format_error.h @@ -0,0 +1,56 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP__FORMAT_FORMAT_ERROR_H +#define _LIBCPP__FORMAT_FORMAT_ERROR_H + +#include <__config> +#include + +#ifdef _LIBCPP_NO_EXCEPTIONS +#include +#endif + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if _LIBCPP_STD_VER > 17 + +class _LIBCPP_EXCEPTION_ABI format_error : public runtime_error { +public: + _LIBCPP_INLINE_VISIBILITY explicit format_error(const string& __s) + : runtime_error(__s) {} + _LIBCPP_INLINE_VISIBILITY explicit format_error(const char* __s) + : runtime_error(__s) {} + virtual ~format_error() noexcept; +}; + +_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY void +__throw_format_error(const char* __s) { +#ifndef _LIBCPP_NO_EXCEPTIONS + throw format_error(__s); +#else + (void)__s; + _VSTD::abort(); +#endif +} + +#endif //_LIBCPP_STD_VER > 17 + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP__FORMAT_FORMAT_ERROR_H diff --git a/libcxx/include/format b/libcxx/include/format --- a/libcxx/include/format +++ b/libcxx/include/format @@ -56,14 +56,10 @@ */ #include <__config> -#include +#include <__format/format_error.h> #include #include -#ifdef _LIBCPP_NO_EXCEPTIONS -#include -#endif - #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header #endif @@ -75,31 +71,12 @@ #if _LIBCPP_STD_VER > 17 -class _LIBCPP_EXCEPTION_ABI format_error : public runtime_error { -public: - _LIBCPP_INLINE_VISIBILITY explicit format_error(const string& __s) - : runtime_error(__s) {} - _LIBCPP_INLINE_VISIBILITY explicit format_error(const char* __s) - : runtime_error(__s) {} - virtual ~format_error() noexcept; -}; - // TODO FMT Remove this once we require compilers with proper C++20 support. // If the compiler has no concepts support, the format header will be disabled. // Without concepts support enable_if needs to be used and that too much effort // to support compilers with partial C++20 support. #if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_BUILTIN_IS_CONSTANT_EVALUATED) -_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY void -__throw_format_error(const char* __s) { -#ifndef _LIBCPP_NO_EXCEPTIONS - throw format_error(__s); -#else - (void)__s; - _VSTD::abort(); -#endif -} - template class _LIBCPP_TEMPLATE_VIS basic_format_parse_context { public: