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 r11-9991] c++: template-id with current inst qualifier [PR102300] Date: Fri, 13 May 2022 12:08:50 +0000 (GMT) [thread overview] Message-ID: <20220513120850.976513856DDC@sourceware.org> (raw) https://gcc.gnu.org/g:8d2f59c8e26960df81e054c7afd2ef63171bae05 commit r11-9991-g8d2f59c8e26960df81e054c7afd2ef63171bae05 Author: Jason Merrill <jason@redhat.com> Date: Tue Jan 18 18:28:22 2022 -0500 c++: template-id with current inst qualifier [PR102300] The patch for PR41723 properly changed one place to look into the current instantiation; now we need to fix this place as well. The fix for GCC 12 depends on r12-3643, so this commit also incorporates some of those changes. PR c++/102300 gcc/cp/ChangeLog: * parser.c (cp_parser_template_name): Use dependent_scope_p. gcc/testsuite/ChangeLog: * g++.dg/parse/no-typename1.C: Remove expected error. * g++.dg/template/nested7.C: New test. Diff: --- gcc/cp/parser.c | 40 +++++++++++++++++++++---------- gcc/testsuite/g++.dg/parse/no-typename1.C | 2 +- gcc/testsuite/g++.dg/template/nested7.C | 12 ++++++++++ 3 files changed, 40 insertions(+), 14 deletions(-) diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 365d5989773..b53cc6d360e 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -17728,7 +17728,7 @@ cp_parser_template_name (cp_parser* parser, : parser->context->object_type); if (scope && TYPE_P (scope) && (!CLASS_TYPE_P (scope) - || (check_dependency_p && dependent_type_p (scope)))) + || (check_dependency_p && dependent_scope_p (scope)))) { /* We're optimizing away the call to cp_parser_lookup_name, but we still need to do this. */ @@ -17739,8 +17739,8 @@ cp_parser_template_name (cp_parser* parser, } /* cp_parser_lookup_name clears OBJECT_TYPE. */ - const bool scoped_p = ((parser->scope ? parser->scope - : parser->context->object_type) != NULL_TREE); + tree scope = (parser->scope ? parser->scope + : parser->context->object_type); /* Look up the name. */ decl = cp_parser_lookup_name (parser, identifier, @@ -17753,6 +17753,19 @@ cp_parser_template_name (cp_parser* parser, decl = strip_using_decl (decl); + /* 13.3 [temp.names] A < is interpreted as the delimiter of a + template-argument-list if it follows a name that is not a + conversion-function-id and + - that follows the keyword template or a ~ after a nested-name-specifier or + in a class member access expression, or + - for which name lookup finds the injected-class-name of a class template + or finds any declaration of a template, or + - that is an unqualified name for which name lookup either finds one or + more functions or finds nothing, or + - that is a terminal name in a using-declarator (9.9), in a declarator-id + (9.3.4), or in a type-only context other than a nested-name-specifier + (13.8). */ + /* If DECL is a template, then the name was a template-name. */ if (TREE_CODE (decl) == TEMPLATE_DECL) { @@ -17772,11 +17785,7 @@ cp_parser_template_name (cp_parser* parser, } else { - /* The standard does not explicitly indicate whether a name that - names a set of overloaded declarations, some of which are - templates, is a template-name. However, such a name should - be a template-name; otherwise, there is no way to form a - template-id for the overloaded templates. */ + /* Look through an overload set for any templates. */ bool found = false; for (lkp_iterator iter (MAYBE_BASELINK_FUNCTIONS (decl)); @@ -17784,16 +17793,14 @@ cp_parser_template_name (cp_parser* parser, if (TREE_CODE (*iter) == TEMPLATE_DECL) found = true; + /* "an unqualified name for which name lookup either finds one or more + functions or finds nothing". */ if (!found && (cxx_dialect > cxx17) - && !scoped_p + && !scope && cp_lexer_next_token_is (parser->lexer, CPP_LESS) && tag_type == none_type) { - /* [temp.names] says "A name is also considered to refer to a template - if it is an unqualified-id followed by a < and name lookup finds - either one or more functions or finds nothing." */ - /* The "more functions" case. Just use the OVERLOAD as normally. We don't use is_overloaded_fn here to avoid considering BASELINKs. */ @@ -17806,6 +17813,13 @@ cp_parser_template_name (cp_parser* parser, return identifier; } + /* "that follows the keyword template"..."in a type-only context" */ + if (!found && scope + && (template_keyword_p || tag_type != none_type) + && TYPE_P (scope) && dependent_type_p (scope) + && cp_parser_nth_token_starts_template_argument_list_p (parser, 1)) + return identifier; + if (!found) { /* The name does not name a template. */ diff --git a/gcc/testsuite/g++.dg/parse/no-typename1.C b/gcc/testsuite/g++.dg/parse/no-typename1.C index 711c621e26a..f40ea0ec13c 100644 --- a/gcc/testsuite/g++.dg/parse/no-typename1.C +++ b/gcc/testsuite/g++.dg/parse/no-typename1.C @@ -6,6 +6,6 @@ template <typename T> struct A { template <typename U> struct B { - A<T>::template B<U> foo(); // { dg-error "" "" { target c++17_down } } + A<T>::template B<U> foo(); }; }; diff --git a/gcc/testsuite/g++.dg/template/nested7.C b/gcc/testsuite/g++.dg/template/nested7.C new file mode 100644 index 00000000000..3a5930c0f31 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/nested7.C @@ -0,0 +1,12 @@ +// PR c++/102300 + +template<typename T> +struct holder +{ + template<typename F> struct fn {}; + + struct t1 : fn<T> {}; // pass + struct t2 : holder<T >::fn<T> {}; // fail + struct t3 : holder<T >::template fn<T> {}; // fail + struct t4 : holder<T*>::template fn<T> {}; // pass +};
reply other threads:[~2022-05-13 12:08 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=20220513120850.976513856DDC@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: linkBe 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).