[Bug c++/124646] [reflection] regression related to define_static_array and range for loops since r16-8235

cvs-commit at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Thu Apr 2 14:01:50 GMT 2026


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

--- Comment #2 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Marek Polacek <mpolacek@gcc.gnu.org>:

https://gcc.gnu.org/g:2fb21bacf7b4b78ccba27ec5e01396c46c58c019

commit r16-8430-g2fb21bacf7b4b78ccba27ec5e01396c46c58c019
Author: Marek Polacek <polacek@redhat.com>
Date:   Wed Apr 1 16:06:58 2026 -0400

    c++/reflection: fix wrong-code with members_of [PR124646, PR124645]

    My r16-8235 change should have set DECL_EXTERNAL only in the
    !at_function_scope_p block, before rest_of_decl_compilation.  Setting
    DECL_EXTERNAL on the temporary var for both at_function_scope_p and
    !at_function_scope_p cases causes issues: in members_of11.C, we wrongly
    initialize 'mem' in the loop to A::a both times, insted of A::a and B::b.
    Similarly in members_of12.C we wrongly initialize member when inspecting
    ns2.

    I couldn't track down where *exactly* things go wrong, but the point
    of r16-8235 was to set DECL_EXTERNAL only for the rest_of_decl_compilation
    call.

            PR c++/124646
            PR c++/124645

    gcc/cp/ChangeLog:

            * call.cc (set_up_extended_ref_temp): Move setting DECL_EXTERNAL
            to the !at_function_scope_p block.

    gcc/testsuite/ChangeLog:

            * g++.dg/reflect/members_of11.C: New test.
            * g++.dg/reflect/members_of12.C: New test.

    Reviewed-by: Jason Merrill <jason@redhat.com>


More information about the Gcc-bugs mailing list