public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jason Merrill <jason@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r12-3557] c++: add parsing_function_declarator predicate
Date: Wed, 15 Sep 2021 20:26:28 +0000 (GMT)	[thread overview]
Message-ID: <20210915202628.949353857C74@sourceware.org> (raw)

https://gcc.gnu.org/g:30e025393209e1936c394e716006cdaaa6d50161

commit r12-3557-g30e025393209e1936c394e716006cdaaa6d50161
Author: Jason Merrill <jason@redhat.com>
Date:   Fri Sep 10 16:36:21 2021 -0400

    c++: add parsing_function_declarator predicate
    
    While looking at PR96184 I noticed that we were recognizing the situation of
    parsing a function declarator based on current_binding_level, and that we
    ought to make that a predicate function.  This patch is just refactoring,
    but I just suggested using it in a review of another patch.
    
    gcc/cp/ChangeLog:
    
            * cp-tree.h (parsing_function_declarator): Declare.
            * name-lookup.c (set_decl_context_in_fn): Use it.
            * parser.c (cp_parser_direct_declarator): Use it.
            (parsing_function_declarator): New.

Diff:
---
 gcc/cp/cp-tree.h     |  1 +
 gcc/cp/name-lookup.c |  7 ++-----
 gcc/cp/parser.c      | 13 ++++++++++++-
 3 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index 060d1a0a3db..e5f632afba4 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -7136,6 +7136,7 @@ extern void cp_convert_omp_range_for (tree &, vec<tree, va_gc> *, tree &,
 				      tree &, tree &, tree &, tree &, tree &);
 extern void cp_finish_omp_range_for (tree, tree);
 extern bool parsing_nsdmi (void);
+extern bool parsing_function_declarator ();
 extern bool parsing_default_capturing_generic_lambda_in_template (void);
 extern void inject_this_parameter (tree, cp_cv_quals);
 extern location_t defparse_location (tree);
diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c
index 8e9c61e1ee8..ddee8b390f9 100644
--- a/gcc/cp/name-lookup.c
+++ b/gcc/cp/name-lookup.c
@@ -3363,12 +3363,9 @@ set_decl_context_in_fn (tree ctx, tree decl)
 
   if (!DECL_CONTEXT (decl)
       /* When parsing the parameter list of a function declarator,
-	 don't set DECL_CONTEXT to an enclosing function.  When we
-	 push the PARM_DECLs in order to process the function body,
-	 current_binding_level->this_entity will be set.  */
+	 don't set DECL_CONTEXT to an enclosing function.  */
       && !(TREE_CODE (decl) == PARM_DECL
-	   && current_binding_level->kind == sk_function_parms
-	   && current_binding_level->this_entity == NULL))
+	   && parsing_function_declarator ()))
     DECL_CONTEXT (decl) = ctx;
 }
 
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 7a0b6234350..8d60f40706b 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -23107,7 +23107,7 @@ cp_parser_direct_declarator (cp_parser* parser,
 	      else if (!cp_parser_uncommitted_to_tentative_parse_p (parser))
 		/* Let compute_array_index_type diagnose this.  */;
 	      else if (!parser->in_function_body
-		       || current_binding_level->kind == sk_function_parms)
+		       || parsing_function_declarator ())
 		{
 		  /* Normally, the array bound must be an integral constant
 		     expression.  However, as an extension, we allow VLAs
@@ -23831,6 +23831,17 @@ parsing_nsdmi (void)
   return false;
 }
 
+/* True if we're parsing a function declarator.  */
+
+bool
+parsing_function_declarator ()
+{
+  /* this_entity is NULL for a function parameter scope while parsing the
+     declarator; it is set when parsing the body of the function.  */
+  return (current_binding_level->kind == sk_function_parms
+	  && !current_binding_level->this_entity);
+}
+
 /* Parse a late-specified return type, if any.  This is not a separate
    non-terminal, but part of a function declarator, which looks like


                 reply	other threads:[~2021-09-15 20:26 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210915202628.949353857C74@sourceware.org \
    --to=jason@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).