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.133.124]) by sourceware.org (Postfix) with ESMTPS id D14A03858D20 for ; Thu, 2 May 2024 17:50:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D14A03858D20 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org D14A03858D20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714672247; cv=none; b=x6/PKh7wHYa9MN6kDmjyT+AlJ0/TuXj2dKv48pZ9mIpbTwGky5xsRHk8O0A/vN3rmUrQJ0OUNLHL1tqXUunFeeWsRi+iXTCYtKQxBeC2DTpZCct+cW26V7uPefDfL4mfP994OG6OAb46ktDdUP8ey/YRKPKVH6vfBqnA+I45Tl0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714672247; c=relaxed/simple; bh=krCd6bJzBkb/SlNq/49QwEoL6aqVebvuxIaP7o+okZs=; h=DKIM-Signature:From:Date:To:Subject:Message-ID:MIME-Version; b=ltB8J0rVSDJvwuGyLI03zhGoxA/OMFFxeprN5rw+/0nBhbJWPReTSNEkWrW/tuVnn3SzA1E83JyVpTntzL/Z3z1pij9MFtHdJhpSxRLZFa8ofjSrquzFxXu2fNgTYZ8RG6GTUDVBXRgRsGD7gpBnNesR4G2boBg+Lhtf+EZaGTY= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1714672241; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=kUYbKOfRj4z8UQIT+ggEUG/dij5uTqq8w+1jVDabX0k=; b=T9ox/rh+5KMaXCCee/RRjDMoP9T+F5G2DN2VaOwRMyppu+YfSKKQeGXe3s63Vr201npNBj +Zfbr6k9odfN/UO+Gu0G6+CnhNKiTqIwnBEVKGcxcWLFFOj+js+902D2mOKkp2ueNgNNey K+AHMse7wSk9Hpaqn0bkLk/WAYWE46k= Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-696-3qYRkiawMHKsUUUvDCe8Vg-1; Thu, 02 May 2024 13:49:22 -0400 X-MC-Unique: 3qYRkiawMHKsUUUvDCe8Vg-1 Received: by mail-qv1-f71.google.com with SMTP id 6a1803df08f44-6a0ff9833afso23263566d6.0 for ; Thu, 02 May 2024 10:49:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714672153; x=1715276953; h=mime-version:references:message-id:in-reply-to:subject:cc:to:date :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=kUYbKOfRj4z8UQIT+ggEUG/dij5uTqq8w+1jVDabX0k=; b=JFZp89c19Zvas+lacu1uhQUuBuHua9p7LBly5wwebPXQQbv2ISYmWRnK9q1AgLNFmu 8aN4by49eaR+eHIVH/m6mBqIXbXUXjOHHrkdHFW3RFKb9eVUyCxJwVwCM2avSpF6acCr S135ZTpxG+1bcfw4spHlmWFOzb4OziyfrhZgQs1nfalqPJgvhiJSyMfMHzxNIK4AMYCE jx8iJQ2AFb+ZSR5CsoyXuNIUuKWx+33fLtK+KhxwvUbeEzYkHyiLKtTEMq7ZHRH6AZ8u XiZ5pR6Uva+dXblkZeYpqQH45Qsuz/xt0pdv/GutJmpIqng0E+xhT9iiVpPzpGRFwjJG 7mcQ== X-Forwarded-Encrypted: i=1; AJvYcCXP3C4gs0ZkwUwapD3XgqaZjq5A59LLAYQiJ1uf1lQKPRb2U4hphD2i1WH/aTMGF5zDx5Uka1+6EotnETj2o2qzEExtwcqYwA== X-Gm-Message-State: AOJu0YxVjkGwTW0T96M6nXTJJG6/j5Z4FblDqFz4bSXK6OAK+O6NrJki 36S/OshSzpTwJjnd3gNQmQ6YcsxqrUnBFuWQBSd2bREJsslgkVDKH+B7TpC1aDBE1DPbbTLYb4Y 7gHHTIjhjIWBVaQGqOfhOzRzi2Nb/tHPJfPwfwjDcrqF1P/gqwx0Hlhg1377LuiQ= X-Received: by 2002:ad4:5de6:0:b0:6a0:64ee:e40d with SMTP id jn6-20020ad45de6000000b006a064eee40dmr911041qvb.22.1714672152591; Thu, 02 May 2024 10:49:12 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGT7sqkcxb6FgAroo0k2+qtklu7BzQvY449UVUQ8f3yHLo+KvE7HBCYllDrAF+Sv+J3T/ILKg== X-Received: by 2002:ad4:5de6:0:b0:6a0:64ee:e40d with SMTP id jn6-20020ad45de6000000b006a064eee40dmr910985qvb.22.1714672151962; Thu, 02 May 2024 10:49:11 -0700 (PDT) Received: from [192.168.1.130] (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id b4-20020ad45184000000b006a0fd54f979sm513517qvp.115.2024.05.02.10.49.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 May 2024 10:49:11 -0700 (PDT) From: Patrick Palka X-Google-Original-From: Patrick Palka Date: Thu, 2 May 2024 13:49:10 -0400 (EDT) To: Jason Merrill cc: Patrick Palka , gcc-patches@gcc.gnu.org Subject: Re: [PATCH 2/2] c++: remove lookup_template_class's entering_scope flag In-Reply-To: Message-ID: <484205c6-07fe-212b-8e88-73fdbc78b377@idea> References: <20240202194104.317982-1-ppalka@redhat.com> <20240202194104.317982-2-ppalka@redhat.com> <1053294c-b63c-b40b-0ba2-069e2bd615c3@idea> <0182a4aa-cb43-42ec-b8fd-c9a23424d889@redhat.com> <823f5898-02d1-e6a3-8e18-aa3695193a0f@idea> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-13.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,RCVD_IN_SORBS_WEB,SPF_HELO_NONE,SPF_NONE,TXREP 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: On Wed, 1 May 2024, Jason Merrill wrote: > On 5/1/24 13:40, Patrick Palka wrote: > > On Wed, 1 May 2024, Jason Merrill wrote: > > > > > On 5/1/24 12:41, Patrick Palka wrote: > > > > On Fri, 2 Feb 2024, Patrick Palka wrote: > > > > > > > > > Bootstrapped and regtested on x86_64-pc-linux, does this look like > > > > > an improvement? This is not a bugfix and barely related to the > > > > > previous > > > > > patch, but the previous patch's new use of entering_scope=true > > > > > motivated > > > > > me to submit this patch since it seems like a nice simplification. > > > > > > > > Ping, now that stage 1 is open. > > > > > > Thanks for the ping. The earlier message isn't showing up in Thunderbird > > > for > > > some reason, though I see it in the gmail web interface... > > > > Ah, weird. No worries, this patch was very much stage 1 material anyway. > > > > > > > > > > @@ -16771,9 +16722,10 @@ tsubst (tree t, tree args, tsubst_flags_t > > > > > complain, tree in_decl) > > > > > ctx = TREE_VEC_ELT (ctx, 0); > > > > > } > > > > > else > > > > > - ctx = tsubst_aggr_type (ctx, args, > > > > > - complain | tf_qualifying_scope, > > > > > - in_decl, /*entering_scope=*/1); > > > > > + { > > > > > + ctx = tsubst_scope (ctx, args, complain, in_decl); > > > > > > Why is this one tsubst_scope while the others are all plain tsubst? > > > > Ah, just because the call to tsubst_aggr_type being replace passes > > tf_qualifying_scope already, so we might as well use tsubst_scope > > as shorthand. > > > > > Do we want a tsubst_entering_scope function? > > > > Which is just shorthand for tsubst + adjust_type_for_entering_scope? > > That's what I was thinking. > > > Sure, though I was wondering if we eventually might want to get rid of > > the distinction between the primary template type A and the generic > > instantiation A, and we could treat this as an incremental step > > towards that (then we'd just eventually remove the > > adjust_type_for_entering_scope calls and keep the tsubst calls). > > I don't think we want that; having the distinction helps to avoid wrongly > looking up members of the primary template in contexts that shouldn't be able > to. Makes sense. How does the following look? The name tsubst_entering_scope sounds confusingly similar to tsubst_scope, but I can't think of a better name for it or for adjust_type_for_entering_scope :/ -- >8 -- Subject: [PATCH] c++: remove lookup_template_class's entering_scope flag gcc/cp/ChangeLog: * coroutines.cc (instantiate_coro_traits): Adjust call to lookup_template_class. (instantiate_coro_handle_for_promise_type): Likewise. * cp-tree.h (adjust_type_for_entering_scope): Declare. (lookup_template_class): Adjust declaration. * decl.cc (make_typename_type): Adjust call to lookup_template_class. Likewise. (get_tuple_size): Likewise. (get_tuple_element_type): Likewise. * pt.cc (adjust_type_for_entering_scope): Define. (tsubst_entering_scope): Define. (lookup_template_class): Remove entering_scope parameter. Replace tsubst_aggr_type call with tsubst_entering_scope. (tsubst_aggr_type): Remove. (tsubst_aggr_type_1): Inline into tsubst. (tsubst_function_decl): Replace tsubst_aggr_type call with tsubst_entering_scope. (tsubst_template_decl): Likewise. (tsubst_decl): Likewise. (tsubst) : Inlined from tsubst_aggr_type_1. : Adjust calls to lookup_template_class. : Replace tsubst_aggr_type call with tsubst_scope followed by adjust_type_for_entering_scope. : Replace tsubst_aggr_type call with tsubst_entering_scope. Increment processing_template_decl when substituting the context. (tsubst_expr) : Replace tsubst_aggr_type call with tsubst_entering_scope. : Likewise. (instantiate_template): Likewise. (resolve_typename_type): Adjust lookup_template_class call and call adjust_type_for_entering_scope afterward. (listify): Adjust lookup_template_class call. (alias_ctad_tweaks): Likewise. * semantics.cc (finish_template_type): Adjust lookup_template_class call and maybe call adjust_type_for_entering_scope afterward. --- gcc/cp/coroutines.cc | 4 +- gcc/cp/cp-tree.h | 3 +- gcc/cp/decl.cc | 4 +- gcc/cp/pt.cc | 209 +++++++++++++++++-------------------------- gcc/cp/semantics.cc | 4 +- 5 files changed, 90 insertions(+), 134 deletions(-) diff --git a/gcc/cp/coroutines.cc b/gcc/cp/coroutines.cc index b05cb9eb330..97bc211ff67 100644 --- a/gcc/cp/coroutines.cc +++ b/gcc/cp/coroutines.cc @@ -353,7 +353,7 @@ instantiate_coro_traits (tree fndecl, location_t kw) tree traits_class = lookup_template_class (coro_traits_templ, targ, /*in_decl=*/NULL_TREE, /*context=*/NULL_TREE, - /*entering scope=*/false, tf_warning_or_error); + tf_warning_or_error); if (traits_class == error_mark_node) { @@ -400,7 +400,7 @@ instantiate_coro_handle_for_promise_type (location_t kw, tree promise_type) = lookup_template_class (coro_handle_identifier, targ, /* in_decl=*/NULL_TREE, /* context=*/std_node, - /* entering scope=*/false, tf_warning_or_error); + tf_warning_or_error); if (handle_type == error_mark_node) { diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 5d1bd6ba493..bc8e22cc39f 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -7521,8 +7521,9 @@ extern tree push_template_decl (tree, bool is_friend = false); extern tree add_inherited_template_parms (tree, tree); extern void template_parm_level_and_index (tree, int*, int*); extern bool redeclare_class_template (tree, tree, tree); +extern tree adjust_type_for_entering_scope (tree); extern tree lookup_template_class (tree, tree, tree, tree, - int, tsubst_flags_t); + tsubst_flags_t); extern tree lookup_template_function (tree, tree); extern tree lookup_template_variable (tree, tree, tsubst_flags_t); extern bool uses_template_parms (tree); diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc index df855334133..876f77cbbe3 100644 --- a/gcc/cp/decl.cc +++ b/gcc/cp/decl.cc @@ -4574,7 +4574,6 @@ make_typename_type (tree context, tree name, enum tag_types tag_type, { t = lookup_template_class (t, TREE_OPERAND (fullname, 1), NULL_TREE, context, - /*entering_scope=*/0, complain | tf_user); if (t == error_mark_node) return error_mark_node; @@ -9168,7 +9167,7 @@ get_tuple_size (tree type) tree inst = lookup_template_class (tuple_size_identifier, args, /*in_decl*/NULL_TREE, /*context*/std_node, - /*entering_scope*/false, tf_none); + tf_none); inst = complete_type (inst); if (inst == error_mark_node || !COMPLETE_TYPE_P (inst) @@ -9197,7 +9196,6 @@ get_tuple_element_type (tree type, unsigned i) tree inst = lookup_template_class (tuple_element_identifier, args, /*in_decl*/NULL_TREE, /*context*/std_node, - /*entering_scope*/false, tf_warning_or_error); return make_typename_type (inst, type_identifier, none_type, tf_warning_or_error); diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index 1c3eef60c06..261d6b9f4c8 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -185,8 +185,6 @@ static int unify_pack_expansion (tree, tree, tree, static tree copy_template_args (tree); static tree tsubst_template_parms (tree, tree, tsubst_flags_t); static void tsubst_each_template_parm_constraints (tree, tree, tsubst_flags_t); -static tree tsubst_aggr_type (tree, tree, tsubst_flags_t, tree, int); -static tree tsubst_aggr_type_1 (tree, tree, tsubst_flags_t, tree, int); static tree tsubst_arg_types (tree, tree, tree, tsubst_flags_t, tree); static tree tsubst_function_type (tree, tree, tsubst_flags_t, tree); static bool check_specialization_scope (void); @@ -9901,6 +9899,34 @@ maybe_get_template_decl_from_type_decl (tree decl) ? CLASSTYPE_TI_TEMPLATE (TREE_TYPE (decl)) : decl; } +/* If TYPE is the generic implicit instantiation A, return the primary + template type A (which is suitable for entering into e.g. for name + lookup), otherwise return TYPE. */ + +tree +adjust_type_for_entering_scope (tree type) +{ + if (CLASS_TYPE_P (type) + && dependent_type_p (type) + && TYPE_TEMPLATE_INFO (type) + /* We detect the generic implicit instantiation A by inspecting + TYPE_CANONICAL, which lookup_template_class sets to the primary + template type A. */ + && TYPE_CANONICAL (type) == TREE_TYPE (TYPE_TI_TEMPLATE (type))) + type = TYPE_CANONICAL (type); + return type; +} + +/* Convenience wrapper over tsubst that does adjust_type_for_entering_scope + on the result. */ + +static tree +tsubst_entering_scope (tree t, tree args, tsubst_flags_t complain, tree in_decl) +{ + t = tsubst (t, args, complain, in_decl); + return adjust_type_for_entering_scope (t); +} + /* Given an IDENTIFIER_NODE (or type TEMPLATE_DECL) and a chain of parameters, find the desired type. @@ -9909,9 +9935,6 @@ maybe_get_template_decl_from_type_decl (tree decl) IN_DECL, if non-NULL, is the template declaration we are trying to instantiate. - If ENTERING_SCOPE is nonzero, we are about to enter the scope of - the class we are looking up. - Issue error and warning messages under control of COMPLAIN. If the template class is really a local class in a template @@ -9927,7 +9950,7 @@ maybe_get_template_decl_from_type_decl (tree decl) tree lookup_template_class (tree d1, tree arglist, tree in_decl, tree context, - int entering_scope, tsubst_flags_t complain) + tsubst_flags_t complain) { auto_timevar tv (TV_TEMPLATE_INST); @@ -10139,9 +10162,10 @@ lookup_template_class (tree d1, tree arglist, tree in_decl, tree context, template class C { void f(C); } the `C' is just the same as `C'. Outside of the - class, however, such a reference is an instantiation. */ - if (entering_scope - || !PRIMARY_TEMPLATE_P (gen_tmpl) + class, however, such a reference is an instantiation. + One can use adjust_type_for_entering_scope to make + this adjustment as needed. */ + if (!PRIMARY_TEMPLATE_P (gen_tmpl) || currently_open_class (template_type)) { tree tinfo = TYPE_TEMPLATE_INFO (template_type); @@ -10207,8 +10231,8 @@ lookup_template_class (tree d1, tree arglist, tree in_decl, tree context, context = DECL_CONTEXT (templ); else { - context = tsubst_aggr_type (context, arglist, - complain, in_decl, true); + context = tsubst_entering_scope (context, arglist, + complain, in_decl); /* Try completing the enclosing context if it's not already so. */ if (context != error_mark_node && !COMPLETE_TYPE_P (context)) @@ -14148,94 +14172,6 @@ tsubst_each_template_parm_constraints (tree parms, tree args, --processing_template_decl; } -/* Substitute the ARGS into the indicated aggregate (or enumeration) - type T. If T is not an aggregate or enumeration type, it is - handled as if by tsubst. IN_DECL is as for tsubst. If - ENTERING_SCOPE is nonzero, T is the context for a template which - we are presently tsubst'ing. Return the substituted value. */ - -static tree -tsubst_aggr_type (tree t, - tree args, - tsubst_flags_t complain, - tree in_decl, - int entering_scope) -{ - if (t == NULL_TREE) - return NULL_TREE; - - /* Handle typedefs via tsubst so that they get consistently reused. */ - if (typedef_variant_p (t)) - { - t = tsubst (t, args, complain, in_decl); - if (t == error_mark_node) - return error_mark_node; - - /* The effect of entering_scope is that for a dependent specialization - A, lookup_template_class prefers to return A's primary template - type instead of the implicit instantiation. So when entering_scope, - we mirror this behavior by inspecting TYPE_CANONICAL appropriately, - taking advantage of the fact that lookup_template_class links the two - types by setting TYPE_CANONICAL of the latter to the former. */ - if (entering_scope - && CLASS_TYPE_P (t) - && dependent_type_p (t) - && TYPE_TEMPLATE_INFO (t) - && TYPE_CANONICAL (t) == TREE_TYPE (TYPE_TI_TEMPLATE (t))) - t = TYPE_CANONICAL (t); - - return t; - } - - switch (TREE_CODE (t)) - { - case RECORD_TYPE: - case ENUMERAL_TYPE: - case UNION_TYPE: - return tsubst_aggr_type_1 (t, args, complain, in_decl, entering_scope); - - default: - return tsubst (t, args, complain, in_decl); - } -} - -/* The part of tsubst_aggr_type that's shared with the RECORD_, UNION_ - and ENUMERAL_TYPE cases of tsubst. */ - -static tree -tsubst_aggr_type_1 (tree t, - tree args, - tsubst_flags_t complain, - tree in_decl, - int entering_scope) -{ - if (TYPE_TEMPLATE_INFO (t) && uses_template_parms (t)) - { - complain &= ~tf_qualifying_scope; - - /* Figure out what arguments are appropriate for the - type we are trying to find. For example, given: - - template struct S; - template void f(T, U) { S su; } - - and supposing that we are instantiating f, - then our ARGS will be {int, double}, but, when looking up - S we only want {double}. */ - tree argvec = tsubst_template_args (TYPE_TI_ARGS (t), args, - complain, in_decl); - if (argvec == error_mark_node) - return error_mark_node; - - tree r = lookup_template_class (t, argvec, in_decl, NULL_TREE, - entering_scope, complain); - return cp_build_qualified_type (r, cp_type_quals (t), complain); - } - else - /* This is not a template type, so there's nothing to do. */ - return t; -} - /* Map from a FUNCTION_DECL to a vec of default argument instantiations, indexed in reverse order of the parameters. */ @@ -14601,8 +14537,7 @@ tsubst_function_decl (tree t, tree args, tsubst_flags_t complain, lambda_fntype = static_fn_type (lambda_fntype); if (member && !closure) - ctx = tsubst_aggr_type (ctx, args, - complain, t, /*entering_scope=*/1); + ctx = tsubst_entering_scope (ctx, args, complain, t); tree type = (lambda_fntype ? lambda_fntype : tsubst (TREE_TYPE (t), args, @@ -14996,8 +14931,7 @@ tsubst_template_decl (tree t, tree args, tsubst_flags_t complain, inner = TREE_TYPE (inner); } if (class_p) - inner = tsubst_aggr_type (inner, args, complain, - in_decl, /*entering*/1); + inner = tsubst_entering_scope (inner, args, complain, in_decl); else inner = tsubst_decl (inner, args, complain, /*use_spec_table=*/false); } @@ -15501,9 +15435,7 @@ tsubst_decl (tree t, tree args, tsubst_flags_t complain, local_p = false; if (DECL_CLASS_SCOPE_P (t)) { - ctx = tsubst_aggr_type (ctx, args, - complain, - in_decl, /*entering_scope=*/1); + ctx = tsubst_entering_scope (ctx, args, complain, in_decl); if (DECL_SELF_REFERENCE_P (t)) /* The context and type of an injected-class-name are the same, so we don't need to substitute both. */ @@ -16299,8 +16231,31 @@ tsubst (tree t, tree args, tsubst_flags_t complain, tree in_decl) /* Fall through. */ case UNION_TYPE: case ENUMERAL_TYPE: - return tsubst_aggr_type_1 (t, args, complain, in_decl, - /*entering_scope=*/0); + if (TYPE_TEMPLATE_INFO (t) && uses_template_parms (t)) + { + complain &= ~tf_qualifying_scope; + + /* Figure out what arguments are appropriate for the + type we are trying to find. For example, given: + + template struct S; + template void f(T, U) { S su; } + + and supposing that we are instantiating f, + then our ARGS will be {int, double}, but, when looking up + S we only want {double}. */ + tree argvec = tsubst_template_args (TYPE_TI_ARGS (t), args, + complain, in_decl); + if (argvec == error_mark_node) + return error_mark_node; + + tree r = lookup_template_class (t, argvec, in_decl, NULL_TREE, + complain); + return cp_build_qualified_type (r, cp_type_quals (t), complain); + } + else + /* This is not a template type, so there's nothing to do. */ + return t; case ERROR_MARK: case IDENTIFIER_NODE: @@ -16492,7 +16447,6 @@ tsubst (tree t, tree args, tsubst_flags_t complain, tree in_decl) r = lookup_template_class (arg, argvec, in_decl, DECL_CONTEXT (arg), - /*entering_scope=*/0, complain); return cp_build_qualified_type (r, cp_type_quals (t) | cp_type_quals (r), complain); @@ -16584,7 +16538,7 @@ tsubst (tree t, tree args, tsubst_flags_t complain, tree in_decl) if (argvec == error_mark_node) return error_mark_node; r = lookup_template_class (tmpl, argvec, in_decl, NULL_TREE, - /*entering_scope=*/false, complain); + complain); r = cp_build_qualified_type (r, cp_type_quals (t), complain); break; } @@ -16839,9 +16793,10 @@ tsubst (tree t, tree args, tsubst_flags_t complain, tree in_decl) ctx = TREE_VEC_ELT (ctx, 0); } else - ctx = tsubst_aggr_type (ctx, args, - complain | tf_qualifying_scope, - in_decl, /*entering_scope=*/1); + { + ctx = tsubst_scope (ctx, args, complain, in_decl); + ctx = adjust_type_for_entering_scope (ctx); + } if (ctx == error_mark_node) return error_mark_node; @@ -16914,8 +16869,10 @@ tsubst (tree t, tree args, tsubst_flags_t complain, tree in_decl) case UNBOUND_CLASS_TEMPLATE: { - tree ctx = tsubst_aggr_type (TYPE_CONTEXT (t), args, complain, - in_decl, /*entering_scope=*/1); + ++processing_template_decl; + tree ctx = tsubst_entering_scope (TYPE_CONTEXT (t), args, + complain, in_decl); + --processing_template_decl; tree name = TYPE_IDENTIFIER (t); tree parm_list = DECL_TEMPLATE_PARMS (TYPE_NAME (t)); @@ -21564,9 +21521,7 @@ tsubst_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl) When we instantiate f<7>::S::g(), say, lookup_name is not clever enough to find f<7>::a. */ - enum_type - = tsubst_aggr_type (DECL_CONTEXT (t), args, complain, in_decl, - /*entering_scope=*/0); + enum_type = tsubst (DECL_CONTEXT (t), args, complain, in_decl); for (v = TYPE_VALUES (enum_type); v != NULL_TREE; @@ -21586,8 +21541,8 @@ tsubst_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl) { tree ctx; - ctx = tsubst_aggr_type (DECL_CONTEXT (t), args, complain, in_decl, - /*entering_scope=*/1); + ctx = tsubst_entering_scope (DECL_CONTEXT (t), args, + complain, in_decl); if (ctx != DECL_CONTEXT (t)) { tree r = lookup_field (ctx, DECL_NAME (t), 0, false); @@ -21630,8 +21585,8 @@ tsubst_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl) TEMPLATE_DECL with `D' as its DECL_CONTEXT. Now we have to substitute this with one having context `D'. */ - tree context = tsubst_aggr_type (DECL_CONTEXT (t), args, complain, - in_decl, /*entering_scope=*/true); + tree context = tsubst_entering_scope (DECL_CONTEXT (t), args, + complain, in_decl); RETURN (lookup_field (context, DECL_NAME(t), 0, false)); } else @@ -22161,8 +22116,8 @@ instantiate_template (tree tmpl, tree orig_args, tsubst_flags_t complain) already non-dependent, then we might as well use it. */ ctx = DECL_CONTEXT (tmpl); else - ctx = tsubst_aggr_type (DECL_CONTEXT (gen_tmpl), targ_ptr, - complain, gen_tmpl, true); + ctx = tsubst_entering_scope (DECL_CONTEXT (gen_tmpl), targ_ptr, + complain, gen_tmpl); push_nested_class (ctx); } @@ -29324,8 +29279,8 @@ resolve_typename_type (tree type, bool only_current_p) tree args = TREE_OPERAND (fullname, 1); /* Instantiate the template. */ result = lookup_template_class (tmpl, args, NULL_TREE, NULL_TREE, - /*entering_scope=*/true, tf_error | tf_user); + result = adjust_type_for_entering_scope (result); if (result == error_mark_node) result = NULL_TREE; } @@ -29564,7 +29519,7 @@ listify (tree arg) TREE_VEC_ELT (argvec, 0) = arg; return lookup_template_class (std_init_list, argvec, NULL_TREE, - NULL_TREE, 0, tf_warning_or_error); + NULL_TREE, tf_warning_or_error); } /* Replace auto in TYPE with std::initializer_list. */ @@ -30510,7 +30465,7 @@ alias_ctad_tweaks (tree tmpl, tree uguides) fprime = copy_decl (fprime); tree fntype = TREE_TYPE (fprime); ret = lookup_template_class (TPARMS_PRIMARY_TEMPLATE (atparms), targs, - in_decl, NULL_TREE, false, complain); + in_decl, NULL_TREE, complain); fntype = build_function_type (ret, TYPE_ARG_TYPES (fntype)); TREE_TYPE (fprime) = fntype; if (TREE_CODE (fprime) == TEMPLATE_DECL) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 2dde65a970b..d0fa324fe5c 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -4011,8 +4011,10 @@ finish_template_type (tree name, tree args, int entering_scope) tree type; type = lookup_template_class (name, args, - NULL_TREE, NULL_TREE, entering_scope, + NULL_TREE, NULL_TREE, tf_warning_or_error | tf_user); + if (entering_scope) + type = adjust_type_for_entering_scope (type); /* If we might be entering the scope of a partial specialization, find the one with the right constraints. */ -- 2.45.0.31.gd4cc1ec35f