[libcxx-commits] [libcxx] 5baa4ee - [libc++][NFC] Move format_to_n_result.

Mark de Wever via libcxx-commits libcxx-commits at lists.llvm.org
Tue Nov 16 06:51:53 PST 2021


Author: Mark de Wever
Date: 2021-11-16T15:51:49+01:00
New Revision: 5baa4ee30b5c2d3920499d974c152525636ab8ac

URL: https://github.com/llvm/llvm-project/commit/5baa4ee30b5c2d3920499d974c152525636ab8ac
DIFF: https://github.com/llvm/llvm-project/commit/5baa4ee30b5c2d3920499d974c152525636ab8ac.diff

LOG: [libc++][NFC] Move format_to_n_result.

Places `format_to_n_result` to its own file. While working on D112361 it
turns out the type will be used outside the format header.

Reviewed By: #libc, Quuxplusone, Mordante

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

Added: 
    libcxx/include/__format/format_to_n_result.h
    libcxx/test/libcxx/diagnostics/detail.headers/format/format_to_n_result.module.verify.cpp

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

Removed: 
    


################################################################################
diff  --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index b13b8e138eb21..9d7abc870a9ef 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -144,6 +144,7 @@ set(files
   __format/format_fwd.h
   __format/format_parse_context.h
   __format/format_string.h
+  __format/format_to_n_result.h
   __format/formatter.h
   __format/formatter_bool.h
   __format/formatter_char.h

diff  --git a/libcxx/include/__format/format_to_n_result.h b/libcxx/include/__format/format_to_n_result.h
new file mode 100644
index 0000000000000..b973dc5c1dfe0
--- /dev/null
+++ b/libcxx/include/__format/format_to_n_result.h
@@ -0,0 +1,41 @@
+// -*- 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_TO_N_RESULT_H
+#define _LIBCPP___FORMAT_FORMAT_TO_N_RESULT_H
+
+#include <__config>
+#include <__iterator/incrementable_traits.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER > 17
+
+// 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)
+
+template <class _OutIt>
+struct _LIBCPP_TEMPLATE_VIS format_to_n_result {
+  _OutIt out;
+  iter_
diff erence_t<_OutIt> size;
+};
+
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
+#endif //_LIBCPP_STD_VER > 17
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___FORMAT_FORMAT_TO_N_RESULT_H

diff  --git a/libcxx/include/format b/libcxx/include/format
index 19f642716b1b7..e1002e72817a4 100644
--- a/libcxx/include/format
+++ b/libcxx/include/format
@@ -278,6 +278,7 @@ namespace std {
 #include <__format/format_fwd.h>
 #include <__format/format_parse_context.h>
 #include <__format/format_string.h>
+#include <__format/format_to_n_result.h>
 #include <__format/formatter.h>
 #include <__format/formatter_bool.h>
 #include <__format/formatter_char.h>
@@ -579,12 +580,6 @@ format(wstring_view __fmt, const _Args&... __args) {
 }
 #endif
 
-template <class _OutIt>
-struct _LIBCPP_TEMPLATE_VIS format_to_n_result {
-  _OutIt out;
-  iter_
diff erence_t<_OutIt> size;
-};
-
 template <output_iterator<const char&> _OutIt, class... _Args>
 _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT format_to_n_result<_OutIt>
 format_to_n(_OutIt __out_it, iter_
diff erence_t<_OutIt> __n, string_view __fmt,

diff  --git a/libcxx/include/module.modulemap b/libcxx/include/module.modulemap
index 39b8a662d3a88..b159d58b7b96a 100644
--- a/libcxx/include/module.modulemap
+++ b/libcxx/include/module.modulemap
@@ -463,6 +463,7 @@ module std [system] {
       module format_fwd             { private header "__format/format_fwd.h"             }
       module format_parse_context   { private header "__format/format_parse_context.h"   }
       module format_string          { private header "__format/format_string.h"          }
+      module format_to_n_result     { private header "__format/format_to_n_result.h"     }
       module formatter              { private header "__format/formatter.h"              }
       module formatter_bool         { private header "__format/formatter_bool.h"         }
       module formatter_char         { private header "__format/formatter_char.h"         }

diff  --git a/libcxx/test/libcxx/diagnostics/detail.headers/format/format_to_n_result.module.verify.cpp b/libcxx/test/libcxx/diagnostics/detail.headers/format/format_to_n_result.module.verify.cpp
new file mode 100644
index 0000000000000..86903a6056964
--- /dev/null
+++ b/libcxx/test/libcxx/diagnostics/detail.headers/format/format_to_n_result.module.verify.cpp
@@ -0,0 +1,15 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// REQUIRES: modules-build
+
+// WARNING: This test was generated by 'generate_private_header_tests.py'
+// and should not be edited manually.
+
+// expected-error@*:* {{use of private header from outside its module: '__format/format_to_n_result.h'}}
+#include <__format/format_to_n_result.h>


        


More information about the libcxx-commits mailing list