From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2122) id 976513856DDC; Fri, 13 May 2022 12:08:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 976513856DDC MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jason Merrill To: gcc-cvs@gcc.gnu.org Subject: [gcc r11-9991] c++: template-id with current inst qualifier [PR102300] X-Act-Checkin: gcc X-Git-Author: Jason Merrill X-Git-Refname: refs/heads/releases/gcc-11 X-Git-Oldrev: 9151de4b43bfb48202ee815924738197ac6e76a3 X-Git-Newrev: 8d2f59c8e26960df81e054c7afd2ef63171bae05 Message-Id: <20220513120850.976513856DDC@sourceware.org> Date: Fri, 13 May 2022 12:08:50 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 13 May 2022 12:08:50 -0000 https://gcc.gnu.org/g:8d2f59c8e26960df81e054c7afd2ef63171bae05 commit r11-9991-g8d2f59c8e26960df81e054c7afd2ef63171bae05 Author: Jason Merrill 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 struct A { template struct B { - A::template B foo(); // { dg-error "" "" { target c++17_down } } + A::template B 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 +struct holder +{ + template struct fn {}; + + struct t1 : fn {}; // pass + struct t2 : holder::fn {}; // fail + struct t3 : holder::template fn {}; // fail + struct t4 : holder::template fn {}; // pass +};