Tested x86_64-pc-linux-gnu, applying to trunk. -- 8< --
I wanted to add more cases to the setting of std_list in g++-dg.exp, but didn't want to do a full scan through the file for each case. So this patch improves that in two ways: first, by extracting all interesting lines on a single pass; second, by generating the list more flexibly: now we test every version mentioned explicitly in the testcase, plus a few more if fewer than three are mentioned. This also lowers changes from testing four to three versions for most testcases: the current default and the earliest and latest versions. This will reduce testing of C++14 and C++20 modes, and increase testing of C++26 mode. C++ front-end developers are encouraged to set the GXX_TESTSUITE_STDS environment variable to test more modes. gcc/testsuite/ChangeLog: * lib/gcc-dg.exp (get_matching_lines): New. * lib/g++-dg.exp: Improve std_list selection. --- gcc/testsuite/lib/g++-dg.exp | 45 +++++++++++++++++++++++++----------- gcc/testsuite/lib/gcc-dg.exp | 13 +++++++++++ 2 files changed, 44 insertions(+), 14 deletions(-) diff --git a/gcc/testsuite/lib/g++-dg.exp b/gcc/testsuite/lib/g++-dg.exp index 52fba75c4a3..991be4d3867 100644 --- a/gcc/testsuite/lib/g++-dg.exp +++ b/gcc/testsuite/lib/g++-dg.exp @@ -53,21 +53,38 @@ proc g++-dg-runtest { testcases flags default-extra-flags } { if { [llength $gpp_std_list] > 0 } { set std_list $gpp_std_list } else { - # If the test requires a newer C++ version than which - # is tested by default, use that C++ version for that - # single test. Or if a test checks behavior specifically for - # one C++ version, include that version in the default list. - # These should be adjusted whenever the default std_list is - # updated or newer C++ effective target is added. - if [search_for $test "\{ dg-do * \{ target c++23"] { - set std_list { 23 26 } - } elseif [search_for $test "\{ dg-do * \{ target c++26"] { - set std_list { 26 } - } elseif [search_for $test "c++11_only"] { - set std_list { 98 11 14 20 } - } else { - set std_list { 98 14 17 20 } + # If the test mentions specific C++ versions, test those. + set lines [get_matching_lines $test {\{ dg* c++[0-9][0-9]}] + set std_list {} + set low 0 + foreach line $lines { + regexp {c\+\+([0-9][0-9])} $line -> ver + lappend std_list $ver + + if { $ver == 98 } { + # Leave low alone. + } elseif { [regexp {dg-do|dg-require-effective-target} $line] } { + set low $ver + } } + #verbose "low: $low" 1 + + set std_list [lsort -unique $std_list] + + # If fewer than 3 specific versions are mentioned, add more. + # The order of this list is significant: first $cxx_default, + # then the oldest and newest, then others in rough order of + # importance based on test coverage and usage. + foreach ver { 17 98 26 11 20 14 23 } { + set cmpver $ver + if { $ver == 98 } { set cmpver 03 } + if { [llength $std_list] < 3 + && $ver ni $std_list + && $cmpver > $low } { + lappend std_list $ver + } + } + verbose "std_list: $std_list" 1 } set option_list { } foreach x $std_list { diff --git a/gcc/testsuite/lib/gcc-dg.exp b/gcc/testsuite/lib/gcc-dg.exp index 228c21d1207..992062103c1 100644 --- a/gcc/testsuite/lib/gcc-dg.exp +++ b/gcc/testsuite/lib/gcc-dg.exp @@ -574,6 +574,19 @@ proc search_for { file pattern } { return 0 } +# get_matching_lines -- return a list of matching lines in file +proc get_matching_lines { file pattern } { + set lines {} + set fd [open $file r] + while { [gets $fd cur_line]>=0 } { + if [string match "*$pattern*" $cur_line] then { + lappend lines $cur_line + } + } + close $fd + return $lines +} + # Modified dg-runtest that can cycle through a list of optimization options # as c-torture does. proc gcc-dg-runtest { testcases flags default-extra-flags } { base-commit: 928116e94a5a8a995dffd926af58abfa7286e78e -- 2.45.2