if (cxx_dialect >= cxx20)
flag_concepts = 1;
- /* Enable lifetime extension of range based for temporaries for C++23.
- Diagnose -std=c++23 -fno-range-for-ext-temps. */
- if (cxx_dialect >= cxx23)
- {
- if (OPTION_SET_P (flag_range_for_ext_temps)
- && !flag_range_for_ext_temps)
- error ("%<-fno-range-for-ext-temps%> is incompatible with C++23");
- flag_range_for_ext_temps = 1;
- }
- /* Otherwise default to enabled in GNU modes but allow user to override. */
- else if (cxx_dialect >= cxx11
- && !flag_iso
- && !OPTION_SET_P (flag_range_for_ext_temps))
- flag_range_for_ext_temps = 1;
+ /* Enable lifetime extension of range based for temporaries for C++23. */
+ SET_OPTION_IF_UNSET (&global_options, &global_options_set,
+ flag_range_for_ext_temps, cxx_dialect >= cxx23);
/* -fimmediate-escalation has no effect when immediate functions are not
supported. */
Enable lifetime extension of C++ range based for temporaries.
With @option{-std=c++23} and above this is part of the language standard,
so lifetime of the temporaries is extended until the end of the loop
-regardless of this option. This option allows enabling that behavior also
-in earlier versions of the standard and is enabled by default in the
-GNU dialects, from @option{-std=gnu++11} until @option{-std=gnu++20}.
+by default. This option allows enabling that behavior also
+in earlier versions of the standard.
@opindex fno-rtti
@opindex frtti
// P2718R0 - Wording for P2644R1 Fix for Range-based for Loop
// { dg-do run { target c++11 } }
-// Verify -frange-for-ext-temps is set by default in -std=gnu++* modes.
-// { dg-options "" }
+// Verify -frange-for-ext-temps works in earlier standards.
+// { dg-additional-options "-frange-for-ext-temps" }
#define RANGE_FOR_EXT_TEMPS 1
#include "range-for1.C"
// P2718R0 - Wording for P2644R1 Fix for Range-based for Loop
// { dg-do run { target c++11 } }
-// Verify -frange-for-ext-temps is set by default in -std=gnu++* modes.
+// Verify -frange-for-ext-temps is not set by default in -std=gnu++* modes.
// { dg-options "" }
-#define RANGE_FOR_EXT_TEMPS 1
+#define RANGE_FOR_EXT_TEMPS 0
#include "range-for2.C"
// { dg-additional-options "-std=gnu++17" }
// { dg-require-effective-target tls_runtime }
-#define RANGE_FOR_EXT_TEMPS 1
+#define RANGE_FOR_EXT_TEMPS 0
#include "range-for-1.C"