From patchwork Tue Nov 3 16:41:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 1393199 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=acm.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=QpFXOrNI; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CQbCb1RXLz9sSn for ; Wed, 4 Nov 2020 03:41:46 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 97D7B3986800; Tue, 3 Nov 2020 16:41:43 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-qv1-xf36.google.com (mail-qv1-xf36.google.com [IPv6:2607:f8b0:4864:20::f36]) by sourceware.org (Postfix) with ESMTPS id DDF633854806 for ; Tue, 3 Nov 2020 16:41:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org DDF633854806 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=acm.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=nathanmsidwell@gmail.com Received: by mail-qv1-xf36.google.com with SMTP id q1so5925542qvn.5 for ; Tue, 03 Nov 2020 08:41:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:to:from:subject:message-id:date:user-agent:mime-version :content-language; bh=K/L0LdlCNDSndMmAYR8NSHkpYsvrZDpFFo7NheRKTn4=; b=QpFXOrNIv2oP8aZHcVfjSPxb5kfSBOIhQQSbo/0kIPQ2cP+iAm5sRniYFAKVFe/wCR flQ41aviLDXG1xwKT8sRqWy/5ZVkWwELo0VfFoXe+SN3rva3ECLgMmOhfhiZqhHJkw2/ e4X0Abz7vOwVlmPaoq3FHXg0zLHCMO5OV1xLpjmga5e8FUw5Jk5XZP4JxrjXjOk4s0E/ ey7XP5vkQQ65kut3j5+M3ndW9KF0obGaK1hwWfH6SWsgkCu6YTz9i34tgjZhs+epAkRR QhIjywhDH8++OdFyAFLbKKNcwGnM2HMZTj7X1GxEf8N+UIoDCTjHiA4hjHdFKz7I6WOE SVVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:to:from:subject:message-id:date :user-agent:mime-version:content-language; bh=K/L0LdlCNDSndMmAYR8NSHkpYsvrZDpFFo7NheRKTn4=; b=tmwezdXGvtq6icZDCYEt2LXEvaYjx+0gQ0XZ3zzZ3Z3LGtzi1F/Escw6GU7T0F+Yel nEr0L58H7Wt0nD4Zzw6lGqqcZpW47gvttIXNlLEd87i+hFX/VNYeRTGLolEgRuAHf5vQ bclqOqmM0opJ65Sxf8bitEGpBDBncsIg5zEGeC6xhhIZ6FLZHKv9eurYUjtHU5OD3jvH UCXrDUbbdTg2M3DGrVcOXviIte0xjP8PXah0wD7Edp8WhdsjUGwteQ1R5txZQq9KbJW4 Lpz5nsgKMGdu1St9vW5KNWz/0+kkSVQL0bMKB2DTUEOftJo5GMgesvdgRa13hLLSXSIx dMpA== X-Gm-Message-State: AOAM532KmkqqaEh4y/RT2lfjdVJarfgG+dagqW1XbfMAqUW7vNMm+cvZ WVUG9/+xbYGFexRED6xMmwPW7jEGh2XhWQ== X-Google-Smtp-Source: ABdhPJxIbmFk8qzZwgwVBYTEKEof3Z9enVx4p7pn0108SourZiwTRqbV9yk4gsCBacRbafD2ZhyUOg== X-Received: by 2002:a05:6214:1541:: with SMTP id t1mr26899666qvw.61.1604421700063; Tue, 03 Nov 2020 08:41:40 -0800 (PST) Received: from ?IPv6:2620:10d:c0a8:1102:e5ef:7eb4:1609:98bb? ([2620:10d:c091:480::1:bc2d]) by smtp.googlemail.com with ESMTPSA id e6sm10585804qtp.23.2020.11.03.08.41.38 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 03 Nov 2020 08:41:38 -0800 (PST) To: GCC Patches From: Nathan Sidwell Subject: c++: A couple of template instantiation cleanups Message-ID: <8406c07a-831e-440c-88e3-cdaf6cb4545d@acm.org> Date: Tue, 3 Nov 2020 11:41:37 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 Content-Language: en-US X-Spam-Status: No, score=-11.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: , Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" I noticed that we were handling lambda extra scope during template instantiation in a different order to how we handle the non-template case. Reordered that for consistency. Also some more RAII during template instantiation. gcc/cp/ * pt.c (tsubst_lambda_expr): Reorder extra-scope handling to match the non-template case. (instantiate_body): Move a couple of declarations to their initializers. pushing to trunk diff --git i/gcc/cp/pt.c w/gcc/cp/pt.c index aa162d2a4f9..2041b5635f0 100644 --- i/gcc/cp/pt.c +++ w/gcc/cp/pt.c @@ -19081,15 +19081,6 @@ tsubst_lambda_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl) LAMBDA_EXPR_MUTABLE_P (r) = LAMBDA_EXPR_MUTABLE_P (t); LAMBDA_EXPR_INSTANTIATED (r) = true; - if (LAMBDA_EXPR_EXTRA_SCOPE (t) == NULL_TREE) - /* A lambda in a default argument outside a class gets no - LAMBDA_EXPR_EXTRA_SCOPE, as specified by the ABI. But - tsubst_default_argument calls start_lambda_scope, so we need to - specifically ignore it here, and use the global scope. */ - record_null_lambda_scope (r); - else - record_lambda_scope (r); - gcc_assert (LAMBDA_EXPR_THIS_CAPTURE (t) == NULL_TREE && LAMBDA_EXPR_PENDING_PROXIES (t) == NULL); @@ -19168,6 +19159,15 @@ tsubst_lambda_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl) if (type == error_mark_node) return error_mark_node; + if (LAMBDA_EXPR_EXTRA_SCOPE (t) == NULL_TREE) + /* A lambda in a default argument outside a class gets no + LAMBDA_EXPR_EXTRA_SCOPE, as specified by the ABI. But + tsubst_default_argument calls start_lambda_scope, so we need to + specifically ignore it here, and use the global scope. */ + record_null_lambda_scope (r); + else + record_lambda_scope (r); + /* Do this again now that LAMBDA_EXPR_EXTRA_SCOPE is set. */ determine_visibility (TYPE_NAME (type)); @@ -25571,9 +25571,6 @@ instantiate_body (tree pattern, tree args, tree d, bool nested_p) if (VAR_P (d)) { - tree init; - bool const_init = false; - /* Clear out DECL_RTL; whatever was there before may not be right since we've reset the type of the declaration. */ SET_DECL_RTL (d, NULL); @@ -25583,7 +25580,8 @@ instantiate_body (tree pattern, tree args, tree d, bool nested_p) regenerate_decl_from_template so we don't need to push/pop_access_scope again here. Pull it out so that cp_finish_decl can process it. */ - init = DECL_INITIAL (d); + bool const_init = false; + tree init = DECL_INITIAL (d); DECL_INITIAL (d) = NULL_TREE; DECL_INITIALIZED_P (d) = 0;