From patchwork Wed May 4 21:59:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 1626629 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=OniHk8HF; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KtrPX6bPgz9sCq for ; Thu, 5 May 2022 08:01:03 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9AEDB3857360 for ; Wed, 4 May 2022 22:01:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9AEDB3857360 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1651701660; bh=uaaDHKib+g8x4PriY8le2n+pllHc9ZIgJ3NlpM2Qfe8=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=OniHk8HF657gkP3MW2wSljBWIVI1n0rQNrqDQ4TPFu+NlcpfiG8wwaoYZOGrQIrPw +wm8aDgjnLTo4hgUJkine39RacDcpH6mlDId0lXWu84Sy+opO+SUHisiTN0O1OvW6+ jAg1ap9PAKA7KQ0Zmg6dibwvOkcAx07yg5Z8LBPo= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 5F9D63857363 for ; Wed, 4 May 2022 21:59:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 5F9D63857363 Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-423-YYbqmcX1PkOUFtXU7zEvEg-1; Wed, 04 May 2022 17:59:34 -0400 X-MC-Unique: YYbqmcX1PkOUFtXU7zEvEg-1 Received: by mail-qv1-f70.google.com with SMTP id a12-20020a056214062c00b0045a7b4a1a29so1842126qvx.10 for ; Wed, 04 May 2022 14:59:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=uaaDHKib+g8x4PriY8le2n+pllHc9ZIgJ3NlpM2Qfe8=; b=l8oNby/t/4d2R/yp7pjEw7q/SPedfghHVFZBNM/7igSjGlIygiJAa1VrPZOkcxrkIJ aukVcGCFqm+1BpFiOKgjurk4U+n0Vsk0hCcHI+eixi1JmZnFoTCepIODzVLXTqROKm7M 4aNLJX1Gjbo2YgH1QHnRQSqjO2txvj8W5Iuz8gNt6LZvV7kuNiUfsCzqTh2Ci00DYpCc 16uCa39IDTa78TX85rXj30n9pD6XRrx/dLj7olbL08rDNlY1ejQHJy0sbARZiD5JgGhe /xB+NJkwJDV0khUyTRPD1vr+F/kwisgUPJnc0GzoBObSgtXciopV2bqS4BVm1+VUPwBq 0zvw== X-Gm-Message-State: AOAM5335eCLAfNo1szz9i95mdP0t2xF4m6BuTQ8ZHRZNLt1M03bR9Lhg 6R8NX3LbYzJF/Xf01mEIl9Yq6wGS9dPOTFHpmOVlPPqrMF0LTVQqKaeQDvn//mDe71K1e3iig5R XD502TnYYzyJCc4LpSQf4PpLmaoATkNm01L3hkddVlYg9lYAemiRadpXmLSJ2Xy7TcA== X-Received: by 2002:ac8:3d49:0:b0:2eb:cbf8:4140 with SMTP id u9-20020ac83d49000000b002ebcbf84140mr21192274qtf.279.1651701573238; Wed, 04 May 2022 14:59:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJygbDmS9dgrfSFNp+W9wabfZwTql4BQZTdaLHf3EKQHp8UWOZnPbRkltQKx5oTy7MwYkUj6gQ== X-Received: by 2002:ac8:3d49:0:b0:2eb:cbf8:4140 with SMTP id u9-20020ac83d49000000b002ebcbf84140mr21192255qtf.279.1651701572796; Wed, 04 May 2022 14:59:32 -0700 (PDT) Received: from barrymore.redhat.com (130-44-159-43.s15913.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.159.43]) by smtp.gmail.com with ESMTPSA id v185-20020a372fc2000000b0069fc13ce252sm8311765qkh.131.2022.05.04.14.59.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 May 2022 14:59:32 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [pushed] c++: alias CTAD refactoring [PR104470] Date: Wed, 4 May 2022 17:59:29 -0400 Message-Id: <20220504215929.2688464-1-jason@redhat.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.4 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_LOW, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jason Merrill via Gcc-patches From: Jason Merrill Reply-To: Jason Merrill Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" In my previous PR104470 patch I added yet another place that needs to handle dependent member rewriting for deduction guides; this patches centralizes rewriting into maybe_dependent_member_ref. tsubst_baselink still has its own handling because that's simpler than teaching maybe_dependent_member_ref about BASELINKs. Tested x86_64-pc-linux-gnu, applying to trunk. PR c++/104470 gcc/cp/ChangeLog: * pt.cc (maybe_dependent_member_ref): Handle types. (tsubst, tsubst_copy): Use it. (tsubst_aggr_type, instantiate_alias_template): Don't handle tf_dguide here. --- gcc/cp/pt.cc | 104 ++++++++++++++++++++++++++------------------------- 1 file changed, 54 insertions(+), 50 deletions(-) base-commit: c8df7208864d863f58da55d42ff82663059930b1 diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index ac002907a41..d8d36f35692 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -220,6 +220,7 @@ static tree make_argument_pack (tree); static void register_parameter_specializations (tree, tree); static tree enclosing_instantiation_of (tree tctx); static void instantiate_body (tree pattern, tree args, tree d, bool nested); +static tree maybe_dependent_member_ref (tree, tree, tsubst_flags_t, tree); /* Make the current scope suitable for access checking when we are processing T. T can be FUNCTION_DECL for instantiated function @@ -13725,18 +13726,6 @@ tsubst_aggr_type (tree t, complain, in_decl); if (argvec == error_mark_node) r = error_mark_node; - else if (!entering_scope && (complain & tf_dguide) - && dependent_scope_p (context)) - { - /* See maybe_dependent_member_ref. */ - tree name = TYPE_IDENTIFIER (t); - tree fullname = name; - if (instantiates_primary_template_p (t)) - fullname = build_nt (TEMPLATE_ID_EXPR, name, - INNERMOST_TEMPLATE_ARGS (argvec)); - return build_typename_type (context, name, fullname, - typename_type); - } else { r = lookup_template_class (t, argvec, in_decl, context, @@ -15586,6 +15575,9 @@ tsubst (tree t, tree args, tsubst_flags_t complain, tree in_decl) gcc_assert (type != unknown_type_node); + if (tree d = maybe_dependent_member_ref (t, args, complain, in_decl)) + return d; + /* Reuse typedefs. We need to do this to handle dependent attributes, such as attribute aligned. */ if (TYPE_P (t) @@ -16815,16 +16807,58 @@ maybe_dependent_member_ref (tree t, tree args, tsubst_flags_t complain, if (!(complain & tf_dguide)) return NULL_TREE; - tree ctx = context_for_name_lookup (t); + tree decl = (t && TYPE_P (t)) ? TYPE_NAME (t) : t; + if (!decl || !DECL_P (decl)) + return NULL_TREE; + + tree ctx = context_for_name_lookup (decl); if (!CLASS_TYPE_P (ctx)) return NULL_TREE; ctx = tsubst (ctx, args, complain, in_decl); - if (dependent_scope_p (ctx)) - return build_qualified_name (NULL_TREE, ctx, DECL_NAME (t), - /*template_p=*/false); + if (!dependent_scope_p (ctx)) + return NULL_TREE; - return NULL_TREE; + if (TYPE_P (t)) + { + if (typedef_variant_p (t)) + t = strip_typedefs (t); + tree decl = TYPE_NAME (t); + if (decl) + decl = maybe_dependent_member_ref (decl, args, complain, in_decl); + if (!decl) + return NULL_TREE; + return cp_build_qualified_type_real (TREE_TYPE (decl), cp_type_quals (t), + complain); + } + + tree name = DECL_NAME (t); + tree fullname = name; + if (instantiates_primary_template_p (t)) + { + tree tinfo = get_template_info (t); + name = DECL_NAME (TI_TEMPLATE (tinfo)); + tree targs = INNERMOST_TEMPLATE_ARGS (TI_ARGS (tinfo)); + targs = tsubst_template_args (targs, args, complain, in_decl); + fullname = build_nt (TEMPLATE_ID_EXPR, name, targs); + } + + if (TREE_CODE (t) == TYPE_DECL) + { + if (TREE_CODE (TREE_TYPE (t)) == TYPENAME_TYPE + && TYPE_NAME (TREE_TYPE (t)) == t) + /* The TYPE_DECL for a typename has DECL_CONTEXT of the typename + scope, but it doesn't need to be rewritten again. */ + return NULL_TREE; + tree type = build_typename_type (ctx, name, fullname, typename_type); + return TYPE_NAME (type); + } + else if (DECL_TYPE_TEMPLATE_P (t)) + return make_unbound_class_template (ctx, name, + NULL_TREE, complain); + else + return build_qualified_name (NULL_TREE, ctx, fullname, + TREE_CODE (t) == TEMPLATE_DECL); } /* Like tsubst, but deals with expressions. This function just replaces @@ -16840,6 +16874,9 @@ tsubst_copy (tree t, tree args, tsubst_flags_t complain, tree in_decl) if (t == NULL_TREE || t == error_mark_node || args == NULL_TREE) return t; + if (tree d = maybe_dependent_member_ref (t, args, complain, in_decl)) + return d; + code = TREE_CODE (t); switch (code) @@ -16885,9 +16922,6 @@ tsubst_copy (tree t, tree args, tsubst_flags_t complain, tree in_decl) if (args == NULL_TREE) return scalar_constant_value (t); - if (tree ref = maybe_dependent_member_ref (t, args, complain, in_decl)) - return ref; - /* Unfortunately, we cannot just call lookup_name here. Consider: @@ -16938,9 +16972,6 @@ tsubst_copy (tree t, tree args, tsubst_flags_t complain, tree in_decl) return t; case VAR_DECL: - if (tree ref = maybe_dependent_member_ref (t, args, complain, in_decl)) - return ref; - gcc_fallthrough(); case FUNCTION_DECL: if (DECL_LANG_SPECIFIC (t) && DECL_TEMPLATE_INFO (t)) r = tsubst (t, args, complain, in_decl); @@ -17070,18 +17101,6 @@ tsubst_copy (tree t, tree args, tsubst_flags_t complain, tree in_decl) have to substitute this with one having context `D'. */ tree context = tsubst (DECL_CONTEXT (t), args, complain, in_decl); - if ((complain & tf_dguide) && dependent_scope_p (context)) - { - /* When rewriting a constructor into a deduction guide, a - non-dependent name can become dependent, so memtmpl - becomes context::template memtmpl. */ - if (DECL_TYPE_TEMPLATE_P (t)) - return make_unbound_class_template (context, DECL_NAME (t), - NULL_TREE, complain); - tree type = tsubst (TREE_TYPE (t), args, complain, in_decl); - return build_qualified_name (type, context, DECL_NAME (t), - /*template*/true); - } return lookup_field (context, DECL_NAME(t), 0, false); } else @@ -21711,21 +21730,6 @@ instantiate_alias_template (tree tmpl, tree args, tsubst_flags_t complain) if (tmpl == error_mark_node || args == error_mark_node) return error_mark_node; - /* See maybe_dependent_member_ref. */ - if (complain & tf_dguide) - { - tree ctx = tsubst_aggr_type (DECL_CONTEXT (tmpl), args, complain, - tmpl, true); - if (dependent_scope_p (ctx)) - { - tree name = DECL_NAME (tmpl); - tree fullname = build_nt (TEMPLATE_ID_EXPR, name, - INNERMOST_TEMPLATE_ARGS (args)); - tree tname = build_typename_type (ctx, name, fullname, typename_type); - return TYPE_NAME (tname); - } - } - args = coerce_innermost_template_parms (DECL_TEMPLATE_PARMS (tmpl), args, tmpl, complain,