aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/parser.c
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2021-09-10 16:36:21 -0400
committerJason Merrill <jason@redhat.com>2021-09-15 16:26:15 -0400
commit30e025393209e1936c394e716006cdaaa6d50161 (patch)
treeb1e8f9db52b12a3a11ee3a64fde5c02186e32633 /gcc/cp/parser.c
parente5d1af8a07ae9fcc40ea5c781c3ad46d20ea12a6 (diff)
downloadgcc-30e025393209e1936c394e716006cdaaa6d50161.zip
gcc-30e025393209e1936c394e716006cdaaa6d50161.tar.gz
gcc-30e025393209e1936c394e716006cdaaa6d50161.tar.bz2
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.
Diffstat (limited to 'gcc/cp/parser.c')
-rw-r--r--gcc/cp/parser.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 7a0b623..8d60f40 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