[libcxx-commits] [libcxx] [libc++][print] Includes <format>. (PR #76333)
Mark de Wever via libcxx-commits
libcxx-commits at lists.llvm.org
Sat Jan 13 10:55:05 PST 2024
https://github.com/mordante updated https://github.com/llvm/llvm-project/pull/76333
>From afeafa7fd4a8c7a75bb6facef2ee1e88df6f4fce Mon Sep 17 00:00:00 2001
From: Mark de Wever <koraq at xs4all.nl>
Date: Sun, 24 Dec 2023 14:25:01 +0100
Subject: [PATCH] [libc++][print] Includes <format>.
The Standard does not require that <print> includes <format>. However
without including <format> formatting ranges does not work. Libc++ uses
granularized headers so it's possible to implement <print> without
<format>. Both libstdc++ and MSVC STL don't use granularized headers so
the example likely works once these libraries implement print.
Even without these implementations doing that it seems reasonable to
expect examples that work for `std::format` also work with `std::print`
without adding additional includes.
Instead of only including the ranges part of format include the entire
header. This ensures future additions to <format> will be available in
<print> and <ostream> too.
Addresses: https://github.com/llvm/llvm-project/issues/71925
---
libcxx/include/ostream | 3 +-
libcxx/include/print | 8 +----
.../ostream.syn/includes.compile.pass.cpp | 30 +++++++++++++++++++
.../test/libcxx/transitive_includes/cxx03.csv | 19 ++++--------
.../test/libcxx/transitive_includes/cxx11.csv | 19 ++++--------
.../test/libcxx/transitive_includes/cxx14.csv | 19 ++++--------
.../test/libcxx/transitive_includes/cxx17.csv | 19 ++++--------
.../test/libcxx/transitive_includes/cxx20.csv | 19 ++++--------
.../test/libcxx/transitive_includes/cxx23.csv | 20 ++++---------
.../test/libcxx/transitive_includes/cxx26.csv | 20 ++++---------
.../print.fun/includes.compile.pass.cpp | 28 +++++++++++++++++
11 files changed, 102 insertions(+), 102 deletions(-)
create mode 100644 libcxx/test/libcxx/input.output/iostream.format/output.streams/ostream.syn/includes.compile.pass.cpp
create mode 100644 libcxx/test/std/input.output/iostream.format/print.fun/includes.compile.pass.cpp
diff --git a/libcxx/include/ostream b/libcxx/include/ostream
index 88ee9d93a1d36c..03a30eea434000 100644
--- a/libcxx/include/ostream
+++ b/libcxx/include/ostream
@@ -175,8 +175,6 @@ void vprint_nonunicode(ostream& os, string_view fmt, format_args args);
#include <__availability>
#include <__config>
#include <__exception/operations.h>
-#include <__format/format_args.h>
-#include <__format/format_functions.h>
#include <__fwd/ostream.h>
#include <__memory/shared_ptr.h>
#include <__memory/unique_ptr.h>
@@ -188,6 +186,7 @@ void vprint_nonunicode(ostream& os, string_view fmt, format_args args);
#include <__utility/declval.h>
#include <bitset>
#include <cstdio>
+#include <format>
#include <ios>
#include <locale>
#include <new>
diff --git a/libcxx/include/print b/libcxx/include/print
index 0f8e73f8eb5c74..3c878bde7580e9 100644
--- a/libcxx/include/print
+++ b/libcxx/include/print
@@ -34,17 +34,11 @@ namespace std {
#include <__assert> // all public C++ headers provide the assertion handler
#include <__concepts/same_as.h>
#include <__config>
-#include <__format/buffer.h>
-#include <__format/format_arg_store.h>
-#include <__format/format_args.h>
-#include <__format/format_context.h>
-#include <__format/format_error.h>
-#include <__format/format_functions.h>
-#include <__format/unicode.h>
#include <__system_error/system_error.h>
#include <__utility/forward.h>
#include <cerrno>
#include <cstdio>
+#include <format>
#include <string>
#include <string_view>
#include <version>
diff --git a/libcxx/test/libcxx/input.output/iostream.format/output.streams/ostream.syn/includes.compile.pass.cpp b/libcxx/test/libcxx/input.output/iostream.format/output.streams/ostream.syn/includes.compile.pass.cpp
new file mode 100644
index 00000000000000..0d685f944e6bc0
--- /dev/null
+++ b/libcxx/test/libcxx/input.output/iostream.format/output.streams/ostream.syn/includes.compile.pass.cpp
@@ -0,0 +1,30 @@
+//===----------------------------------------------------------------------===//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
+// UNSUPPORTED: no-filesystem
+// UNSUPPORTED: GCC-ALWAYS_INLINE-FIXME
+
+// XFAIL: availability-fp_to_chars-missing
+
+// <ostream>
+
+// The Standard does indirectly require that <ostream> includes <format>.
+// However using the granularized headers so it's possible to implement
+// <ostream> without <format>. This would be a non-conforming implementation.
+//
+// See https://github.com/llvm/llvm-project/issues/71925
+
+#include <ostream>
+#include <vector>
+
+extern std::ostream& os;
+
+void test() {
+ std::vector<int> v{1, 2, 3};
+ std::print(os, "{} {}", 42, v);
+}
diff --git a/libcxx/test/libcxx/transitive_includes/cxx03.csv b/libcxx/test/libcxx/transitive_includes/cxx03.csv
index 3f066342717624..a0b062884842a6 100644
--- a/libcxx/test/libcxx/transitive_includes/cxx03.csv
+++ b/libcxx/test/libcxx/transitive_includes/cxx03.csv
@@ -576,45 +576,38 @@ optional typeinfo
optional utility
optional variant
optional version
-ostream array
ostream atomic
ostream bitset
-ostream cmath
+ostream cerrno
ostream concepts
ostream cstddef
ostream cstdint
ostream cstdio
ostream cstdlib
+ostream cstring
+ostream format
+ostream initializer_list
ostream ios
ostream iosfwd
ostream iterator
ostream limits
ostream locale
ostream new
-ostream optional
ostream print
ostream stdexcept
ostream streambuf
ostream string
ostream string_view
-ostream tuple
ostream type_traits
+ostream typeinfo
ostream version
-print array
print cerrno
-print cmath
print cstddef
-print cstdint
print cstdio
-print initializer_list
-print limits
-print locale
-print new
-print optional
+print format
print stdexcept
print string
print string_view
-print tuple
print version
queue compare
queue concepts
diff --git a/libcxx/test/libcxx/transitive_includes/cxx11.csv b/libcxx/test/libcxx/transitive_includes/cxx11.csv
index 7b443e5a0ec0f9..f59f0b5dfc0923 100644
--- a/libcxx/test/libcxx/transitive_includes/cxx11.csv
+++ b/libcxx/test/libcxx/transitive_includes/cxx11.csv
@@ -581,45 +581,38 @@ optional typeinfo
optional utility
optional variant
optional version
-ostream array
ostream atomic
ostream bitset
-ostream cmath
+ostream cerrno
ostream concepts
ostream cstddef
ostream cstdint
ostream cstdio
ostream cstdlib
+ostream cstring
+ostream format
+ostream initializer_list
ostream ios
ostream iosfwd
ostream iterator
ostream limits
ostream locale
ostream new
-ostream optional
ostream print
ostream stdexcept
ostream streambuf
ostream string
ostream string_view
-ostream tuple
ostream type_traits
+ostream typeinfo
ostream version
-print array
print cerrno
-print cmath
print cstddef
-print cstdint
print cstdio
-print initializer_list
-print limits
-print locale
-print new
-print optional
+print format
print stdexcept
print string
print string_view
-print tuple
print version
queue compare
queue concepts
diff --git a/libcxx/test/libcxx/transitive_includes/cxx14.csv b/libcxx/test/libcxx/transitive_includes/cxx14.csv
index a5b77ec79bb5c3..54b465993dacda 100644
--- a/libcxx/test/libcxx/transitive_includes/cxx14.csv
+++ b/libcxx/test/libcxx/transitive_includes/cxx14.csv
@@ -583,45 +583,38 @@ optional typeinfo
optional utility
optional variant
optional version
-ostream array
ostream atomic
ostream bitset
-ostream cmath
+ostream cerrno
ostream concepts
ostream cstddef
ostream cstdint
ostream cstdio
ostream cstdlib
+ostream cstring
+ostream format
+ostream initializer_list
ostream ios
ostream iosfwd
ostream iterator
ostream limits
ostream locale
ostream new
-ostream optional
ostream print
ostream stdexcept
ostream streambuf
ostream string
ostream string_view
-ostream tuple
ostream type_traits
+ostream typeinfo
ostream version
-print array
print cerrno
-print cmath
print cstddef
-print cstdint
print cstdio
-print initializer_list
-print limits
-print locale
-print new
-print optional
+print format
print stdexcept
print string
print string_view
-print tuple
print version
queue compare
queue concepts
diff --git a/libcxx/test/libcxx/transitive_includes/cxx17.csv b/libcxx/test/libcxx/transitive_includes/cxx17.csv
index a5b77ec79bb5c3..54b465993dacda 100644
--- a/libcxx/test/libcxx/transitive_includes/cxx17.csv
+++ b/libcxx/test/libcxx/transitive_includes/cxx17.csv
@@ -583,45 +583,38 @@ optional typeinfo
optional utility
optional variant
optional version
-ostream array
ostream atomic
ostream bitset
-ostream cmath
+ostream cerrno
ostream concepts
ostream cstddef
ostream cstdint
ostream cstdio
ostream cstdlib
+ostream cstring
+ostream format
+ostream initializer_list
ostream ios
ostream iosfwd
ostream iterator
ostream limits
ostream locale
ostream new
-ostream optional
ostream print
ostream stdexcept
ostream streambuf
ostream string
ostream string_view
-ostream tuple
ostream type_traits
+ostream typeinfo
ostream version
-print array
print cerrno
-print cmath
print cstddef
-print cstdint
print cstdio
-print initializer_list
-print limits
-print locale
-print new
-print optional
+print format
print stdexcept
print string
print string_view
-print tuple
print version
queue compare
queue concepts
diff --git a/libcxx/test/libcxx/transitive_includes/cxx20.csv b/libcxx/test/libcxx/transitive_includes/cxx20.csv
index c8c84867fda459..db9f751e70a32a 100644
--- a/libcxx/test/libcxx/transitive_includes/cxx20.csv
+++ b/libcxx/test/libcxx/transitive_includes/cxx20.csv
@@ -588,45 +588,38 @@ optional typeinfo
optional utility
optional variant
optional version
-ostream array
ostream atomic
ostream bitset
-ostream cmath
+ostream cerrno
ostream concepts
ostream cstddef
ostream cstdint
ostream cstdio
ostream cstdlib
+ostream cstring
+ostream format
+ostream initializer_list
ostream ios
ostream iosfwd
ostream iterator
ostream limits
ostream locale
ostream new
-ostream optional
ostream print
ostream stdexcept
ostream streambuf
ostream string
ostream string_view
-ostream tuple
ostream type_traits
+ostream typeinfo
ostream version
-print array
print cerrno
-print cmath
print cstddef
-print cstdint
print cstdio
-print initializer_list
-print limits
-print locale
-print new
-print optional
+print format
print stdexcept
print string
print string_view
-print tuple
print version
queue compare
queue concepts
diff --git a/libcxx/test/libcxx/transitive_includes/cxx23.csv b/libcxx/test/libcxx/transitive_includes/cxx23.csv
index a4fa50dc014aba..dac5ae68ae3faf 100644
--- a/libcxx/test/libcxx/transitive_includes/cxx23.csv
+++ b/libcxx/test/libcxx/transitive_includes/cxx23.csv
@@ -398,39 +398,31 @@ optional initializer_list
optional limits
optional new
optional version
-ostream array
ostream bitset
-ostream cmath
+ostream cerrno
ostream cstddef
ostream cstdint
ostream cstdio
+ostream cstring
+ostream format
+ostream initializer_list
ostream ios
ostream limits
ostream locale
ostream new
-ostream optional
ostream print
-ostream stdexcept
ostream streambuf
ostream string
ostream string_view
-ostream tuple
+ostream typeinfo
ostream version
-print array
print cerrno
-print cmath
print cstddef
-print cstdint
print cstdio
-print initializer_list
-print limits
-print locale
-print new
-print optional
+print format
print stdexcept
print string
print string_view
-print tuple
print version
queue compare
queue cstddef
diff --git a/libcxx/test/libcxx/transitive_includes/cxx26.csv b/libcxx/test/libcxx/transitive_includes/cxx26.csv
index a4fa50dc014aba..dac5ae68ae3faf 100644
--- a/libcxx/test/libcxx/transitive_includes/cxx26.csv
+++ b/libcxx/test/libcxx/transitive_includes/cxx26.csv
@@ -398,39 +398,31 @@ optional initializer_list
optional limits
optional new
optional version
-ostream array
ostream bitset
-ostream cmath
+ostream cerrno
ostream cstddef
ostream cstdint
ostream cstdio
+ostream cstring
+ostream format
+ostream initializer_list
ostream ios
ostream limits
ostream locale
ostream new
-ostream optional
ostream print
-ostream stdexcept
ostream streambuf
ostream string
ostream string_view
-ostream tuple
+ostream typeinfo
ostream version
-print array
print cerrno
-print cmath
print cstddef
-print cstdint
print cstdio
-print initializer_list
-print limits
-print locale
-print new
-print optional
+print format
print stdexcept
print string
print string_view
-print tuple
print version
queue compare
queue cstddef
diff --git a/libcxx/test/std/input.output/iostream.format/print.fun/includes.compile.pass.cpp b/libcxx/test/std/input.output/iostream.format/print.fun/includes.compile.pass.cpp
new file mode 100644
index 00000000000000..34eff101d730aa
--- /dev/null
+++ b/libcxx/test/std/input.output/iostream.format/print.fun/includes.compile.pass.cpp
@@ -0,0 +1,28 @@
+//===----------------------------------------------------------------------===//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
+// UNSUPPORTED: no-filesystem
+// UNSUPPORTED: GCC-ALWAYS_INLINE-FIXME
+
+// XFAIL: availability-fp_to_chars-missing
+
+// <print>
+
+// The Standard does indirectly require that <print> includes <format>. However
+// using the granularized headers so it's possible to implement <print> without
+// <format>. This would be a non-conforming implementation.
+//
+// See https://github.com/llvm/llvm-project/issues/71925
+
+#include <print>
+#include <vector>
+
+void test() {
+ std::vector<int> v{1, 2, 3};
+ std::print("{} {}", 42, v);
+}
More information about the libcxx-commits
mailing list