From patchwork Tue Mar 21 15:08:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 1759494 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.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=) Authentication-Results: legolas.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=uEq/ZJKN; dkim-atps=neutral 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 ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Pgw4C3qwNz247F for ; Wed, 22 Mar 2023 02:09:14 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 430BC3850854 for ; Tue, 21 Mar 2023 15:09:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 430BC3850854 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1679411352; bh=7FeeBC4r8vjNabsH2/N5jQwtIwlbI2kTER2u/XkFWiE=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=uEq/ZJKNgF6VB6So/1sjmLABkVTHlK9zkYOwpTtWDB7CyugOIZ2APWiNk0Zc1d+Oe qqlqpPcg+5BkWV3wbJ800RPHiBl6ttM2jSW/Uv4x84nQnHYMR/vVyiK9F1RhW6hyQY Xm8VuQYFwEh333RG+TStcTClATU2xdlQrJNSYlKA= 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 590A53858022 for ; Tue, 21 Mar 2023 15:08:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 590A53858022 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-427-39qpCj1uNHKWoXDeOcJyew-1; Tue, 21 Mar 2023 11:08:50 -0400 X-MC-Unique: 39qpCj1uNHKWoXDeOcJyew-1 Received: by mail-qv1-f71.google.com with SMTP id px9-20020a056214050900b005d510cdfc41so489598qvb.7 for ; Tue, 21 Mar 2023 08:08:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679411329; 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=7FeeBC4r8vjNabsH2/N5jQwtIwlbI2kTER2u/XkFWiE=; b=uQSxeyZewlFZdjVuXFWXhcMGYL5ybnBS61EVlucQ9aywPeanuwANGsdOTpKKK72+wt wL9O+qLpXn6y88mikMPfErgJCh6kIHN6D/VCwIeKZX4hiemcEU49ODBXGsD6Dtu7dweK qSf5w7dco6hsTtiZn7SNLWvErdnVAwPJdFvkv1F3JA6kctkHvAsC1/A+UTKoDX9QuZEu zIiMYgZ3xnG9spRPP7uyYxRe6Hs7nQDutWbPdxtlnOn2234GUf0RWgQOO256PghToc1F K+f4VGtGm2WBaRrcOUgPngm++BqmPgn7DY5FmRPKUm7HddamE/CCUDINGVb7Daybo+GA /pbg== X-Gm-Message-State: AO0yUKWhQelXqcxs4YAYrEft5uXkxzRUsabjj5/b5GTV4LQB16re6oGa B+kNF1LN2xf9YassCoalGf0l+BOxUnO/ScLYUurL8z2GtOOLcWlWYoGjbYqqXW5m7gb/edtQIR6 /kE8r5wcTrV8D5gfAaP0SWzFDFSrK+B7kgTuaouq4aOtuVaGFqOW/p8Q3Hi1B6auSee7g6u53vw == X-Received: by 2002:a05:622a:246:b0:3d7:b045:d38 with SMTP id c6-20020a05622a024600b003d7b0450d38mr230957qtx.35.1679411328945; Tue, 21 Mar 2023 08:08:48 -0700 (PDT) X-Google-Smtp-Source: AK7set9FFCg52p9WaAdgCBK7s6QX1/1dxqc+oXVxG+Hj9rgaPcwI8Z/52K28kUN11dsf5ul9AZ+PnA== X-Received: by 2002:a05:622a:246:b0:3d7:b045:d38 with SMTP id c6-20020a05622a024600b003d7b0450d38mr230914qtx.35.1679411328484; Tue, 21 Mar 2023 08:08:48 -0700 (PDT) Received: from jason.cygnus.csb (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 b13-20020ac8540d000000b003d2d815825fsm1195793qtq.40.2023.03.21.08.08.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Mar 2023 08:08:47 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [pushed] c++: DMI in template with virtual base [PR106890] Date: Tue, 21 Mar 2023 11:08:44 -0400 Message-Id: <20230321150844.1983244-1-jason@redhat.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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_H2, 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 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" Tested x86_64-pc-linux-gnu, applying to trunk. -- 8< -- When parsing a default member init we just build a CONVERT_EXPR for converting to a virtual base, and then expand that into the more complex form when we actually use the DMI in a constructor. But that wasn't working for the template case where we are considering the conversion at the point that the constructor needs the DMI instantiation, so it seemed like we were in a constructor already. And then when the other constructor tries to reuse the instantiation, it sees uses of the first constructor's parameters, and dies. So ensure that we get the CONVERT_EXPR in this case, too. PR c++/106890 gcc/cp/ChangeLog: * init.cc (maybe_instantiate_nsdmi_init): Don't leave current_function_decl set to a constructor. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/nsdmi-template25.C: New test. --- gcc/cp/init.cc | 14 ++++++++++++++ gcc/testsuite/g++.dg/cpp0x/nsdmi-template25.C | 18 ++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 gcc/testsuite/g++.dg/cpp0x/nsdmi-template25.C base-commit: 0a846340b99675d57fc2f2923a0412134eed09d3 diff --git a/gcc/cp/init.cc b/gcc/cp/init.cc index 90302372340..c5a55dae563 100644 --- a/gcc/cp/init.cc +++ b/gcc/cp/init.cc @@ -613,6 +613,18 @@ maybe_instantiate_nsdmi_init (tree member, tsubst_flags_t complain) pushed = true; } + /* If we didn't push_to_top_level, still step out of constructor + scope so build_base_path doesn't try to use its __in_chrg. */ + tree cfd = current_function_decl; + auto cbl = current_binding_level; + if (at_function_scope_p ()) + { + current_function_decl + = decl_function_context (current_function_decl); + while (current_binding_level->kind != sk_class) + current_binding_level = current_binding_level->level_chain; + } + inject_this_parameter (ctx, TYPE_UNQUALIFIED); start_lambda_scope (member); @@ -629,6 +641,8 @@ maybe_instantiate_nsdmi_init (tree member, tsubst_flags_t complain) if (init != error_mark_node) hash_map_safe_put (nsdmi_inst, member, init); + current_function_decl = cfd; + current_binding_level = cbl; if (pushed) { pop_deferring_access_checks (); diff --git a/gcc/testsuite/g++.dg/cpp0x/nsdmi-template25.C b/gcc/testsuite/g++.dg/cpp0x/nsdmi-template25.C new file mode 100644 index 00000000000..368e745540e --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/nsdmi-template25.C @@ -0,0 +1,18 @@ +// PR c++/106890 +// { dg-do compile { target c++11 } } + +struct A +{ + int p; +}; + +template +struct B : virtual public A +{ + B() { } + B(int) { } + + int k = this->p; +}; + +template struct B;