aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2024-01-08 17:09:54 -0500
committerJason Merrill <jason@redhat.com>2024-01-09 16:09:23 -0500
commitae3003b20d3e3ab6e50a6d4f2173e10ad9025135 (patch)
treed7f0e6b620e098c4e712ba8baaedf92e18f974c2 /gcc/cp
parent5a6d3b1737843aa64d83ffc5d639fa0afa5d8318 (diff)
downloadgcc-ae3003b20d3e3ab6e50a6d4f2173e10ad9025135.zip
gcc-ae3003b20d3e3ab6e50a6d4f2173e10ad9025135.tar.gz
gcc-ae3003b20d3e3ab6e50a6d4f2173e10ad9025135.tar.bz2
c++: adjust accessor fixits for explicit object parm
In a couple of places in the xobj patch I noticed that is_this_parameter probably wanted to change to is_object_parameter; this implements that and does the additional adjustments needed to make the accessor fixits handle xobj parms. gcc/cp/ChangeLog: * semantics.cc (is_object_parameter): New. * cp-tree.h (is_object_parameter): Declare. * call.cc (maybe_warn_class_memaccess): Use it. * search.cc (field_access_p): Use it. (class_of_object_parm): New. (field_accessor_p): Adjust for explicit object parms. gcc/testsuite/ChangeLog: * g++.dg/torture/accessor-fixits-9-xobj.C: New test.
Diffstat (limited to 'gcc/cp')
-rw-r--r--gcc/cp/call.cc3
-rw-r--r--gcc/cp/cp-tree.h1
-rw-r--r--gcc/cp/search.cc19
-rw-r--r--gcc/cp/semantics.cc14
4 files changed, 30 insertions, 7 deletions
diff --git a/gcc/cp/call.cc b/gcc/cp/call.cc
index 7d3d676..191664e 100644
--- a/gcc/cp/call.cc
+++ b/gcc/cp/call.cc
@@ -10815,8 +10815,7 @@ maybe_warn_class_memaccess (location_t loc, tree fndecl,
be more permissive. */
if (current_function_decl
&& DECL_OBJECT_MEMBER_FUNCTION_P (current_function_decl)
- /* ??? is_object_parameter? */
- && is_this_parameter (tree_strip_nop_conversions (dest)))
+ && is_object_parameter (tree_strip_nop_conversions (dest)))
{
tree ctx = DECL_CONTEXT (current_function_decl);
bool special = same_type_ignoring_top_level_qualifiers_p (ctx, desttype);
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index dbc7177..f3f265a 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -7784,6 +7784,7 @@ extern void finish_handler_parms (tree, tree);
extern void finish_handler (tree);
extern void finish_cleanup (tree, tree);
extern bool is_this_parameter (tree);
+extern bool is_object_parameter (tree);
enum {
BCS_NORMAL = 0,
diff --git a/gcc/cp/search.cc b/gcc/cp/search.cc
index dc76714..2b4ed5d 100644
--- a/gcc/cp/search.cc
+++ b/gcc/cp/search.cc
@@ -1737,8 +1737,7 @@ field_access_p (tree component_ref, tree field_decl, tree field_type)
return false;
tree ptr = STRIP_NOPS (TREE_OPERAND (indirect_ref, 0));
- /* ??? is_object_parameter? */
- if (!is_this_parameter (ptr))
+ if (!is_object_parameter (ptr))
return false;
/* Must access the correct field. */
@@ -1818,6 +1817,17 @@ reference_accessor_p (tree init_expr, tree field_decl, tree field_type,
return true;
}
+/* Return the class of the `this' or explicit object parameter of FN. */
+
+static tree
+class_of_object_parm (const_tree fn)
+{
+ tree fntype = TREE_TYPE (fn);
+ if (DECL_XOBJ_MEMBER_FUNCTION_P (fn))
+ return non_reference (TREE_VALUE (TYPE_ARG_TYPES (fntype)));
+ return class_of_this_parm (fntype);
+}
+
/* Return true if FN is an accessor method for FIELD_DECL.
i.e. a method of the form { return FIELD; }, with no
conversions.
@@ -1835,15 +1845,14 @@ field_accessor_p (tree fn, tree field_decl, bool const_p)
if (TREE_CODE (field_decl) != FIELD_DECL)
return false;
- tree fntype = TREE_TYPE (fn);
- if (TREE_CODE (fntype) != METHOD_TYPE)
+ if (!DECL_OBJECT_MEMBER_FUNCTION_P (fn))
return false;
/* If the field is accessed via a const "this" argument, verify
that the "this" parameter is const. */
if (const_p)
{
- tree this_class = class_of_this_parm (fntype);
+ tree this_class = class_of_object_parm (fn);
if (!TYPE_READONLY (this_class))
return false;
}
diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc
index 86e1adf..3299e27 100644
--- a/gcc/cp/semantics.cc
+++ b/gcc/cp/semantics.cc
@@ -12832,6 +12832,20 @@ is_this_parameter (tree t)
return true;
}
+/* As above, or a C++23 explicit object parameter. */
+
+bool
+is_object_parameter (tree t)
+{
+ if (is_this_parameter (t))
+ return true;
+ if (TREE_CODE (t) != PARM_DECL)
+ return false;
+ tree ctx = DECL_CONTEXT (t);
+ return (ctx && DECL_XOBJ_MEMBER_FUNCTION_P (ctx)
+ && t == DECL_ARGUMENTS (ctx));
+}
+
/* Insert the deduced return type for an auto function. */
void