diff --git a/libcxx/docs/FeatureTestMacroTable.rst b/libcxx/docs/FeatureTestMacroTable.rst --- a/libcxx/docs/FeatureTestMacroTable.rst +++ b/libcxx/docs/FeatureTestMacroTable.rst @@ -406,6 +406,8 @@ --------------------------------------------------- ----------------- ``__cpp_lib_text_encoding`` *unimplemented* --------------------------------------------------- ----------------- + ``__cpp_lib_to_chars`` *unimplemented* + --------------------------------------------------- ----------------- ``__cpp_lib_within_lifetime`` *unimplemented* =================================================== ================= diff --git a/libcxx/docs/Status/Cxx2cPapers.csv b/libcxx/docs/Status/Cxx2cPapers.csv --- a/libcxx/docs/Status/Cxx2cPapers.csv +++ b/libcxx/docs/Status/Cxx2cPapers.csv @@ -1,5 +1,5 @@ "Paper #","Group","Paper Name","Meeting","Status","First released version","Labels" -"`P2497R0 `__","LWG","Testing for success or failure of ```` functions","Varna June 2023","","","" +"`P2497R0 `__","LWG","Testing for success or failure of ```` functions","Varna June 2023","|Complete|","17.0","" "`P2592R3 `__","LWG","Hashing support for ``std::chrono`` value classes","Varna June 2023","","","" "`P2587R3 `__","LWG","``to_string`` or not ``to_string``","Varna June 2023","","","|format|" "`P2562R1 `__","LWG","``constexpr`` Stable Sorting","Varna June 2023","","","" diff --git a/libcxx/include/__charconv/from_chars_result.h b/libcxx/include/__charconv/from_chars_result.h --- a/libcxx/include/__charconv/from_chars_result.h +++ b/libcxx/include/__charconv/from_chars_result.h @@ -27,6 +27,9 @@ # if _LIBCPP_STD_VER >= 20 _LIBCPP_HIDE_FROM_ABI friend bool operator==(const from_chars_result&, const from_chars_result&) = default; # endif +# if _LIBCPP_STD_VER >= 26 + _LIBCPP_HIDE_FROM_ABI constexpr explicit operator bool() const noexcept { return ec == errc{}; } +# endif }; #endif // _LIBCPP_STD_VER >= 17 diff --git a/libcxx/include/__charconv/to_chars_result.h b/libcxx/include/__charconv/to_chars_result.h --- a/libcxx/include/__charconv/to_chars_result.h +++ b/libcxx/include/__charconv/to_chars_result.h @@ -27,6 +27,9 @@ # if _LIBCPP_STD_VER >= 20 _LIBCPP_HIDE_FROM_ABI friend bool operator==(const to_chars_result&, const to_chars_result&) = default; # endif +# if _LIBCPP_STD_VER >= 26 + _LIBCPP_HIDE_FROM_ABI constexpr explicit operator bool() const noexcept { return ec == errc{}; } +# endif }; #endif // _LIBCPP_STD_VER >= 17 diff --git a/libcxx/include/charconv b/libcxx/include/charconv --- a/libcxx/include/charconv +++ b/libcxx/include/charconv @@ -28,6 +28,7 @@ char* ptr; errc ec; friend bool operator==(const to_chars_result&, const to_chars_result&) = default; // since C++20 + constexpr explicit operator bool() const noexcept { return ec == errc{}; } // since C++26 }; constexpr to_chars_result to_chars(char* first, char* last, see below value, @@ -58,6 +59,7 @@ const char* ptr; errc ec; friend bool operator==(const from_chars_result&, const from_chars_result&) = default; // since C++20 + constexpr explicit operator bool() const noexcept { return ec == errc{}; } // since C++26 }; constexpr from_chars_result from_chars(const char* first, const char* last, diff --git a/libcxx/include/version b/libcxx/include/version --- a/libcxx/include/version +++ b/libcxx/include/version @@ -201,7 +201,8 @@ __cpp_lib_three_way_comparison 201907L __cpp_lib_to_address 201711L __cpp_lib_to_array 201907L -__cpp_lib_to_chars 201611L +__cpp_lib_to_chars 202306L + 201611L // C++17 __cpp_lib_to_string 202306L __cpp_lib_to_underlying 202102L __cpp_lib_transformation_trait_aliases 201304L @@ -466,6 +467,8 @@ // # define __cpp_lib_sstream_from_string_view 202306L // # define __cpp_lib_submdspan 202306L // # define __cpp_lib_text_encoding 202306L +# undef __cpp_lib_to_chars +// # define __cpp_lib_to_chars 202306L // # define __cpp_lib_within_lifetime 202306L #endif diff --git a/libcxx/test/std/language.support/support.limits/support.limits.general/charconv.version.compile.pass.cpp b/libcxx/test/std/language.support/support.limits/support.limits.general/charconv.version.compile.pass.cpp --- a/libcxx/test/std/language.support/support.limits/support.limits.general/charconv.version.compile.pass.cpp +++ b/libcxx/test/std/language.support/support.limits/support.limits.general/charconv.version.compile.pass.cpp @@ -18,6 +18,7 @@ /* Constant Value __cpp_lib_constexpr_charconv 202207L [C++23] __cpp_lib_to_chars 201611L [C++17] + 202306L [C++26] */ #include @@ -116,8 +117,8 @@ # ifndef __cpp_lib_to_chars # error "__cpp_lib_to_chars should be defined in c++26" # endif -# if __cpp_lib_to_chars != 201611L -# error "__cpp_lib_to_chars should have the value 201611L in c++26" +# if __cpp_lib_to_chars != 202306L +# error "__cpp_lib_to_chars should have the value 202306L in c++26" # endif # else // _LIBCPP_VERSION # ifdef __cpp_lib_to_chars diff --git a/libcxx/test/std/language.support/support.limits/support.limits.general/version.version.compile.pass.cpp b/libcxx/test/std/language.support/support.limits/support.limits.general/version.version.compile.pass.cpp --- a/libcxx/test/std/language.support/support.limits/support.limits.general/version.version.compile.pass.cpp +++ b/libcxx/test/std/language.support/support.limits/support.limits.general/version.version.compile.pass.cpp @@ -187,6 +187,7 @@ __cpp_lib_to_address 201711L [C++20] __cpp_lib_to_array 201907L [C++20] __cpp_lib_to_chars 201611L [C++17] + 202306L [C++26] __cpp_lib_to_string 202306L [C++23] __cpp_lib_to_underlying 202102L [C++23] __cpp_lib_transformation_trait_aliases 201304L [C++14] @@ -6892,8 +6893,8 @@ # ifndef __cpp_lib_to_chars # error "__cpp_lib_to_chars should be defined in c++26" # endif -# if __cpp_lib_to_chars != 201611L -# error "__cpp_lib_to_chars should have the value 201611L in c++26" +# if __cpp_lib_to_chars != 202306L +# error "__cpp_lib_to_chars should have the value 202306L in c++26" # endif # else // _LIBCPP_VERSION # ifdef __cpp_lib_to_chars diff --git a/libcxx/test/std/utilities/charconv/charconv.syn/from_chars_result.operator_bool.pass.cpp b/libcxx/test/std/utilities/charconv/charconv.syn/from_chars_result.operator_bool.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/utilities/charconv/charconv.syn/from_chars_result.operator_bool.pass.cpp @@ -0,0 +1,44 @@ +//===----------------------------------------------------------------------===// +// +// 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, c++23 + +// + +// struct from_chars_result +// constexpr explicit operator bool() const noexcept { return ec == errc{}; } + +#include + +#include + +#include "test_macros.h" + +constexpr bool test() { + // True + { + std::from_chars_result value{nullptr, std::errc{}}; + assert(bool(value) == true); + static_assert(noexcept(bool(true)) == true); + } + // False + { + std::from_chars_result value{nullptr, std::errc::value_too_large}; + assert(bool(value) == false); + static_assert(noexcept(bool(true)) == true); + } + + return true; +} + +int main(int, char**) { + assert(test()); + static_assert(test()); + + return 0; +} diff --git a/libcxx/test/std/utilities/charconv/charconv.syn/from_chars_result.operator_bool.verify.cpp b/libcxx/test/std/utilities/charconv/charconv.syn/from_chars_result.operator_bool.verify.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/utilities/charconv/charconv.syn/from_chars_result.operator_bool.verify.cpp @@ -0,0 +1,23 @@ +//===----------------------------------------------------------------------===// +// +// 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, c++23 + +// + +// struct from_chars_result +// constexpr explicit operator bool() const noexcept { return ec == errc{}; } + +#include + +void test() { + // expected-error@+1 {{no viable conversion from 'std::from_chars_result' to 'bool'}} + [[maybe_unused]] bool implicit = std::from_chars_result{nullptr, std::errc{}}; + if (std::from_chars_result{nullptr, std::errc{}}) { + } +} diff --git a/libcxx/test/std/utilities/charconv/charconv.syn/to_chars_result.operator_bool.pass.cpp b/libcxx/test/std/utilities/charconv/charconv.syn/to_chars_result.operator_bool.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/utilities/charconv/charconv.syn/to_chars_result.operator_bool.pass.cpp @@ -0,0 +1,44 @@ +//===----------------------------------------------------------------------===// +// +// 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, c++23 + +// + +// struct to_chars_result +// constexpr explicit operator bool() const noexcept { return ec == errc{}; } + +#include + +#include + +#include "test_macros.h" + +constexpr bool test() { + // True + { + std::to_chars_result value{nullptr, std::errc{}}; + assert(bool(value) == true); + static_assert(noexcept(bool(true)) == true); + } + // False + { + std::to_chars_result value{nullptr, std::errc::value_too_large}; + assert(bool(value) == false); + static_assert(noexcept(bool(true)) == true); + } + + return true; +} + +int main(int, char**) { + assert(test()); + static_assert(test()); + + return 0; +} diff --git a/libcxx/test/std/utilities/charconv/charconv.syn/to_chars_result.operator_bool.verify.cpp b/libcxx/test/std/utilities/charconv/charconv.syn/to_chars_result.operator_bool.verify.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/utilities/charconv/charconv.syn/to_chars_result.operator_bool.verify.cpp @@ -0,0 +1,23 @@ +//===----------------------------------------------------------------------===// +// +// 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, c++23 + +// + +// struct to_chars_result +// constexpr explicit operator bool() const noexcept { return ec == errc{}; } + +#include + +void test() { + // expected-error@+1 {{no viable conversion from 'std::to_chars_result' to 'bool'}} + [[maybe_unused]] bool implicit = std::to_chars_result{nullptr, std::errc{}}; + if (std::to_chars_result{nullptr, std::errc{}}) { + } +} diff --git a/libcxx/utils/generate_feature_test_macro_components.py b/libcxx/utils/generate_feature_test_macro_components.py --- a/libcxx/utils/generate_feature_test_macro_components.py +++ b/libcxx/utils/generate_feature_test_macro_components.py @@ -1045,7 +1045,7 @@ "name": "__cpp_lib_to_chars", "values": { "c++17": 201611, - #"c++26: 202306, # P2497R0 Testing for success or failure of functions + "c++26": 202306, # P2497R0 Testing for success or failure of functions }, "headers": ["charconv"], "unimplemented": True,