diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 41849756f97..a19af885d39 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2020-09-25  Gary Benson <gbenson@redhat.com>
+
+	* lib/gdb.exp (gdb_compile): Pass "-x c++" earlier, and only
+	for .c files.
+
 2020-09-24  Tom Tromey  <tromey@adacore.com>
 
 	PR tui/26638:
diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index 59439f8e379..608469953bf 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -3944,8 +3944,9 @@ proc gdb_compile {source dest type options} {
     # explicitly force C++ language.
     if { [lsearch -exact $options getting_compiler_info] == -1
 	 && [lsearch -exact $options c++] != -1
-	 && [test_compiler_info "clang-*"]} {
-	lappend new_options additional_flags=-x\ c++
+	 && [string match *.c $source] != 0
+	 && [test_compiler_info "clang-*"] } {
+	lappend new_options early_flags=-x\ c++
     }
 
     # Place (and look for) Fortran `.mod` files in the output