aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2023-11-21 18:22:53 -0500
committerJason Merrill <jason@redhat.com>2023-11-21 22:37:44 -0500
commitf4c53580f3aba1343ca77756078722bb07f8118a (patch)
tree246aa8f10796b4f6349ac6c31063c9c9769b0a15
parent56ff988e6be3fdba70cad86d73ec0038bc3b6b5a (diff)
downloadgcc-f4c53580f3aba1343ca77756078722bb07f8118a.zip
gcc-f4c53580f3aba1343ca77756078722bb07f8118a.tar.gz
gcc-f4c53580f3aba1343ca77756078722bb07f8118a.tar.bz2
c++: start_preparsed_function tweak
In review of the deducing 'this' patch, it came up that the logic in start_preparsed_function around the ctype variable was convoluted, being set for non-static member functions and friends, but not for static member functions. Let's set it for any member function, and not rely on it to decide whether to set up 'this'. gcc/cp/ChangeLog: * decl.cc (start_preparsed_function): Clarify ctype logic.
-rw-r--r--gcc/cp/decl.cc12
1 files changed, 5 insertions, 7 deletions
diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
index e6f75d7..e7701af 100644
--- a/gcc/cp/decl.cc
+++ b/gcc/cp/decl.cc
@@ -17392,8 +17392,8 @@ start_preparsed_function (tree decl1, tree attrs, int flags)
gcc_assert (TREE_CHAIN (void_list_node) == NULL_TREE);
tree fntype = TREE_TYPE (decl1);
- if (TREE_CODE (fntype) == METHOD_TYPE)
- ctype = TYPE_METHOD_BASETYPE (fntype);
+ if (DECL_CLASS_SCOPE_P (decl1))
+ ctype = DECL_CONTEXT (decl1);
else
{
ctype = DECL_FRIEND_CONTEXT (decl1);
@@ -17424,15 +17424,13 @@ start_preparsed_function (tree decl1, tree attrs, int flags)
/* Sometimes we don't notice that a function is a static member, and
build a METHOD_TYPE for it. Fix that up now. */
- gcc_assert (!(ctype != NULL_TREE && DECL_STATIC_FUNCTION_P (decl1)
+ gcc_assert (!(DECL_STATIC_FUNCTION_P (decl1)
&& TREE_CODE (TREE_TYPE (decl1)) == METHOD_TYPE));
/* Set up current_class_type, and enter the scope of the class, if
appropriate. */
if (ctype)
push_nested_class (ctype);
- else if (DECL_STATIC_FUNCTION_P (decl1))
- push_nested_class (DECL_CONTEXT (decl1));
/* Now that we have entered the scope of the class, we must restore
the bindings for any template parameters surrounding DECL1, if it
@@ -17469,7 +17467,7 @@ start_preparsed_function (tree decl1, tree attrs, int flags)
tree newdecl1 = push_template_decl (decl1, doing_friend);
if (newdecl1 == error_mark_node)
{
- if (ctype || DECL_STATIC_FUNCTION_P (decl1))
+ if (ctype)
pop_nested_class ();
return false;
}
@@ -17621,7 +17619,7 @@ start_preparsed_function (tree decl1, tree attrs, int flags)
/* Start the statement-tree, start the tree now. */
DECL_SAVED_TREE (decl1) = push_stmt_list ();
- if (ctype && !doing_friend && !DECL_STATIC_FUNCTION_P (decl1))
+ if (DECL_NONSTATIC_MEMBER_FUNCTION_P (decl1))
{
/* We know that this was set up by `grokclassfn'. We do not
wait until `store_parm_decls', since evil parse errors may