Skip to content

Commit dab0f35

Browse files
committed
c++: improve C++ testsuite default versions
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.
1 parent 928116e commit dab0f35

File tree

2 files changed

+44
-14
lines changed

2 files changed

+44
-14
lines changed

gcc/testsuite/lib/g++-dg.exp

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,21 +53,38 @@ proc g++-dg-runtest { testcases flags default-extra-flags } {
5353
if { [llength $gpp_std_list] > 0 } {
5454
set std_list $gpp_std_list
5555
} else {
56-
# If the test requires a newer C++ version than which
57-
# is tested by default, use that C++ version for that
58-
# single test. Or if a test checks behavior specifically for
59-
# one C++ version, include that version in the default list.
60-
# These should be adjusted whenever the default std_list is
61-
# updated or newer C++ effective target is added.
62-
if [search_for $test "\{ dg-do * \{ target c++23"] {
63-
set std_list { 23 26 }
64-
} elseif [search_for $test "\{ dg-do * \{ target c++26"] {
65-
set std_list { 26 }
66-
} elseif [search_for $test "c++11_only"] {
67-
set std_list { 98 11 14 20 }
68-
} else {
69-
set std_list { 98 14 17 20 }
56+
# If the test mentions specific C++ versions, test those.
57+
set lines [get_matching_lines $test {\{ dg* c++[0-9][0-9]}]
58+
set std_list {}
59+
set low 0
60+
foreach line $lines {
61+
regexp {c\+\+([0-9][0-9])} $line -> ver
62+
lappend std_list $ver
63+
64+
if { $ver == 98 } {
65+
# Leave low alone.
66+
} elseif { [regexp {dg-do|dg-require-effective-target} $line] } {
67+
set low $ver
68+
}
69+
}
70+
#verbose "low: $low" 1
71+
72+
set std_list [lsort -unique $std_list]
73+
74+
# If fewer than 3 specific versions are mentioned, add more.
75+
# The order of this list is significant: first $cxx_default,
76+
# then the oldest and newest, then others in rough order of
77+
# importance based on test coverage and usage.
78+
foreach ver { 17 98 26 11 20 14 23 } {
79+
set cmpver $ver
80+
if { $ver == 98 } { set cmpver 03 }
81+
if { [llength $std_list] < 3
82+
&& $ver ni $std_list
83+
&& $cmpver > $low } {
84+
lappend std_list $ver
85+
}
7086
}
87+
verbose "std_list: $std_list" 1
7188
}
7289
set option_list { }
7390
foreach x $std_list {

gcc/testsuite/lib/gcc-dg.exp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,19 @@ proc search_for { file pattern } {
574574
return 0
575575
}
576576

577+
# get_matching_lines -- return a list of matching lines in file
578+
proc get_matching_lines { file pattern } {
579+
set lines {}
580+
set fd [open $file r]
581+
while { [gets $fd cur_line]>=0 } {
582+
if [string match "*$pattern*" $cur_line] then {
583+
lappend lines $cur_line
584+
}
585+
}
586+
close $fd
587+
return $lines
588+
}
589+
577590
# Modified dg-runtest that can cycle through a list of optimization options
578591
# as c-torture does.
579592
proc gcc-dg-runtest { testcases flags default-extra-flags } {

0 commit comments

Comments
 (0)