From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id D19263858C56; Tue, 26 Mar 2024 11:43:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D19263858C56 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1711453427; bh=MK7IysscmVDnVjjkSF1UArMemaUmzSEd5ptkMo74OVM=; h=From:To:Subject:Date:From; b=ZO/G4vwLqftm9OaTOKYTanVZz7pWwHm0XYTJDu92nwGmHn31Kd6669Wq7B+utMXBa 0Cygvy96b8nXABEUr8Oey84sgK2zCeNrz24IVv5BDgDfj/T5LfBoPohi5JAvc4/3EE 5V3FJ06HOCTScT57q9INH6ZmtMToEC2nBGSWp2u4= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jonathan Wakely To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r14-9670] libstdc++: Add dg-require-cpp-feature-test to test feature test macros X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/master X-Git-Oldrev: 4549b0f67d52b4f042ab89a036249545c3938b45 X-Git-Newrev: 4a3a1b6b75f921d35bbfef26619e7b5cece3fcf0 Message-Id: <20240326114347.D19263858C56@sourceware.org> Date: Tue, 26 Mar 2024 11:43:47 +0000 (GMT) List-Id: https://gcc.gnu.org/g:4a3a1b6b75f921d35bbfef26619e7b5cece3fcf0 commit r14-9670-g4a3a1b6b75f921d35bbfef26619e7b5cece3fcf0 Author: Jonathan Wakely Date: Fri Mar 22 22:01:50 2024 +0000 libstdc++: Add dg-require-cpp-feature-test to test feature test macros This adds a new dejagnu directive which can be used to make a test depend on a feature test macro such as __cpp_lib_text_encoding. This is mroe flexible than writing a new dg-require-xxx for each feature. libstdc++-v3/ChangeLog: * testsuite/lib/dg-options.exp (dg-require-cpp-feature-test): New proc. * testsuite/lib/libstdc++.exp (check_v3_target_cpp_feature_test): New proc. * testsuite/std/text_encoding/cons.cc: Use new directive to skip the test if the __cpp_lib_text_encoding feature test macro is not defined. * testsuite/std/text_encoding/requirements.cc: Likewise. Diff: --- libstdc++-v3/testsuite/lib/dg-options.exp | 9 +++++++++ libstdc++-v3/testsuite/lib/libstdc++.exp | 15 +++++++++++++++ libstdc++-v3/testsuite/std/text_encoding/cons.cc | 1 + libstdc++-v3/testsuite/std/text_encoding/requirements.cc | 1 + 4 files changed, 26 insertions(+) diff --git a/libstdc++-v3/testsuite/lib/dg-options.exp b/libstdc++-v3/testsuite/lib/dg-options.exp index 00ca678a53a..802bfc0b492 100644 --- a/libstdc++-v3/testsuite/lib/dg-options.exp +++ b/libstdc++-v3/testsuite/lib/dg-options.exp @@ -277,6 +277,15 @@ proc dg-require-target-fs-lwt { args } { return } +proc dg-require-cpp-feature-test { n args } { + if { ![ check_v3_target_cpp_feature_test $args ] } { + upvar dg-do-what dg-do-what + set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"] + return + } + return +} + proc add_options_for_no_pch { flags } { # Remove any inclusion of bits/stdc++.h from the options. regsub -all -- "-include bits/stdc...h" $flags "" flags diff --git a/libstdc++-v3/testsuite/lib/libstdc++.exp b/libstdc++-v3/testsuite/lib/libstdc++.exp index 7466fb51c58..2b31c950826 100644 --- a/libstdc++-v3/testsuite/lib/libstdc++.exp +++ b/libstdc++-v3/testsuite/lib/libstdc++.exp @@ -1134,6 +1134,21 @@ proc v3_check_preprocessor_condition { name cond { inc "" } } { return [v3_try_preprocess name $code $flags] } +# Return 1 if libstdc++ defines macro for the current target, 0 otherwise. +proc check_v3_target_cpp_feature_test { cond } { + global cxxflags + set cxxflags_saved $cxxflags + # Use the latest standard, so that all feature test macros are defined. + # We need to do it here, because this check happens before v3-dg-runtest + # runs its loop to test multiple times with different -std options. + # This should be updated when a new -std is added. + set cxxflags "$cxxflags -std=gnu++26" + set inc "#include " + set result [v3_check_preprocessor_condition cpp_feature_test "$cond" $inc] + set cxxflags $cxxflags_saved + return $result +} + # Return 1 if Debug Mode is active, 0 otherwise. proc check_v3_target_debug_mode { } { global cxxflags diff --git a/libstdc++-v3/testsuite/std/text_encoding/cons.cc b/libstdc++-v3/testsuite/std/text_encoding/cons.cc index 8fcc2ec8c3b..4196e32ea8b 100644 --- a/libstdc++-v3/testsuite/std/text_encoding/cons.cc +++ b/libstdc++-v3/testsuite/std/text_encoding/cons.cc @@ -1,4 +1,5 @@ // { dg-do run { target c++26 } } +// { dg-require-cpp-feature-test "__cpp_lib_text_encoding" } #include #include diff --git a/libstdc++-v3/testsuite/std/text_encoding/requirements.cc b/libstdc++-v3/testsuite/std/text_encoding/requirements.cc index 6cd71b68225..3889b250688 100644 --- a/libstdc++-v3/testsuite/std/text_encoding/requirements.cc +++ b/libstdc++-v3/testsuite/std/text_encoding/requirements.cc @@ -1,4 +1,5 @@ // { dg-do compile { target c++26 } } +// { dg-require-cpp-feature-test __cpp_lib_text_encoding } // { dg-add-options no_pch } #include