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 6F76338582A0 for ; Fri, 2 Feb 2024 19:41:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6F76338582A0 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 6F76338582A0 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=1706902876; cv=none; b=Vf1YQY/BYB/435QM1YRh/sLYqWFmOJRTPem82KR3+SeoFeBUub853mPXwzUKiActKtdG3IxxJiwg9EMJoqIWKDvSiIM9PVir31SMrSHjp1Ls9DPUmrolhpC6G2T6YBLvntBX+YFg5d1zg1OfUZKovXlS9BmfMLgbjGS/AcqcNxE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706902876; c=relaxed/simple; bh=jotcGvK5A4X5iN85nc3VnLXZZVDJ1FdaVpJEfNUOEUw=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=VsweNdyo197uq4b3qHHz0S2gFfvWOvrzYaBsSp1BCYoRq9oI3lvVtxnvuJBJBtz5ycWlh/u83PMEdHS6afeX1vm9sXEhdHdPT6k7QWqO+Mx5WchpLkcd9uoSsBMFrfuiXaZW2p7mZTd76yCMfRSiSn7qXN6QcZR0/Us+zylf6RE= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706902872; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CyB6pbpGrpS3V0xMKom97xbeWDtv5g7PsdmG8Trj7fI=; b=ShSDbDAy8mq4AKVrzYr8q3JO1gpJ/L0cyQGQfmaukTSjOilD7Iaxut/VQKRAHeCK68KZUN o4hK78AV9kl1qqyU1E+sNy14j/YyVU5JJcH/fJyloxmXt6Pn01Ym4j/Nfw/hia0Njp12c9 u4plVj05PHowtnLuGMBxWL9LfFyJtXk= Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-392-GoMbDMB8MjWPoMU_8JRSvw-1; Fri, 02 Feb 2024 14:41:10 -0500 X-MC-Unique: GoMbDMB8MjWPoMU_8JRSvw-1 Received: by mail-qv1-f69.google.com with SMTP id 6a1803df08f44-68c51abe499so36931806d6.2 for ; Fri, 02 Feb 2024 11:41:10 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706902869; x=1707507669; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CyB6pbpGrpS3V0xMKom97xbeWDtv5g7PsdmG8Trj7fI=; b=BBdt11B5F9FlXz18q6SQq9uWbsCzhLzgAylGZbcYIHFKofJD/sgGHCcotdY9KNTB6L 2gCT8hHTTOE7T66llnhExnfK6tG2uuQzm0CMJ71yBOsHult4jdnzX6KOLSALR1SY9M/V er1ECcekcZbKlqVjSUhRJpsRBbhKInQ4nx2rpI31X9FsFlE+nnLaZptS1mCvWQhYEtxb mW0/j/kfn+VVDTBoBgDBQOqRXdthrdheJnuQ8XY+/q/++RwwEsO0JIfk+9wlN6kgo3JN 55pQX20ZPUoR/JSAfmdYkP2tUe7hFtqKVzvOK/hnqMno42/Mh/3spjSZD1lRJu9RUzru t86g== X-Gm-Message-State: AOJu0Yz6OWASR0DUxcZ91xzUD8mvBWezF2zRMlWmoHc5HYAfMJFZCyeA MlQZGuuJ6j7aT6FWINIjiECCnO4eGMhnU8xafTiYNpyxogjtged8XU/tdzPFeiZUhn8xmkDwpgc t4XCvea1iOSUvHt9o+fISJzoa14Iu9p108T72jpPrHXSUf57aTGxpOhKNlKsSRIxC2UcAKuItI/ swoXlXRtdJg59kiJA82L+H7KrxgatypTT9NZmb X-Received: by 2002:a05:6214:e88:b0:68c:6af8:e57c with SMTP id hf8-20020a0562140e8800b0068c6af8e57cmr10544166qvb.12.1706902868599; Fri, 02 Feb 2024 11:41:08 -0800 (PST) X-Google-Smtp-Source: AGHT+IFxq+tEIWc1Y/k5ko63JHRzxasjhNVi/OMvdlKI4OYmz7/fNkaPa6RqxiH9mvDFo7BaicyxlQ== X-Received: by 2002:a05:6214:e88:b0:68c:6af8:e57c with SMTP id hf8-20020a0562140e8800b0068c6af8e57cmr10544130qvb.12.1706902868028; Fri, 02 Feb 2024 11:41:08 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCXHLj0MXdb+7JzHmBKQ/GFcegNJdIrDhhOmWq/utYVJhVCiij55NtdC2ECkGYnIsOfxh40tcboDz4zCVs/xc1ghmQ== Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id mv1-20020a056214338100b0068c816c7bc5sm1060016qvb.101.2024.02.02.11.41.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Feb 2024 11:41:07 -0800 (PST) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, Patrick Palka Subject: [PATCH 2/2] c++: remove lookup_template_class's entering_scope flag Date: Fri, 2 Feb 2024 14:41:04 -0500 Message-ID: <20240202194104.317982-2-ppalka@redhat.com> X-Mailer: git-send-email 2.43.0.493.gbc7ee2e5e1 In-Reply-To: <20240202194104.317982-1-ppalka@redhat.com> References: <20240202194104.317982-1-ppalka@redhat.com> 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=-14.0 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_H5,RCVD_IN_MSPIKE_WL,RCVD_IN_SORBS_WEB,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: 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. -- >8 -- lookup_template_class's entering_scope flag controls whether to prefer returning the primary template type A instead of the corresponding implicit instantiation A. When we want to set this flag as part of substitution, we need to use tsubst_aggr_type which also takes the flag, but this separate entry point to substitution turned out to be subtly problematic because it doesn't reuse typedefs like tsubst does, which r13-4729-gbe124477b38a71 fixed in a way that respects the flag after the fact, by adjusting the entering_scope=false result of lookup_template_class as if entering_scope=true was passed. But if that's possible then it means lookup_template_class's the entering_scope flag is not necessary after all -- we can just do the after-the-fact adjustment everywhere that we currently pass entering_scope=true to it and tsubst_aggr_type. To that end, this patch replaces this flag with an adjustment function adjust_type_for_entering_scope, to be used whereever we currently need the entering_scope=true behavior. This means we can also get rid of tsubst_aggr_type, since the only reason we needed this entry point was to be able to pass entering_scope=true to lookup_template_class. 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. (lookup_template_class): Remove entering_scope parameter. Replace tsubst_aggr_type call with tsubst followed by adjust_type_for_entering_scope. (tsubst_aggr_type): Remove. (tsubst_aggr_type_1): Inline into tsubst. (tsubst_function_decl): Replace tsubst_aggr_type call with tsubst followed by adjust_type_for_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 tsubst_scope followed by adjust_type_for_entering_scope. : Replace tsubst_aggr_type call with tsubst followed by adjust_type_for_entering_scope. Increment processing_template_decl when substituting the context. (tsubst_baselink): Replace tsubst_aggr_type call with tsubst followed by adjust_type_for_entering_scope. (tsubst_expr) : Replace tsubst_aggr_type call with tsubst followed by adjust_type_for_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 | 212 +++++++++++++++++-------------------------- gcc/cp/semantics.cc | 4 +- 5 files changed, 91 insertions(+), 136 deletions(-) diff --git a/gcc/cp/coroutines.cc b/gcc/cp/coroutines.cc index 3194c911e8c..8dab173d5cb 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 969c7239c97..4f73a7c84b6 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -7506,8 +7506,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 3e41fd4fa31..8149aab5781 100644 --- a/gcc/cp/decl.cc +++ b/gcc/cp/decl.cc @@ -4569,7 +4569,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; @@ -9163,7 +9162,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) @@ -9192,7 +9191,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 17ecd4b9c5a..baf9b0e6fda 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); @@ -9873,6 +9871,24 @@ 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; +} + /* Given an IDENTIFIER_NODE (or type TEMPLATE_DECL) and a chain of parameters, find the desired type. @@ -9881,9 +9897,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 @@ -9899,7 +9912,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); @@ -10085,9 +10098,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); @@ -10154,8 +10168,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 (context, arglist, complain, in_decl); + context = adjust_type_for_entering_scope (context); /* Try completing the enclosing context if it's not already so. */ if (context != error_mark_node && !COMPLETE_TYPE_P (context)) @@ -14091,94 +14105,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. */ @@ -14544,8 +14470,10 @@ 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 (ctx, args, complain, t); + ctx = adjust_type_for_entering_scope (ctx); + } tree type = (lambda_fntype ? lambda_fntype : tsubst (TREE_TYPE (t), args, @@ -14938,8 +14866,10 @@ 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 (inner, args, complain, in_decl); + inner = adjust_type_for_entering_scope (inner); + } else inner = tsubst_decl (inner, args, complain, /*use_spec_table=*/false); } @@ -15443,9 +15373,8 @@ 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 (ctx, args, complain, in_decl); + ctx = adjust_type_for_entering_scope (ctx); 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. */ @@ -16241,8 +16170,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: @@ -16424,7 +16376,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); @@ -16516,7 +16467,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; } @@ -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); + ctx = adjust_type_for_entering_scope (ctx); + } if (ctx == error_mark_node) return error_mark_node; @@ -16846,8 +16798,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 (TYPE_CONTEXT (t), args, complain, in_decl); + ctx = adjust_type_for_entering_scope (ctx); + --processing_template_decl; tree name = TYPE_IDENTIFIER (t); tree parm_list = DECL_TEMPLATE_PARMS (TYPE_NAME (t)); @@ -17065,8 +17019,8 @@ tsubst_baselink (tree baselink, tree object_type, { bool qualified_p = BASELINK_QUALIFIED_P (baselink); tree qualifying_scope = BINFO_TYPE (BASELINK_ACCESS_BINFO (baselink)); - qualifying_scope = tsubst_aggr_type (qualifying_scope, args, complain, in_decl, - /*entering_scope=*/true); + qualifying_scope = tsubst (qualifying_scope, args, complain, in_decl); + qualifying_scope = adjust_type_for_entering_scope (qualifying_scope); tree optype = BASELINK_OPTYPE (baselink); optype = tsubst (optype, args, complain, in_decl); @@ -21451,9 +21405,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; @@ -21473,8 +21425,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 (DECL_CONTEXT (t), args, complain, in_decl); + ctx = adjust_type_for_entering_scope (ctx); if (ctx != DECL_CONTEXT (t)) { tree r = lookup_field (ctx, DECL_NAME (t), 0, false); @@ -21517,8 +21469,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 (DECL_CONTEXT (t), args, complain, in_decl); + context = adjust_type_for_entering_scope (context); RETURN (lookup_field (context, DECL_NAME(t), 0, false)); } else @@ -22060,8 +22012,10 @@ 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 (DECL_CONTEXT (gen_tmpl), targ_ptr, complain, gen_tmpl); + ctx = adjust_type_for_entering_scope (ctx); + } push_nested_class (ctx); } @@ -29214,8 +29168,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; } @@ -29443,7 +29397,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. */ @@ -30389,7 +30343,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 3299e270446..cea819db221 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -3946,8 +3946,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.43.0.493.gbc7ee2e5e1