[libcxx-commits] [libcxx] 16342e3 - [libc++][NFC] Move format_error to its own header.

Mark de Wever via libcxx-commits libcxx-commits at lists.llvm.org
Wed May 26 08:43:29 PDT 2021


Author: Mark de Wever
Date: 2021-05-26T17:43:23+02:00
New Revision: 16342e39947bca83b25c251a65c7ea86a244a092

URL: https://github.com/llvm/llvm-project/commit/16342e39947bca83b25c251a65c7ea86a244a092
DIFF: https://github.com/llvm/llvm-project/commit/16342e39947bca83b25c251a65c7ea86a244a092.diff

LOG: [libc++][NFC] Move format_error to its own header.

Reviewed By: #libc, ldionne

Differential Revision: https://reviews.llvm.org/D101723

Added: 
    libcxx/include/__format/format_error.h

Modified: 
    libcxx/include/CMakeLists.txt
    libcxx/include/format

Removed: 
    


################################################################################
diff  --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index e086a4cf8c729..9dddd500b9b7e 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -7,6 +7,7 @@ set(files
   __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
index 0000000000000..608a16d361d88
--- /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 <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/libcxx/include/format b/libcxx/include/format
index d9d43d82d1813..d755062c53fd4 100644
--- a/libcxx/include/format
+++ b/libcxx/include/format
@@ -56,14 +56,10 @@ namespace std {
 */
 
 #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 @@ _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;
-};
-
 // 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:


        


More information about the libcxx-commits mailing list