[gcc r16-653] c++: use normal std list for module tests

Jason Merrill jason@gcc.gnu.org
Thu May 15 14:32:32 GMT 2025


https://gcc.gnu.org/g:9a2083f025fae3559474b961943484d764c2e6dd

commit r16-653-g9a2083f025fae3559474b961943484d764c2e6dd
Author: Jason Merrill <jason@redhat.com>
Date:   Mon Nov 18 19:48:41 2024 +0100

    c++: use normal std list for module tests
    
    The modules tests have used their own version of the code to run tests under
    multiple standard versions; they should use the same one as other tests.
    
    I'm not sure about continuing to run modules tests in C++17 mode, but I
    guess we might as well for now.
    
    gcc/testsuite/ChangeLog:
    
            * lib/g++-dg.exp (g++-std-flags): Factor out of g++-dg-runtest.
            * g++.dg/modules/modules.exp: Use it instead of a copy.

Diff:
---
 gcc/testsuite/g++.dg/modules/modules.exp |  39 ++--------
 gcc/testsuite/lib/g++-dg.exp             | 129 +++++++++++++++++--------------
 2 files changed, 78 insertions(+), 90 deletions(-)

diff --git a/gcc/testsuite/g++.dg/modules/modules.exp b/gcc/testsuite/g++.dg/modules/modules.exp
index 81d0bebdfe5a..73b5de1397fa 100644
--- a/gcc/testsuite/g++.dg/modules/modules.exp
+++ b/gcc/testsuite/g++.dg/modules/modules.exp
@@ -36,7 +36,6 @@ if ![info exists DEFAULT_CXXFLAGS] then {
     set DEFAULT_CXXFLAGS " -pedantic-errors -Wno-long-long"
 }
 set DEFAULT_MODFLAGS $DEFAULT_CXXFLAGS
-set MOD_STD_LIST { 17 2a 2b }
 
 dg-init
 
@@ -261,44 +260,16 @@ proc srcdir {} {
     return $testdir
 }
 
-# Return set of std options to iterate over, taken from g++-dg.exp & compat.exp
+# Return set of std options to iterate over.
 proc module-init { src } {
-    set tmp [dg-get-options $src]
-    set option_list {}
-    set have_std 0
-    set std_prefix "-std=c++"
+    set option_list [g++-std-flags $src]
     global extra_tool_flags
     set extra_tool_flags {}
-    global MOD_STD_LIST
 
-    foreach op $tmp {
-	switch [lindex $op 0] {
-	    "dg-options" {
-		set std_prefix "-std=gnu++"
-		if { [string match "*-std=*" [lindex $op 2]] } {
-		    set have_std 1
-		}
-		eval lappend extra_tool_flags [lindex $op 2]
-	    }
-	    "dg-additional-options" {
-		if { [string match "*-std=*" [lindex $op 2]] } {
-		    set have_std 1
-		}
-		eval lappend extra_tool_flags [lindex $op 2]
-	    }
-	}
-    }
-
-    if { $have_std } {
-	lappend option_list ""
-    } elseif { [string match "*xtreme*" $src] } {
+    if { [llength $option_list]
+	 && [string match "*xtreme*" $src] } {
 	# Only run the xtreme tests once.
-	set x [lindex $MOD_STD_LIST end]
-	lappend option_list "${std_prefix}$x"
-    } else {
-	foreach x $MOD_STD_LIST {
-	    lappend option_list "${std_prefix}$x"
-	}
+	set option_list [lrange [lsort $option_list] end end]
     }
 
     return $option_list
diff --git a/gcc/testsuite/lib/g++-dg.exp b/gcc/testsuite/lib/g++-dg.exp
index 26bda651e01e..eb7a9714bc4d 100644
--- a/gcc/testsuite/lib/g++-dg.exp
+++ b/gcc/testsuite/lib/g++-dg.exp
@@ -27,6 +27,78 @@ proc g++-dg-prune { system text } {
     return [gcc-dg-prune $system $text]
 }
 
+# Return a list of -std flags to use for TEST.
+proc g++-std-flags { test } {
+    # If the testcase specifies a standard, use that one.
+    # If not, run it under several standards, allowing GNU extensions
+    # if there's a dg-options line.
+    if ![search_for $test "-std=*++"] {
+	if [search_for $test "dg-options"] {
+	    set std_prefix "-std=gnu++"
+	} else {
+	    set std_prefix "-std=c++"
+	}
+
+	set low 0
+	# Some directories expect certain minimums.
+	if { [string match "*/modules/*" $test] } { set low 17 }
+
+	# See g++.exp for the initial value of this list.
+	global gpp_std_list
+	if { [llength $gpp_std_list] > 0 } {
+	    set std_list {}
+	    foreach ver $gpp_std_list {
+		set cmpver $ver
+		if { $ver == 98 } { set cmpver 03 }
+		if { $ver ni $std_list
+		     && $cmpver >= $low } {
+		    lappend std_list $ver
+		}
+	    }
+	} else {
+	    # If the test mentions specific C++ versions, test those.
+	    set lines [get_matching_lines $test {\{ dg* c++[0-9][0-9]}]
+	    set std_list {}
+	    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 {
+	    if { $x eq "impcx" } then { set x "26 -fimplicit-constexpr" }
+	    lappend option_list "${std_prefix}$x"
+	}
+    } else {
+	set option_list { "" }
+    }
+    return $option_list
+}
+
 # Modified dg-runtest that runs tests in multiple standard modes,
 # unless they specifically specify one standard.
 proc g++-dg-runtest { testcases flags default-extra-flags } {
@@ -38,62 +110,7 @@ proc g++-dg-runtest { testcases flags default-extra-flags } {
 	    continue
 	}
 
-	# If the testcase specifies a standard, use that one.
-	# If not, run it under several standards, allowing GNU extensions
-	# if there's a dg-options line.
-	if ![search_for $test "-std=*++"] {
-	    if [search_for $test "dg-options"] {
-		set std_prefix "-std=gnu++"
-	    } else {
-		set std_prefix "-std=c++"
-	    }
-
-	    # See g++.exp for the initial value of this list.
-	    global gpp_std_list
-	    if { [llength $gpp_std_list] > 0 } {
-		set std_list $gpp_std_list
-	    } else {
-		# 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 {
-		if { $x eq "impcx" } then { set x "26 -fimplicit-constexpr" }
-		lappend option_list "${std_prefix}$x"
-	    }
-	} else {
-	    set option_list { "" }
-	}
+	set option_list [g++-std-flags $test]
 
 	set nshort [file tail [file dirname $test]]/[file tail $test]


More information about the Gcc-cvs mailing list