From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp86.iad3b.emailsrvr.com (smtp86.iad3b.emailsrvr.com [146.20.161.86]) by sourceware.org (Postfix) with ESMTPS id AF9313939813 for ; Tue, 11 Jan 2022 20:13:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org AF9313939813 X-Auth-ID: tom@honermann.net Received: by smtp3.relay.iad3b.emailsrvr.com (Authenticated sender: tom-AT-honermann.net) with ESMTPSA id A13134015A; Tue, 11 Jan 2022 15:13:52 -0500 (EST) Subject: Re: [PATCH] C++ P0482R6 char8_t: declare std::c8rtomb and std::mbrtoc8 if provided by the C library To: Jonathan Wakely Cc: Jonathan Wakely , "libstdc++@gcc.gnu.org" , gcc-patches References: <79037d6b-3c48-eb7b-030a-f388fb988187@honermann.net> <09fb5a3b-fd25-7852-0c62-95afe0740b6c@honermann.net> From: Tom Honermann Message-ID: <723ca8d2-d509-3045-f223-f14ec253dded@honermann.net> Date: Tue, 11 Jan 2022 15:13:52 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/mixed; boundary="------------5FBDA33722C22D408B889D90" Content-Language: en-US X-Classification-ID: 492265ee-be4e-42fc-bbde-31461ba947f8-1-1 X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_BL, RCVD_IN_MSPIKE_L3, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libstdc++@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++ mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 11 Jan 2022 20:13:55 -0000 This is a multi-part message in MIME format. --------------5FBDA33722C22D408B889D90 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit On 1/10/22 4:38 PM, Jonathan Wakely wrote: > On Mon, 10 Jan 2022 at 21:24, Tom Honermann via Libstdc++ > wrote: >> On 1/10/22 8:23 AM, Jonathan Wakely wrote: >>> >>> On Sat, 8 Jan 2022 at 00:42, Tom Honermann via Libstdc++ >>> > wrote: >>> >>> This patch completes implementation of the C++20 proposal P0482R6 >>> [1] by >>> adding declarations of std::c8rtomb() and std::mbrtoc8() in >>> if >>> provided by the C library in . >>> >>> This patch addresses feedback provided in response to a previous >>> patch >>> submission [2]. >>> >>> Autoconf changes determine if the C library declares c8rtomb and >>> mbrtoc8 >>> at global scope when uchar.h is included and compiled with either >>> -fchar8_t or -std=c++20. New >>> _GLIBCXX_USE_UCHAR_C8RTOMB_MBRTOC8_FCHAR8_T >>> and _GLIBCXX_USE_UCHAR_C8RTOMB_MBRTOC8_CXX20 configuration macros >>> reflect the probe results. The header declares these >>> functions >>> in the std namespace only if available and the _GLIBCXX_USE_CHAR8_T >>> configuration macro is defined (by default it is defined if the C++20 >>> __cpp_char8_t feature test macro is defined) >>> >>> Patches to glibc to implement c8rtomb and mbrtoc8 have been >>> submitted [3]. >>> >>> New tests validate the presence of these declarations. The tests pass >>> trivially if the C library does not provide these functions. >>> Otherwise >>> they ensure that the functions are declared when is included >>> and either -fchar8_t or -std=c++20 is enabled. >>> >>> Tested on Linux x86_64. >>> >>> libstdc++-v3/ChangeLog: >>> >>> 2022-01-07 Tom Honermann >> > >>> >>> * acinclude.m4 Define config macros if uchar.h provides >>> c8rtomb() and mbrtoc8(). >>> * config.h.in : Re-generate. >>> * configure: Re-generate. >>> * include/c_compatibility/uchar.h: Declare ::c8rtomb and >>> ::mbrtoc8. >>> * include/c_global/cuchar: Declare std::c8rtomb and >>> std::mbrtoc8. >>> * include/c_std/cuchar: Declare std::c8rtomb and std::mbrtoc8. >>> * testsuite/21_strings/headers/cuchar/functions_std_cxx20.cc: >>> New test. >>> * >>> testsuite/21_strings/headers/cuchar/functions_std_fchar8_t.cc: >>> New test. >>> >>> >>> >>> Thanks, Tom, this looks good and I'll get it committed for GCC 12. >> Thank you! >>> My only concern is that the new tests depend on an internal macro: >>> >>> +#if _GLIBCXX_USE_UCHAR_C8RTOMB_MBRTOC8_CXX20 >>> + using std::mbrtoc8; >>> + using std::c8rtomb; >>> >>> I prefer if tests are written as "user code" when possible, and not >>> using our internal macros. That isn't always possible, and in this >>> case would require adding new effective-target keyword to >>> testsuite/lib/libstdc++.exp just for use in these two tests. I don't >>> think we should bother with that. >> I went with this approach solely due to my unfamiliarity with the test >> system. I knew there should be a way to conditionally make the test >> "pass" as unsupported or as an expected failure, but didn't know how to >> go about implementing that. I don't mind following up with an additional >> patch if such a change is desirable. I took a look at >> testsuite/lib/libstdc++.exp and it looks like it may be pretty straight >> forward to add effective-target support. It would probably be a good >> learning experience for me. I'll prototype and report back. > Yes, it's very easy to do. Take a look at the > check_effective_target_blah procs in that file, especially the later > ones that use v3_check_preprocessor_condition. You can use that to > define an effective target keyword for any preprocessor condition > (such as the new macros you're adding). > > Then the test can do: > // { dg-do compile { target blah } } > which will make it UNSUPPORTED if the effective target proc doesn't return true. > See https://gcc.gnu.org/onlinedocs/gccint/Selectors.html#Selectors for > the docs on target selectors. > > I'm just not sure it's worth adding a new keyword for just two tests. Thank you for the implementation direction; this was quite easy! Patch attached (to be applied after the original one). libstdc++-v3/ChangeLog: 2022-01-11 Tom Honermann * testsuite/21_strings/headers/cuchar/functions_std_cxx20.cc: Modify to use new c8rtomb_mbrtoc8_cxx20 effective target. * testsuite/21_strings/headers/cuchar/functions_std_fchar8_t.cc: Modify to use new c8rtomb_mbrtoc8_fchar8_t effective target. * testsuite/lib/libstdc++.exp: Add new effective targets. If you decide that the new keywords aren't worth adding, no worries; my feelings won't be hurt :) Tom. --------------5FBDA33722C22D408B889D90 Content-Type: text/x-patch; charset=UTF-8; name="p0482r6-n2653-eff-target.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="p0482r6-n2653-eff-target.patch" commit 0542361fe8cb5da146097f86ca8ea8bca86421e0 Author: Tom Honermann Date: Tue Jan 11 14:57:51 2022 -0500 Add effective target support for tests of C++20 c8rtomb and mbrtoc8. diff --git a/libstdc++-v3/testsuite/21_strings/headers/cuchar/functions_std_cxx20.cc b/libstdc++-v3/testsuite/21_strings/headers/cuchar/functions_std_cxx20.cc index 7c152ed42b5..681c12127db 100644 --- a/libstdc++-v3/testsuite/21_strings/headers/cuchar/functions_std_cxx20.cc +++ b/libstdc++-v3/testsuite/21_strings/headers/cuchar/functions_std_cxx20.cc @@ -1,12 +1,10 @@ -// { dg-do compile } +// { dg-do compile { target c8rtomb_mbrtoc8_cxx20 } } // { dg-options "-std=c++20" } #include namespace gnu { -#if _GLIBCXX_USE_UCHAR_C8RTOMB_MBRTOC8_CXX20 using std::mbrtoc8; using std::c8rtomb; -#endif // _GLIBCXX_USE_UCHAR_C8RTOMB_MBRTOC8_CXX20 } diff --git a/libstdc++-v3/testsuite/21_strings/headers/cuchar/functions_std_fchar8_t.cc b/libstdc++-v3/testsuite/21_strings/headers/cuchar/functions_std_fchar8_t.cc index 1cfaf7427e5..836690f0349 100644 --- a/libstdc++-v3/testsuite/21_strings/headers/cuchar/functions_std_fchar8_t.cc +++ b/libstdc++-v3/testsuite/21_strings/headers/cuchar/functions_std_fchar8_t.cc @@ -1,12 +1,10 @@ -// { dg-do compile } +// { dg-do compile { target c8rtomb_mbrtoc8_fchar8_t } } // { dg-options "-fchar8_t" } #include namespace gnu { -#if _GLIBCXX_USE_UCHAR_C8RTOMB_MBRTOC8_FCHAR8_T using std::mbrtoc8; using std::c8rtomb; -#endif // _GLIBCXX_USE_UCHAR_C8RTOMB_MBRTOC8_FCHAR8_T } diff --git a/libstdc++-v3/testsuite/lib/libstdc++.exp b/libstdc++-v3/testsuite/lib/libstdc++.exp index 1a43dd05ba7..7a2379c9982 100644 --- a/libstdc++-v3/testsuite/lib/libstdc++.exp +++ b/libstdc++-v3/testsuite/lib/libstdc++.exp @@ -1346,6 +1346,22 @@ proc check_effective_target_std_allocator_new { } { }] } +# Return 1 if mbrtoc8 and c8rtomb are available for C++20, 0 otherwise. +proc check_effective_target_c8rtomb_mbrtoc8_cxx20 { } { + return [check_v3_target_prop_cached et_c8rtomb_mbrtoc8_cxx20 { + set cond "_GLIBCXX_USE_UCHAR_C8RTOMB_MBRTOC8_CXX20" + return [v3_check_preprocessor_condition c8rtomb_mbrtoc8_cxx20 $cond] + }] +} + +# Return 1 if mbrtoc8 and c8rtomb are available for -fchar8_t, 0 otherwise. +proc check_effective_target_c8rtomb_mbrtoc8_fchar8_t { } { + return [check_v3_target_prop_cached et_c8rtomb_mbrtoc8_fchar8_t { + set cond "_GLIBCXX_USE_UCHAR_C8RTOMB_MBRTOC8_FCHAR8_T" + return [v3_check_preprocessor_condition c8rtomb_mbrtoc8_fchar8_t $cond] + }] +} + set additional_prunes "" if { [info exists env(GCC_RUNTEST_PARALLELIZE_DIR)] \ --------------5FBDA33722C22D408B889D90--