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

--- Comment #3 from CVS 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:86caab6c5d1e26e1c54c3dceacc873d6e27bfc09

commit r13-5266-g86caab6c5d1e26e1c54c3dceacc873d6e27bfc09
Author: Jakub Jelinek <ja...@redhat.com>
Date:   Thu Jan 19 23:31:15 2023 +0100

    c++: Fix up handling of non-dependent subscript with static operator[]
[PR108437]

    As the following testcases shows, when adding static operator[]
    support I've missed that the 2 build_min_non_dep_op_overload functions
    need to be adjusted.  The first one we only use for the single index
    case, but as cp_tree_code_length (ARRAY_REF) is 2, we were running
    into an assertion there which compared nargs and expected_nargs.
    For ARRAY_REF, the operator[] is either a non-static member or newly
    static member, never out of class and for the static member case
    if user uses single index the operator[] needs to have a single
    argument as well, but the function is called with 2 - the object
    it is invoked on and the index.  We need to evaluate side-effects
    of the object and use just a single argument in the call - the index.
    The other build_min_non_dep_op_overload overload has been added
    solely for ARRAY_REF - CALL_EXPR is the other operator that accepts
    variable number of operands but that one goes through different
    routines.  There we asserted it is a METHOD_TYPE, so again
    we shouldn't assert that but handle the case when it is not one
    by making sure object's side-effects are evaluated if needed and
    passing all the index arguments to the static operator[].

    2023-01-19  Jakub Jelinek  <ja...@redhat.com>

            PR c++/108437
            * cp-tree.h (keep_unused_object_arg): Declare.
            * call.cc (keep_unused_object_arg): No longer static.
            * tree.cc (build_min_non_dep_op_overload): Handle ARRAY_REF
            with overload being static member function.

            * g++.dg/cpp23/subscript12.C: New test.
            * g++.dg/cpp23/subscript13.C: New test.

Reply via email to