https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107637

--- Comment #4 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <ja...@gcc.gnu.org>:

https://gcc.gnu.org/g:650e91566561870f3d1c8d5b92e6613296ee1a8d

commit r15-3840-g650e91566561870f3d1c8d5b92e6613296ee1a8d
Author: Jakub Jelinek <ja...@redhat.com>
Date:   Tue Sep 24 20:19:50 2024 +0200

    c++: Implement C++23 P2718R0 - Wording for P2644R1 Fix for Range-based for
Loop [PR107637]

    The following patch implements the C++23 P2718R0 paper
    - Wording for P2644R1 Fix for Range-based for Loop.
    The patch introduces a new option, -f{,no-}range-for-ext-temps so that
    user can control the behavior even in older C++ versions.
    The option is on by default in C++23 and later (-fno-range-for-ext-temps
    is an error in that case) and in the -std=gnu++11 ... -std=gnu++20 modes
    (one can use -fno-range-for-ext-temps to request previous behavior in that
    case), and is not enabled by default in -std=c++11 ... -std=c++20 modes
    but one can explicitly enable it with -frange-for-ext-temps.
    As all the temporaries from __for_range initialization should have life
    extended until the end of __for_range scope, this patch disables (for
    -frange-for-ext-temps 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.

    2024-09-24  Jakub Jelinek  <ja...@redhat.com>

            PR c++/107637
    gcc/
            * omp-general.cc (find_combined_omp_for, find_nested_loop_xform):
            Handle CLEANUP_POINT_EXPR like TRY_FINALLY_EXPR.
            * doc/invoke.texi (frange-for-ext-temps): Document.  Add
            -fconcepts to the C++ option list.
    gcc/c-family/
            * c.opt (frange-for-ext-temps): New option.
            * c-opts.cc (c_common_post_options): Set flag_range_for_ext_temps
            for C++23 or later or for C++11 or later in !flag_iso mode if
            the option wasn't set by user.
            * c-cppbuiltin.cc (c_cpp_builtins): Change __cpp_range_based_for
            value for flag_range_for_ext_temps from 201603L to 202212L in C++17
            or later.
            * c-omp.cc (c_find_nested_loop_xform_r): Handle CLEANUP_POINT_EXPR
            like TRY_FINALLY_EXPR.
    gcc/cp/
            * cp-tree.h: Implement C++23 P2718R0 - Wording for P2644R1 Fix for
            Range-based for Loop.
            (cp_convert_omp_range_for): Add bool tmpl_p argument.
            (find_range_for_decls): Declare.
            * parser.cc (cp_convert_range_for): For flag_range_for_ext_temps
call
            push_stmt_list () before cp_finish_decl for range_temp and save it
            temporarily to FOR_INIT_STMT.
            (cp_convert_omp_range_for): Add tmpl_p argument.  If set, remember
            DECL_NAME of range_temp and for cp_finish_decl call restore it
before
            clearing it again, if unset, don't adjust DECL_NAME of range_temp
at
            all.
            (cp_parser_omp_loop_nest): For flag_range_for_ext_temps range for
add
            CLEANUP_POINT_EXPR around sl.  Call find_range_for_decls and adjust
            DECL_NAMEs for range fors if not processing_template_decl.  Adjust
            cp_convert_omp_range_for caller.  Remove superfluous backslash at
the
            end of line.
            * decl.cc (initialize_local_var): For flag_range_for_ext_temps
            temporarily clear stmts_are_full_exprs_p rather than set for
            for_range__identifier decls.
            * call.cc (extend_ref_init_temps): For flag_range_for_ext_temps
return
            init early for for_range__identifier decls.
            * semantics.cc (find_range_for_decls): New function.
            (finish_for_stmt): Use it.  For flag_range_for_ext_temps if
            cp_convert_range_for set FOR_INIT_STMT, pop_stmt_list it and wrap
            into CLEANUP_POINT_EXPR.
            * pt.cc (tsubst_omp_for_iterator): Adjust tsubst_omp_for_iterator
            caller.
            (tsubst_stmt) <case OMP_FOR>: For flag_range_for_ext_temps if there
            are any range fors in the loop nest, add push_stmt_list starting
            before the initializations, pop_stmt_list it after the body and
wrap
            into CLEANUP_POINT_EXPR.  Change DECL_NAME of range for temps from
            NULL to for_range_identifier.
    gcc/testsuite/
            * g++.dg/cpp23/range-for1.C: New test.
            * g++.dg/cpp23/range-for2.C: New test.
            * g++.dg/cpp23/range-for3.C: New test.
            * g++.dg/cpp23/range-for4.C: New test.
            * g++.dg/cpp23/range-for5.C: New test.
            * g++.dg/cpp23/range-for6.C: New test.
            * g++.dg/cpp23/range-for7.C: New test.
            * g++.dg/cpp23/range-for8.C: New test.
            * g++.dg/cpp23/feat-cxx2b.C (__cpp_range_based_for): Check for
            202212L rather than 201603L.
            * g++.dg/cpp26/feat-cxx26.C (__cpp_range_based_for): Likewise.
            * g++.dg/warn/Wdangling-reference4.C: Don't expect warning for
C++23
            or newer.  Use dg-additional-options rather than dg-options.
    libgomp/
            * testsuite/libgomp.c++/range-for-1.C: New test.
            * testsuite/libgomp.c++/range-for-2.C: New test.
            * testsuite/libgomp.c++/range-for-3.C: New test.
            * testsuite/libgomp.c++/range-for-4.C: New test.
            * testsuite/libgomp.c++/range-for-5.C: New test.
  • [Bug c++/107637] [C++23] P2718R... cvs-commit at gcc dot gnu.org via Gcc-bugs

Reply via email to