[libcxx-commits] [libcxx] 3ba96cb - [libc++] Adds tests for LWG-3373.
Mark de Wever via libcxx-commits
libcxx-commits at lists.llvm.org
Sat Jan 15 04:46:58 PST 2022
Author: Mark de Wever
Date: 2022-01-15T13:46:53+01:00
New Revision: 3ba96cb2c94904ab68a59cfd2391846f1e9b9902
URL: https://github.com/llvm/llvm-project/commit/3ba96cb2c94904ab68a59cfd2391846f1e9b9902
DIFF: https://github.com/llvm/llvm-project/commit/3ba96cb2c94904ab68a59cfd2391846f1e9b9902.diff
LOG: [libc++] Adds tests for LWG-3373.
The code in libc++ already satisfy the requirements of LWG-3373. Since
the issue was written to specifically allow the types to be used in
structured bindings, tests have been added to validate the new
requirement.
Implements
LWG-3373 {to,from}_chars_result and format_to_n_result need the "we really mean what we say" wording
Reviewed By: #libc, ldionne
Differential Revision: https://reviews.llvm.org/D117337
Added:
libcxx/test/std/utilities/format/format.syn/format_to_n_result.pass.cpp
Modified:
libcxx/docs/Status/Cxx20Issues.csv
libcxx/test/std/utilities/charconv/charconv.syn/from_chars_result.pass.cpp
libcxx/test/std/utilities/charconv/charconv.syn/to_chars_result.pass.cpp
Removed:
################################################################################
diff --git a/libcxx/docs/Status/Cxx20Issues.csv b/libcxx/docs/Status/Cxx20Issues.csv
index 82ead0d7ecd30..f93e66fda1849 100644
--- a/libcxx/docs/Status/Cxx20Issues.csv
+++ b/libcxx/docs/Status/Cxx20Issues.csv
@@ -277,7 +277,7 @@
"`3369 <https://wg21.link/LWG3369>`__","``span``\ 's deduction-guide for built-in arrays doesn't work","Prague","|Complete|","14.0"
"`3371 <https://wg21.link/LWG3371>`__","``visit_format_arg``\ and ``make_format_args``\ are not hidden friends","Prague","|Complete|","14.0","|format|"
"`3372 <https://wg21.link/LWG3372>`__","``vformat_to``\ should not try to deduce ``Out``\ twice","Prague","|Complete|","14.0","|format|"
-"`3373 <https://wg21.link/LWG3373>`__","``{to,from}_chars_result``\ and ``format_to_n_result``\ need the ""we really mean what we say"" wording","Prague","","","|format|"
+"`3373 <https://wg21.link/LWG3373>`__","``{to,from}_chars_result``\ and ``format_to_n_result``\ need the ""we really mean what we say"" wording","Prague","|Complete|","14.0","|format|"
"`3374 <https://wg21.link/LWG3374>`__","P0653 + P1006 should have made the other ``std::to_address``\ overload ``constexpr``\ ","Prague","|Complete|","12.0"
"`3375 <https://wg21.link/LWG3375>`__","``decay``\ in ``viewable_range``\ should be ``remove_cvref``\ ","Prague","","","|ranges|"
"`3377 <https://wg21.link/LWG3377>`__","``elements_view::iterator``\ befriends a specialization of itself","Prague","","","|ranges|"
diff --git a/libcxx/test/std/utilities/charconv/charconv.syn/from_chars_result.pass.cpp b/libcxx/test/std/utilities/charconv/charconv.syn/from_chars_result.pass.cpp
index 007446b3f03a2..e8f89b741e9a7 100644
--- a/libcxx/test/std/utilities/charconv/charconv.syn/from_chars_result.pass.cpp
+++ b/libcxx/test/std/utilities/charconv/charconv.syn/from_chars_result.pass.cpp
@@ -6,14 +6,19 @@
//
//===----------------------------------------------------------------------===//
-// UNSUPPORTED: c++03, c++11, c++14, c++17
-// UNSUPPORTED: libcpp-no-concepts
+// UNSUPPORTED: c++03, c++11, c++14
+// UNSUPPORTED: c++20 && libcpp-no-concepts
// <charconv>
// struct from_chars_result
// friend bool operator==(const from_chars_result&, const from_chars_result&) = default;
+// [charconv.syn]/2
+// The types to_chars_result and from_chars_result have the data members and
+// special members specified above. They have no base classes or members other
+// than those specified.
+
#include <charconv>
#include <cassert>
@@ -24,17 +29,26 @@
constexpr bool test() {
std::from_chars_result lhs{nullptr, std::errc{}};
+#if TEST_STD_VER > 17
std::from_chars_result rhs{nullptr, std::errc{}};
assert(lhs == rhs);
assert(!(lhs != rhs));
+#endif
+ auto [ptr, ec] = lhs;
+ static_assert(std::is_same_v<decltype(ptr), const char*>);
+ assert(ptr == lhs.ptr);
+ static_assert(std::is_same_v<decltype(ec), std::errc>);
+ assert(ec == lhs.ec);
return true;
}
int main(int, char**) {
+#if TEST_STD_VER > 17
static_assert(std::equality_comparable<std::from_chars_result>);
static_assert(!std::totally_ordered<std::from_chars_result>);
static_assert(!std::three_way_comparable<std::from_chars_result>);
+#endif
assert(test());
static_assert(test());
diff --git a/libcxx/test/std/utilities/charconv/charconv.syn/to_chars_result.pass.cpp b/libcxx/test/std/utilities/charconv/charconv.syn/to_chars_result.pass.cpp
index 2320f917f8254..b34dc3249f6f7 100644
--- a/libcxx/test/std/utilities/charconv/charconv.syn/to_chars_result.pass.cpp
+++ b/libcxx/test/std/utilities/charconv/charconv.syn/to_chars_result.pass.cpp
@@ -6,14 +6,19 @@
//
//===----------------------------------------------------------------------===//
-// UNSUPPORTED: c++03, c++11, c++14, c++17
-// UNSUPPORTED: libcpp-no-concepts
+// UNSUPPORTED: c++03, c++11, c++14
+// UNSUPPORTED: c++20 && libcpp-no-concepts
// <charconv>
// struct to_chars_result
// friend bool operator==(const to_chars_result&, const to_chars_result&) = default;
+// [charconv.syn]/2
+// The types to_chars_result and from_chars_result have the data members and
+// special members specified above. They have no base classes or members other
+// than those specified.
+
#include <charconv>
#include <cassert>
@@ -24,17 +29,26 @@
constexpr bool test() {
std::to_chars_result lhs{nullptr, std::errc{}};
+#if TEST_STD_VER > 17
std::to_chars_result rhs{nullptr, std::errc{}};
assert(lhs == rhs);
assert(!(lhs != rhs));
+#endif
+ auto [ptr, ec] = lhs;
+ static_assert(std::is_same_v<decltype(ptr), char*>);
+ assert(ptr == lhs.ptr);
+ static_assert(std::is_same_v<decltype(ec), std::errc>);
+ assert(ec == lhs.ec);
return true;
}
int main(int, char**) {
+#if TEST_STD_VER > 17
static_assert(std::equality_comparable<std::to_chars_result>);
static_assert(!std::totally_ordered<std::to_chars_result>);
static_assert(!std::three_way_comparable<std::to_chars_result>);
+#endif
assert(test());
static_assert(test());
diff --git a/libcxx/test/std/utilities/format/format.syn/format_to_n_result.pass.cpp b/libcxx/test/std/utilities/format/format.syn/format_to_n_result.pass.cpp
new file mode 100644
index 0000000000000..e83345ce96684
--- /dev/null
+++ b/libcxx/test/std/utilities/format/format.syn/format_to_n_result.pass.cpp
@@ -0,0 +1,53 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+// UNSUPPORTED: libcpp-no-concepts
+// UNSUPPORTED: libcpp-has-no-incomplete-format
+
+// <format>
+
+// struct format_to_n_result
+
+// [format.syn]/1
+// The class template format_to_n_result has the template parameters, data
+// members, and special members specified above. It has no base classes or
+// members other than those specified.
+
+#include <format>
+
+#include <cassert>
+#include <concepts>
+
+#include "test_macros.h"
+
+template <class CharT>
+constexpr void test() {
+ std::format_to_n_result<CharT*> v{nullptr, std::iter_
diff erence_t<CharT*>{42}};
+
+ auto [out, size] = v;
+ static_assert(std::same_as<decltype(out), CharT*>);
+ assert(out == v.out);
+ static_assert(std::same_as<decltype(size), std::iter_
diff erence_t<CharT*>>);
+ assert(size == v.size);
+}
+
+constexpr bool test() {
+ test<char>();
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+ test<wchar_t>();
+#endif
+ return true;
+}
+
+int main(int, char**) {
+ assert(test());
+ static_assert(test());
+
+ return 0;
+}
More information about the libcxx-commits
mailing list