c++: P0847R7 (deducing this) - initial functionality. [PR102609]
commitfbc980d85149409ce62c22f48d3693113803929e
authorwaffl3x <waffl3x@protonmail.com>
Sun, 7 Jan 2024 00:01:48 +0000 (7 00:01 +0000)
committerJason Merrill <jason@redhat.com>
Tue, 9 Jan 2024 20:59:04 +0000 (9 15:59 -0500)
tree1337c2b1223d0be16a0ab3567643372211ceef04
parentf9fbf93dc82525a0f54a2293b7ec92d65776bf19
c++: P0847R7 (deducing this) - initial functionality. [PR102609]

This implements the initial functionality for P0847R7.  CWG2789 is
implemented, but instead of "same type" for the object parameters we take
correspondence into account instead.  Without this alteration, the behavior
here would be slightly different than the behavior with constrained member
function templates, which I believe would be undesirable.

There are a few outstanding issues related to xobj member functions
overloading iobj member functions that are introduced by using declarations.
Unfortunately, fixing this will be a little more involved and will have to
be pushed back until later.

Most diagnostics have been split out into another patch to improve its
clarity and allow all the strictly functional changes to be more
distinct. Explicit object lambdas and CWG2586 are addressed in a follow up
patch.

PR c++/102609

gcc/cp/ChangeLog:

PR c++/102609
C++23 P0847R7 (deducing this) - initial functionality.
* class.cc (xobj_iobj_parameters_correspond): New function, checks
for corresponding object parameters between xobj and iobj member
functions.
(add_method): Handle object parameters of xobj member functions, use
xobj_iobj_parameters_correspond.
* call.cc (build_over_call): Refactor, handle xobj member functions.
(cand_parms_match): Handle object parameters of xobj and iobj member
functions, use xobj_iobj_parameters_correspond.
* cp-tree.h (enum cp_decl_spec): Add ds_this, add comments.
* decl.cc (grokfndecl): Add xobj_func_p parameter.  For xobj member
functions, Set xobj_flag, don't set static_function flag.
(grokdeclarator): Handle xobj member functions, tell grokfndecl.
(grok_op_properties): Don't error for xobj operators.
* parser.cc (cp_parser_decl_specifier_seq): Handle this specifier.
(cp_parser_parameter_declaration): Set default argument to
"this_identifier" for xobj parameters.
(set_and_check_decl_spec_loc): Add "this", add comments.
* tree.cc (build_min_non_dep_op_overload): Handle xobj operators.
* typeck.cc (cp_build_addr_expr_1): Handle address-of xobj member
functions.

gcc/testsuite/ChangeLog:

PR c++/102609
C++23 P0847R7 (deducing this) - initial functionality.
* g++.dg/cpp23/explicit-obj-basic1.C: New test.
* g++.dg/cpp23/explicit-obj-basic2.C: New test.
* g++.dg/cpp23/explicit-obj-basic3.C: New test.
* g++.dg/cpp23/explicit-obj-basic4.C: New test.
* g++.dg/cpp23/explicit-obj-basic5.C: New test.
* g++.dg/cpp23/explicit-obj-by-value1.C: New test.
* g++.dg/cpp23/explicit-obj-by-value2.C: New test.
* g++.dg/cpp23/explicit-obj-by-value3.C: New test.
* g++.dg/cpp23/explicit-obj-by-value4.C: New test.
* g++.dg/cpp23/explicit-obj-constraints.C: New test.
* g++.dg/cpp23/explicit-obj-constraints2.C: New test.
* g++.dg/cpp23/explicit-obj-ops-mem-arrow.C: New test.
* g++.dg/cpp23/explicit-obj-ops-mem-assignment.C: New test.
* g++.dg/cpp23/explicit-obj-ops-mem-call.C: New test.
* g++.dg/cpp23/explicit-obj-ops-mem-subscript.C: New test.
* g++.dg/cpp23/explicit-obj-ops-non-mem-dep.C: New test.
* g++.dg/cpp23/explicit-obj-ops-non-mem-non-dep.C: New test.
* g++.dg/cpp23/explicit-obj-ops-non-mem.h: New test.
* g++.dg/cpp23/explicit-obj-ops-requires-mem.C: New test.
* g++.dg/cpp23/explicit-obj-ops-requires-non-mem.C: New test.
* g++.dg/cpp23/explicit-obj-redecl.C: New test.
* g++.dg/cpp23/explicit-obj-redecl2.C: New test.
* g++.dg/cpp23/explicit-obj-redecl3.C: New test.
* g++.dg/cpp23/explicit-obj-redecl4.C: New test.

Signed-off-by: Waffl3x <waffl3x@protonmail.com>
31 files changed:
gcc/cp/call.cc
gcc/cp/class.cc
gcc/cp/cp-tree.h
gcc/cp/decl.cc
gcc/cp/parser.cc
gcc/cp/tree.cc
gcc/cp/typeck.cc
gcc/testsuite/g++.dg/cpp23/explicit-obj-basic1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp23/explicit-obj-basic2.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp23/explicit-obj-basic3.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp23/explicit-obj-basic4.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp23/explicit-obj-basic5.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp23/explicit-obj-by-value1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp23/explicit-obj-by-value2.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp23/explicit-obj-by-value3.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp23/explicit-obj-by-value4.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp23/explicit-obj-constraints.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp23/explicit-obj-constraints2.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp23/explicit-obj-ops-mem-arrow.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp23/explicit-obj-ops-mem-assignment.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp23/explicit-obj-ops-mem-call.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp23/explicit-obj-ops-mem-subscript.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp23/explicit-obj-ops-non-mem-dep.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp23/explicit-obj-ops-non-mem-non-dep.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp23/explicit-obj-ops-non-mem.h [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp23/explicit-obj-ops-requires-mem.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp23/explicit-obj-ops-requires-non-mem.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp23/explicit-obj-redecl.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp23/explicit-obj-redecl2.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp23/explicit-obj-redecl3.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp23/explicit-obj-redecl4.C [new file with mode: 0644]