diff options
author | Jakub Jelinek <jakub@redhat.com> | 2022-11-15 08:00:21 +0100 |
---|---|---|
committer | Jakub Jelinek <jakub@redhat.com> | 2022-11-15 08:00:21 +0100 |
commit | 6492cec069bccf817ac5e984fb3eca407056a566 (patch) | |
tree | fefcbffd560982373a49d8a1a6b0b9c119bd20c6 /gcc/cp/call.cc | |
parent | e0f4fcf9dfb8794a11d4ee63899b820aa9257f50 (diff) | |
download | gcc-6492cec069bccf817ac5e984fb3eca407056a566.zip gcc-6492cec069bccf817ac5e984fb3eca407056a566.tar.gz gcc-6492cec069bccf817ac5e984fb3eca407056a566.tar.bz2 |
c++: Implement C++23 P2589R1 - - static operator[]
Here is a patch that implements the static operator[] paper.
One thing that doesn't work properly is the same problem as I've filed
yesterday for static operator() - PR107624 - that side-effects of
the postfix-expression on which the call or subscript operator are
applied are thrown away, I assume we have to add them into COMPOUND_EXPR
somewhere after we find out that the we've chosen a static member function
operator.
2022-11-15 Jakub Jelinek <jakub@redhat.com>
gcc/c-family/
* c-cppbuiltin.cc (c_cpp_builtins): Bump C++23
__cpp_multidimensional_subscript macro value to 202211L.
gcc/cp/
* decl.cc (grok_op_properties): Implement C++23 P2589R1
- static operator[]. Handle operator[] similarly to operator()
- allow static member functions, but pedwarn on it for C++20 and
older. Unlike operator(), perform rest of checks on it though for
C++20.
* call.cc (add_operator_candidates): For operator[] with class
typed first parameter, pass that parameter as first_arg and
an adjusted arglist without that parameter.
gcc/testsuite/
* g++.dg/cpp23/subscript9.C: New test.
* g++.dg/cpp23/feat-cxx2b.C: Expect a newer
__cpp_multidimensional_subscript value.
* g++.old-deja/g++.bugs/900210_10.C: Don't expect an error
for C++23 or later.
Diffstat (limited to 'gcc/cp/call.cc')
-rw-r--r-- | gcc/cp/call.cc | 36 |
1 files changed, 30 insertions, 6 deletions
diff --git a/gcc/cp/call.cc b/gcc/cp/call.cc index ef618d5..dbb01ec 100644 --- a/gcc/cp/call.cc +++ b/gcc/cp/call.cc @@ -6589,12 +6589,36 @@ add_operator_candidates (z_candidate **candidates, if (fns == error_mark_node) return error_mark_node; if (fns) - add_candidates (BASELINK_FUNCTIONS (fns), - NULL_TREE, arglist, NULL_TREE, - NULL_TREE, false, - BASELINK_BINFO (fns), - BASELINK_ACCESS_BINFO (fns), - flags, candidates, complain); + { + if (code == ARRAY_REF) + { + vec<tree,va_gc> *restlist = make_tree_vector (); + for (unsigned i = 1; i < nargs; ++i) + vec_safe_push (restlist, (*arglist)[i]); + z_candidate *save_cand = *candidates; + add_candidates (BASELINK_FUNCTIONS (fns), + (*arglist)[0], restlist, NULL_TREE, + NULL_TREE, false, + BASELINK_BINFO (fns), + BASELINK_ACCESS_BINFO (fns), + flags, candidates, complain); + /* Release the vec if we didn't add a candidate that uses it. */ + for (z_candidate *c = *candidates; c != save_cand; c = c->next) + if (c->args == restlist) + { + restlist = NULL; + break; + } + release_tree_vector (restlist); + } + else + add_candidates (BASELINK_FUNCTIONS (fns), + NULL_TREE, arglist, NULL_TREE, + NULL_TREE, false, + BASELINK_BINFO (fns), + BASELINK_ACCESS_BINFO (fns), + flags, candidates, complain); + } } /* Per [over.match.oper]3.2, if no operand has a class type, then only non-member functions that have type T1 or reference to |