From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id C84D83858D35 for ; Wed, 26 Jul 2023 16:31:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C84D83858D35 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1690389112; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=JfSBaLFlmGTvboKXx3CszPmq3Qntmd109g7Gu1be/co=; b=K6CBo4pLek6TfduY1O5aR+3X1R/m1p/FqtfEeK00qrEM0YzQswo4D6Jdczw4RVbazIiXpD nzKThcTJDRBKvx88IDjkK4gIr8RjnUit6orBp+Yzqu9x6z/BOLuhlaA8uWMIih0MF/7xPR EpV11k8xXAi/GwiVKK1wQA5rMsxFpNA= Received: from mail-ot1-f69.google.com (mail-ot1-f69.google.com [209.85.210.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-505-UzHkpVGzNg-6GTE0s1MI_g-1; Wed, 26 Jul 2023 12:31:51 -0400 X-MC-Unique: UzHkpVGzNg-6GTE0s1MI_g-1 Received: by mail-ot1-f69.google.com with SMTP id 46e09a7af769-6bb1a153d8fso9243339a34.1 for ; Wed, 26 Jul 2023 09:31:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690389110; x=1690993910; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=JfSBaLFlmGTvboKXx3CszPmq3Qntmd109g7Gu1be/co=; b=Ps5M1Ycn6Qs8FHfD8yzU7ztTmxW1RDE9OLzWJe71W9OKNypUdZlfkMCqU4Gaqpel6h wEqeNnQ9q4c/zLwTWkOsctTyftSiWGtUCLk76m4KF3bZY1OdKRUA2XIJZ1QOGdWwbj7r vA6DzgVDcPw1vlxXRhy1sDjwxONgnk0re/SMGa9rR2znTFu+IZA+Rs5meMHC1HhD0XQB 8JXRGOJDX4cd+qC7eKyYzIiEWqW4JhUv3MvIHELxd9cjL1xKBSdxU/xdtTNuvaNqLmEZ 9QVMBrgrP8UyHch0nnHz5ucst+WukUrMlI6HsEKI8n0z1v/2XyxNo9lD1+oNicIM0QwN FiMw== X-Gm-Message-State: ABy/qLaZbnxbSewNzdF8gyrzBXuAPR2s6tqmGp3wagq1TgyyIFHYrfef nL4LZnXu1tZyRvcDZyooLiRA7hgzBsGGoB0k9zi9pOyRTutgL9pyV44YLCU5vGUfPeyLkMDDEk+ WuamZBauSrYlU0l4zww934KI5YbmNM/81OGx2LWsFXX174s9UmYipwk1rqSc9JhEqYcUJg+sjBQ == X-Received: by 2002:a05:6830:1b66:b0:6b8:958f:36ea with SMTP id d6-20020a0568301b6600b006b8958f36eamr2635866ote.0.1690389109985; Wed, 26 Jul 2023 09:31:49 -0700 (PDT) X-Google-Smtp-Source: APBJJlFW1B9LxGH3JlLNg7EW0mWve4U9bFgR7WYDyGgI3rPH3e3VCann4/DpTtcv6yAfDmROVrbfdQ== X-Received: by 2002:a05:6830:1b66:b0:6b8:958f:36ea with SMTP id d6-20020a0568301b6600b006b8958f36eamr2635842ote.0.1690389109302; Wed, 26 Jul 2023 09:31:49 -0700 (PDT) Received: from jason.com (130-44-146-16.s12558.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.146.16]) by smtp.gmail.com with ESMTPSA id p4-20020a05620a15e400b0076768dfe53esm4477472qkm.105.2023.07.26.09.31.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jul 2023 09:31:48 -0700 (PDT) From: Jason Merrill To: gcc-patches@gcc.gnu.org Subject: [pushed] c++: member vs global template [PR106310] Date: Wed, 26 Jul 2023 12:31:45 -0400 Message-Id: <20230726163145.2905222-1-jason@redhat.com> X-Mailer: git-send-email 2.39.3 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Tested x86_64-pc-linux-gnu, applying to trunk. -- 8< -- For backward compatibility we still want to allow patterns like this->A::foo, but the template keyword in a qualified name is specifically to specify that a dependent name is a template, so don't look in the enclosing scope at all. Also fix handling of dependent bases: if member lookup in the current instantiation fails and we have dependent bases, the lookup is dependent. We were already handling that for the case where lookup in the enclosing scope also fails, but we also want it to affect that lookup itself. PR c++/106310 gcc/cp/ChangeLog: * parser.cc (cp_parser_template_name): Skip non-member lookup after the template keyword. (cp_parser_lookup_name): Pass down template_keyword_p. gcc/testsuite/ChangeLog: * g++.dg/template/template-keyword4.C: New test. --- gcc/cp/parser.cc | 20 ++++++++++++------- .../g++.dg/template/template-keyword4.C | 18 +++++++++++++++++ 2 files changed, 31 insertions(+), 7 deletions(-) create mode 100644 gcc/testsuite/g++.dg/template/template-keyword4.C diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index 5e2b5cba57e..571997733be 100644 --- a/gcc/cp/parser.cc +++ b/gcc/cp/parser.cc @@ -2748,7 +2748,7 @@ static tree cp_parser_objc_struct_declaration /* Utility Routines */ static cp_expr cp_parser_lookup_name - (cp_parser *, tree, enum tag_types, bool, bool, bool, tree *, location_t); + (cp_parser *, tree, enum tag_types, int, bool, bool, tree *, location_t); static tree cp_parser_lookup_name_simple (cp_parser *, tree, location_t); static tree cp_parser_maybe_treat_template_as_class @@ -18771,7 +18771,7 @@ cp_parser_template_name (cp_parser* parser, /* Look up the name. */ decl = cp_parser_lookup_name (parser, identifier, tag_type, - /*is_template=*/true, + /*is_template=*/1 + template_keyword_p, /*is_namespace=*/false, check_dependency_p, /*ambiguous_decls=*/NULL, @@ -31173,7 +31173,7 @@ prefer_type_arg (tag_types tag_type) refer to types are ignored. If IS_TEMPLATE is TRUE, bindings that do not refer to templates are - ignored. + ignored. If IS_TEMPLATE IS 2, the 'template' keyword was specified. If IS_NAMESPACE is TRUE, bindings that do not refer to namespaces are ignored. @@ -31188,7 +31188,7 @@ prefer_type_arg (tag_types tag_type) static cp_expr cp_parser_lookup_name (cp_parser *parser, tree name, enum tag_types tag_type, - bool is_template, + int is_template, bool is_namespace, bool check_dependency, tree *ambiguous_decls, @@ -31372,7 +31372,14 @@ cp_parser_lookup_name (cp_parser *parser, tree name, else decl = NULL_TREE; - if (!decl) + /* If we didn't find a member and have dependent bases, the member lookup + is now dependent. */ + if (!dep && !decl && any_dependent_bases_p (object_type)) + dep = true; + + if (dep && is_template == 2) + /* The template keyword specifies a dependent template. */; + else if (!decl) /* Look it up in the enclosing context. DR 141: When looking for a template-name after -> or ., only consider class templates. */ decl = lookup_name (name, is_namespace ? LOOK_want::NAMESPACE @@ -31400,8 +31407,7 @@ cp_parser_lookup_name (cp_parser *parser, tree name, /* If we know we're looking for a type (e.g. A in p->A::x), mock up a typename. */ - if (!decl && object_type && tag_type != none_type - && dependentish_scope_p (object_type)) + if (!decl && dep && tag_type != none_type) { tree type = build_typename_type (object_type, name, name, typename_type); diff --git a/gcc/testsuite/g++.dg/template/template-keyword4.C b/gcc/testsuite/g++.dg/template/template-keyword4.C new file mode 100644 index 00000000000..a7ab9bb8ca6 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/template-keyword4.C @@ -0,0 +1,18 @@ +// PR c++/106310 + +template +struct set{}; + +template< typename T > +struct Base +{ + template< int > int set(T const &); +}; + +template< typename T > +struct Derived : Base< T > +{ + void f(T const &arg) { + this->template set< 0 >(arg); + } +}; base-commit: 21da32d995c8b574c929ec420cd3b0fcfe6fa4fe -- 2.39.3