[libcxx-commits] [libcxx] [libc++][print] Includes <format>. (PR #76333)
via libcxx-commits
libcxx-commits at lists.llvm.org
Sun Dec 24 05:36:31 PST 2023
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libcxx
Author: Mark de Wever (mordante)
<details>
<summary>Changes</summary>
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
---
Full diff: https://github.com/llvm/llvm-project/pull/76333.diff
9 Files Affected:
- (modified) libcxx/include/print (+1-7)
- (added) libcxx/test/libcxx/input.output/iostream.format/print.fun/includes.compile.pass.cpp (+34)
- (modified) libcxx/test/libcxx/transitive_includes/cxx03.csv (+1-11)
- (modified) libcxx/test/libcxx/transitive_includes/cxx11.csv (+1-11)
- (modified) libcxx/test/libcxx/transitive_includes/cxx14.csv (+1-11)
- (modified) libcxx/test/libcxx/transitive_includes/cxx17.csv (+1-11)
- (modified) libcxx/test/libcxx/transitive_includes/cxx20.csv (+1-11)
- (modified) libcxx/test/libcxx/transitive_includes/cxx23.csv (+1-11)
- (modified) libcxx/test/libcxx/transitive_includes/cxx26.csv (+1-11)
``````````diff
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/print.fun/includes.compile.pass.cpp b/libcxx/test/libcxx/input.output/iostream.format/print.fun/includes.compile.pass.cpp
new file mode 100644
index 00000000000000..c6cbe6834b5e9b
--- /dev/null
+++ b/libcxx/test/libcxx/input.output/iostream.format/print.fun/includes.compile.pass.cpp
@@ -0,0 +1,34 @@
+//===----------------------------------------------------------------------===//
+// 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 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 code in
+// this tests most likely works in these implementations. This validates it
+// works with our implementation too.
+//
+// https://github.com/llvm/llvm-project/issues/71925
+
+#include <print>
+#include <vector>
+#include <iostream>
+
+void test() {
+ std::vector<int> v{1, 2, 3};
+ std::print("{} {}", 42, v);
+ std::print(stdout, "{} {}", 42, v);
+ std::print(std::cout, "{} {}", 42, v);
+}
diff --git a/libcxx/test/libcxx/transitive_includes/cxx03.csv b/libcxx/test/libcxx/transitive_includes/cxx03.csv
index 3f066342717624..a63cfea8d0aedb 100644
--- a/libcxx/test/libcxx/transitive_includes/cxx03.csv
+++ b/libcxx/test/libcxx/transitive_includes/cxx03.csv
@@ -600,21 +600,11 @@ ostream string_view
ostream tuple
ostream type_traits
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 stdexcept
+print format
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..37311e2b130af1 100644
--- a/libcxx/test/libcxx/transitive_includes/cxx11.csv
+++ b/libcxx/test/libcxx/transitive_includes/cxx11.csv
@@ -605,21 +605,11 @@ ostream string_view
ostream tuple
ostream type_traits
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 stdexcept
+print format
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..a81b3e59d35872 100644
--- a/libcxx/test/libcxx/transitive_includes/cxx14.csv
+++ b/libcxx/test/libcxx/transitive_includes/cxx14.csv
@@ -607,21 +607,11 @@ ostream string_view
ostream tuple
ostream type_traits
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 stdexcept
+print format
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..a81b3e59d35872 100644
--- a/libcxx/test/libcxx/transitive_includes/cxx17.csv
+++ b/libcxx/test/libcxx/transitive_includes/cxx17.csv
@@ -607,21 +607,11 @@ ostream string_view
ostream tuple
ostream type_traits
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 stdexcept
+print format
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..9a11135d9ef747 100644
--- a/libcxx/test/libcxx/transitive_includes/cxx20.csv
+++ b/libcxx/test/libcxx/transitive_includes/cxx20.csv
@@ -612,21 +612,11 @@ ostream string_view
ostream tuple
ostream type_traits
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 stdexcept
+print format
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..9093f649316f2f 100644
--- a/libcxx/test/libcxx/transitive_includes/cxx23.csv
+++ b/libcxx/test/libcxx/transitive_includes/cxx23.csv
@@ -416,21 +416,11 @@ ostream string
ostream string_view
ostream tuple
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 stdexcept
+print format
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..9093f649316f2f 100644
--- a/libcxx/test/libcxx/transitive_includes/cxx26.csv
+++ b/libcxx/test/libcxx/transitive_includes/cxx26.csv
@@ -416,21 +416,11 @@ ostream string
ostream string_view
ostream tuple
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 stdexcept
+print format
print string
print string_view
-print tuple
print version
queue compare
queue cstddef
``````````
</details>
https://github.com/llvm/llvm-project/pull/76333
More information about the libcxx-commits
mailing list