[libc++][NFC] Move format_error to its own header.
Reviewed By: #libc, ldionne
Differential Revision: https://reviews.llvm.org/D101723
NOKEYCHECK=True
GitOrigin-RevId: 16342e39947bca83b25c251a65c7ea86a244a092
diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt
index e086a4c..9dddd50 100644
--- a/include/CMakeLists.txt
+++ b/include/CMakeLists.txt
@@ -7,6 +7,7 @@
__config
__debug
__errc
+ __format/format_error.h
__function_like.h
__functional_03
__functional_base
diff --git a/include/__format/format_error.h b/include/__format/format_error.h
new file mode 100644
index 0000000..608a16d
--- /dev/null
+++ b/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 <stdexcept>
+
+#ifdef _LIBCPP_NO_EXCEPTIONS
+#include <cstdlib>
+#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/include/format b/include/format
index d9d43d8..d755062 100644
--- a/include/format
+++ b/include/format
@@ -56,14 +56,10 @@
*/
#include <__config>
-#include <stdexcept>
+#include <__format/format_error.h>
#include <string_view>
#include <version>
-#ifdef _LIBCPP_NO_EXCEPTIONS
-#include <cstdlib>
-#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 _CharT>
class _LIBCPP_TEMPLATE_VIS basic_format_parse_context {
public: