]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Add dg-require-cpp-feature-test to test feature test macros
authorJonathan Wakely <jwakely@redhat.com>
Fri, 22 Mar 2024 22:01:50 +0000 (22:01 +0000)
committerJonathan Wakely <jwakely@redhat.com>
Tue, 26 Mar 2024 11:32:55 +0000 (11:32 +0000)
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.

libstdc++-v3/testsuite/lib/dg-options.exp
libstdc++-v3/testsuite/lib/libstdc++.exp
libstdc++-v3/testsuite/std/text_encoding/cons.cc
libstdc++-v3/testsuite/std/text_encoding/requirements.cc

index 00ca678a53a9f6695c3fb670c45e768c952c3fb0..802bfc0b492b8bedbd301cba0f052ffeef0fd39f 100644 (file)
@@ -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
index 7466fb51c58bca75bf8ed012daf95266c815eea1..2b31c9508269d81ab94991ae53759c2945ae8412 100644 (file)
@@ -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 <version>"
+    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
index 8fcc2ec8c3b9839ef3cdc5666f8fc9d41c239838..4196e32ea8b73be6712536bdd0e2f287e15e6ac6 100644 (file)
@@ -1,4 +1,5 @@
 // { dg-do run { target c++26 } }
+// { dg-require-cpp-feature-test "__cpp_lib_text_encoding" }
 
 #include <text_encoding>
 #include <string_view>
index 6cd71b68225369cbab592c0d720a5a4f63abb2b6..3889b2506884365e5a8f28e3527d8b9c3d75263b 100644 (file)
@@ -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 <text_encoding>