[libcxx-commits] [libcxx] 82d2181 - [libc++][print] Includes <format>. (#76333)
via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Jan 16 08:33:05 PST 2024
Author: Mark de Wever
Date: 2024-01-16T17:33:01+01:00
New Revision: 82d21814e6556480a71c83a2f8da350d0c8cadf6
URL: https://github.com/llvm/llvm-project/commit/82d21814e6556480a71c83a2f8da350d0c8cadf6
DIFF: https://github.com/llvm/llvm-project/commit/82d21814e6556480a71c83a2f8da350d0c8cadf6.diff
LOG: [libc++][print] Includes <format>. (#76333)
The overloads of `println` are specified in terms of `format`. The
function `format` is specified to work with ranges.
The implementations for `println` do not include `<format>`, but
libc++'s granularized header. This means the following example does not
work
#include <vector>
#include <print>
int main() {
std::vector<int> v{1, 2, 3};
std::println("{}", v);
}
(The other print functions also require this to work, they are specified
in terms of other format functions.)
Fixes: https://github.com/llvm/llvm-project/issues/71925
Added:
libcxx/test/libcxx/input.output/iostream.format/output.streams/ostream.syn/includes.compile.pass.cpp
libcxx/test/std/input.output/iostream.format/print.fun/includes.compile.pass.cpp
Modified:
libcxx/include/ostream
libcxx/include/print
libcxx/test/libcxx/transitive_includes/cxx03.csv
libcxx/test/libcxx/transitive_includes/cxx11.csv
libcxx/test/libcxx/transitive_includes/cxx14.csv
libcxx/test/libcxx/transitive_includes/cxx17.csv
libcxx/test/libcxx/transitive_includes/cxx20.csv
libcxx/test/libcxx/transitive_includes/cxx23.csv
libcxx/test/libcxx/transitive_includes/cxx26.csv
Removed:
################################################################################
diff --git a/libcxx/include/ostream b/libcxx/include/ostream
index 25b3b49262be40..e9c78032d84e94 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 ee3ed0773129dd..7f2b5bac3dcf61 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 e709628ce2311b..5769fc70d8a75e 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 d3ea6ed97367e4..863b674a13d0a0 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 3e56017bfb537b..bbaf1ed89fac64 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 3e56017bfb537b..bbaf1ed89fac64 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 0c5b9721a22551..07e23053e9558d 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 0d8c3fa21b2f37..23a1f42556f22e 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 0d8c3fa21b2f37..23a1f42556f22e 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