Skip to content

Commit 556248d

Browse files
committed
c++: don't default -frange-for-ext-temps in -std=gnu++20 [PR188574]
Since -frange-for-ext-temps has been causing trouble, let's not enable it by default in pre-C++23 GNU modes for GCC 15, and also allow disabling it in C++23 and up. PR c++/188574 gcc/c-family/ChangeLog: * c-opts.cc (c_common_post_options): Only enable -frange-for-ext-temps by default in C++23. gcc/ChangeLog: * doc/invoke.texi: Adjust -frange-for-ext-temps documentation. gcc/testsuite/ChangeLog: * g++.dg/cpp23/range-for3.C: Use -frange-for-ext-temps. * g++.dg/cpp23/range-for4.C: Adjust expected result. libgomp/ChangeLog: * testsuite/libgomp.c++/range-for-4.C: Adjust expected result.
1 parent 0d2a5f3 commit 556248d

File tree

5 files changed

+10
-22
lines changed

5 files changed

+10
-22
lines changed

gcc/c-family/c-opts.cc

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,20 +1213,9 @@ c_common_post_options (const char **pfilename)
12131213
if (cxx_dialect >= cxx20)
12141214
flag_concepts = 1;
12151215

1216-
/* Enable lifetime extension of range based for temporaries for C++23.
1217-
Diagnose -std=c++23 -fno-range-for-ext-temps. */
1218-
if (cxx_dialect >= cxx23)
1219-
{
1220-
if (OPTION_SET_P (flag_range_for_ext_temps)
1221-
&& !flag_range_for_ext_temps)
1222-
error ("%<-fno-range-for-ext-temps%> is incompatible with C++23");
1223-
flag_range_for_ext_temps = 1;
1224-
}
1225-
/* Otherwise default to enabled in GNU modes but allow user to override. */
1226-
else if (cxx_dialect >= cxx11
1227-
&& !flag_iso
1228-
&& !OPTION_SET_P (flag_range_for_ext_temps))
1229-
flag_range_for_ext_temps = 1;
1216+
/* Enable lifetime extension of range based for temporaries for C++23. */
1217+
SET_OPTION_IF_UNSET (&global_options, &global_options_set,
1218+
flag_range_for_ext_temps, cxx_dialect >= cxx23);
12301219

12311220
/* -fimmediate-escalation has no effect when immediate functions are not
12321221
supported. */

gcc/doc/invoke.texi

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3548,9 +3548,8 @@ easier, you can use @option{-fno-pretty-templates} to disable them.
35483548
Enable lifetime extension of C++ range based for temporaries.
35493549
With @option{-std=c++23} and above this is part of the language standard,
35503550
so lifetime of the temporaries is extended until the end of the loop
3551-
regardless of this option. This option allows enabling that behavior also
3552-
in earlier versions of the standard and is enabled by default in the
3553-
GNU dialects, from @option{-std=gnu++11} until @option{-std=gnu++20}.
3551+
by default. This option allows enabling that behavior also
3552+
in earlier versions of the standard.
35543553

35553554
@opindex fno-rtti
35563555
@opindex frtti
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// P2718R0 - Wording for P2644R1 Fix for Range-based for Loop
22
// { dg-do run { target c++11 } }
3-
// Verify -frange-for-ext-temps is set by default in -std=gnu++* modes.
4-
// { dg-options "" }
3+
// Verify -frange-for-ext-temps works in earlier standards.
4+
// { dg-additional-options "-frange-for-ext-temps" }
55

66
#define RANGE_FOR_EXT_TEMPS 1
77
#include "range-for1.C"
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// P2718R0 - Wording for P2644R1 Fix for Range-based for Loop
22
// { dg-do run { target c++11 } }
3-
// Verify -frange-for-ext-temps is set by default in -std=gnu++* modes.
3+
// Verify -frange-for-ext-temps is not set by default in -std=gnu++* modes.
44
// { dg-options "" }
55

6-
#define RANGE_FOR_EXT_TEMPS 1
6+
#define RANGE_FOR_EXT_TEMPS 0
77
#include "range-for2.C"

libgomp/testsuite/libgomp.c++/range-for-4.C

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
// { dg-additional-options "-std=gnu++17" }
44
// { dg-require-effective-target tls_runtime }
55

6-
#define RANGE_FOR_EXT_TEMPS 1
6+
#define RANGE_FOR_EXT_TEMPS 0
77
#include "range-for-1.C"

0 commit comments

Comments
 (0)