On 8/9/24 9:06 PM, Jakub Jelinek wrote:
Hi!
The following patch implements the C++23 P2718R0 paper
- Wording for P2644R1 Fix for Range-based for Loop.
As all the temporaries from __for_range initialization should have life
extended until the end of __for_range scope, this patch disables (for C++23
and later only and if !processing_template_decl) CLEANUP_POINT_EXPR wrapping
of the __for_range declaration, also disables -Wdangling-reference warning
as well as the rest of extend_ref_init_temps (we know the __for_range temporary
is not TREE_STATIC and as all the temporaries from the initializer will be life
extended, we shouldn't try to handle temporaries referenced by references any
differently) and adds an extra push_stmt_list/pop_stmt_list before
cp_finish_decl of __for_range and after end of the for body and wraps all
that into CLEANUP_POINT_EXPR.
I had to repeat that also for OpenMP range loops because those are handled
differently.
Let's add a flag for this, not just control it with cxx_dialect. We
might want to consider enabling it by default in earlier modes when not
being strictly conforming?
@@ -44600,11 +44609,14 @@ cp_convert_omp_range_for (tree &this_pre
else
{
range_temp = build_range_temp (init);
+ tree name = DECL_NAME (range_temp);
DECL_NAME (range_temp) = NULL_TREE;
pushdecl (range_temp);
+ DECL_NAME (range_temp) = name;
cp_finish_decl (range_temp, init,
/*is_constant_init*/false, NULL_TREE,
LOOKUP_ONLYCONVERTING);
+ DECL_NAME (range_temp) = NULL_TREE;
This messing with the name needs a rationale. What wants it to be null?
Jason