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 EBB6D385DC0F for ; Wed, 14 Feb 2024 13:46:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EBB6D385DC0F 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 EBB6D385DC0F 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=1707918377; cv=none; b=gAld6K8eoQrPjYDMH0GsBfGtAuvkek99IhkvvYtFbMRPRLyY/LgZWqRYAE9XtweH8VJnJrjYic1iEycR5iHo7n64r5KGLQL0eaNH5yzapfNNH0MPP5vaIjuatRrx/WIm0EZwJjkkpOpHJRbqaGh7ktdU0/xq/v1bDs2OVkmdaO8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707918377; c=relaxed/simple; bh=eAEQKa3qdO3n9jShbp5ddDRIftsiQSnmQz1ZeVfbWI4=; h=DKIM-Signature:From:Date:To:Subject:Message-ID:MIME-Version; b=HQcZpOg4UeTg7O/915xD8W89X9CyAQ2w5J7v4xrMvvDuIvCWisjXFHqGQ2k6Kft61+MJGDkainF+q9rk1jTAQsLqHg5O1hCfL5Fflv6K47x82mQV2Pyjd1DpXv+UdKf2AN+ugv6quXyVcqC1oRn4bf4AMozL+FabQbQOnbcpsKI= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1707918375; 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=YmM3bl1lrydxQI59oS9CVaxF0G6ZHRE6CM4848yG6Zs=; b=fPsCXkGpeavty1Ee44ee8yYsOH/6lBc2VNlnyW6RYgLbY8mA7s6J/cThXjmn+XYNqttcYv pyAIeGaaLh4ZTyRZncVsndLl/kQsju6UkbsF7DpCELBfybZn6GRYEQrR06Pf0bAp9MoVz6 vuuIIdk8/KCbMURoh4gowzeUi8kXTaI= Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-328-KCTh_3LNM0iyKvTiRaymOQ-1; Wed, 14 Feb 2024 08:46:14 -0500 X-MC-Unique: KCTh_3LNM0iyKvTiRaymOQ-1 Received: by mail-qt1-f199.google.com with SMTP id d75a77b69052e-42c70b8e409so15623851cf.0 for ; Wed, 14 Feb 2024 05:46:14 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707918374; x=1708523174; 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=YmM3bl1lrydxQI59oS9CVaxF0G6ZHRE6CM4848yG6Zs=; b=NlTBEoVsRpB50KROIczZVZeY4D41G7JImRo0SyxEslDf3iePeR+Srl3K04Sg5yiZal 0z+ikfUpW6Nh+MLM3yr+OyRCPrSYXLqvDfyti2vGvDSR7wDm2Liq/4c/PYn3iqtAIKiJ 3AyOTvDKgZTKHy+RsZxyu5ieqBxXibRUl9DCjKsbAs1GzlYKgL22rDrEE6ajr3rn+PDN r+ySvz+9ZPSx3Argk+8HOIbffoZMLICiyT9yQONfwvdf0PsOvqbZV6CKSveifJfIHI7Y Q48tmgd65J3F63+eKpNph1ECTHnsId7BPUy+bPyEtImrLLHXyIq2hrwG1ThbC5qe05Sp v6vA== X-Forwarded-Encrypted: i=1; AJvYcCXTQGAoxtNGJW6FLpuNYKMUO2PYmZkHvh/ZA1M4UFdeFfEt1FECEP2rrIIllE+9WPQNQdT5A7TtcaI5erP50E/eAL0sXuNwJA== X-Gm-Message-State: AOJu0YyQN4hk6bqSqbRzKqtPGhcRUxT6ZFAI2fAvpsVAjbeJ6w9+4Wc2 JAnLAmuAxK86QfhA5wHiqStUc8BBtvcI8olP/IBgA6pfHQqKHyQUkmq0m5eV9cTg2X3vLj+Kbsa QwGsSvU62kwG/T9KecPu8pcvblVh9dF2q09J3r8r/ChzETvuKjBX4IUI= X-Received: by 2002:ac8:580a:0:b0:42d:b7ff:22fc with SMTP id g10-20020ac8580a000000b0042db7ff22fcmr2994977qtg.11.1707918373771; Wed, 14 Feb 2024 05:46:13 -0800 (PST) X-Google-Smtp-Source: AGHT+IGEaTFz1oEv2C33IBwusV5DgLJB0YmhHKM6M3Bp7rMslESjSMYQ067HtleRDeDHDFo/TtqxZA== X-Received: by 2002:ac8:580a:0:b0:42d:b7ff:22fc with SMTP id g10-20020ac8580a000000b0042db7ff22fcmr2994956qtg.11.1707918373503; Wed, 14 Feb 2024 05:46:13 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCWjFJ1fTfIhv7gg7MXcsoCSE9GNk4R/nlvOTGxoJCVC7efJdhQ5NSqKu4SyFwjDJi1eYdmy/iSP35P5hS215GqwXShuMyftTg== Received: from [192.168.1.130] (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id e13-20020ac84b4d000000b0042c524de19asm2033776qts.58.2024.02.14.05.46.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Feb 2024 05:46:12 -0800 (PST) From: Patrick Palka X-Google-Original-From: Patrick Palka Date: Wed, 14 Feb 2024 08:46:12 -0500 (EST) To: Jason Merrill cc: Patrick Palka , gcc-patches@gcc.gnu.org Subject: Re: [PATCH] c++: implicitly_declare_fn and access checks [PR113908] In-Reply-To: <6477dc34-e936-40cc-b3f6-31d1e885a201@redhat.com> Message-ID: <4b01fcb6-9a97-3d30-c00e-58d04da73448@idea> References: <20240213164907.3648858-1-ppalka@redhat.com> <6477dc34-e936-40cc-b3f6-31d1e885a201@redhat.com> 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=-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_H4,RCVD_IN_MSPIKE_WL,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: On Tue, 13 Feb 2024, Jason Merrill wrote: > On 2/13/24 11:49, Patrick Palka wrote: > > Bootstrapped and regtested on x86_64-pc-linux-gnu, are one of > > both of these fixes OK for trunk? > > > > -- >8 -- > > > > Here during ahead of time checking of the non-dependent new-expr we > > synthesize B's copy constructor, which should be defined as deleted > > due to A's inaccessible copy constructor. But enforce_access incorrectly > > decides to defer the (silent) access check for A::A(const A&) during > > synthesization since current_template_parms is still set (before r14-557 > > it checked processing_template_decl which got cleared from > > implicitly_declare_fn), which leads to the access check leaking out to > > the template context that needed the synthesization. > > > > This patch narrowly fixes this regression in two sufficient ways: > > > > 1. Clear current_template_parms alongside processing_template_decl > > in implicitly_declare_fn so that it's more independent of context. > > Hmm, perhaps it or synthesized_method_walk should use maybe_push_to_top_level? That works nicely, and also fixes the other regression PR113332. There the lambda context triggering synthesization of a default ctor was causing maybe_dummy_object to misbehave during overload resolution of one of its member's default ctors, and now synthesization is context independent. > > > 2. Don't defer a silent access check when in a template context, > > since such deferred checks will be replayed noisily at instantiation > > time which may not be what the caller intended. > > True, but returning a possibly incorrect 'false' is probably also not what the > caller intended. It would be better to see that we never call enforce_access > with tf_none in a template. If that's not feasible, I think we should still > conservatively return true. Makes sense, I can experiment with that enforce_access access change as a follow-up. Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for trunk? -- >8 -- Subject: [PATCH] c++: synthesized_method_walk context independence [PR113908] PR c++/113908 PR c++/113332 gcc/cp/ChangeLog: * method.cc (synthesized_method_walk): Use maybe_push_to_top_level. gcc/testsuite/ChangeLog: * g++.dg/template/non-dependent31.C: New test. * g++.dg/template/non-dependent32.C: New test. --- gcc/cp/method.cc | 2 ++ .../g++.dg/template/non-dependent31.C | 18 +++++++++++++++++ .../g++.dg/template/non-dependent32.C | 20 +++++++++++++++++++ 3 files changed, 40 insertions(+) create mode 100644 gcc/testsuite/g++.dg/template/non-dependent31.C create mode 100644 gcc/testsuite/g++.dg/template/non-dependent32.C diff --git a/gcc/cp/method.cc b/gcc/cp/method.cc index 957496d3e18..98c10e6a8b5 100644 --- a/gcc/cp/method.cc +++ b/gcc/cp/method.cc @@ -2760,6 +2760,7 @@ synthesized_method_walk (tree ctype, special_function_kind sfk, bool const_p, return; } + bool push_to_top = maybe_push_to_top_level (TYPE_NAME (ctype)); ++cp_unevaluated_operand; ++c_inhibit_evaluation_warnings; push_deferring_access_checks (dk_no_deferred); @@ -2857,6 +2858,7 @@ synthesized_method_walk (tree ctype, special_function_kind sfk, bool const_p, pop_deferring_access_checks (); --cp_unevaluated_operand; --c_inhibit_evaluation_warnings; + maybe_pop_from_top_level (push_to_top); } /* DECL is a defaulted function whose exception specification is now diff --git a/gcc/testsuite/g++.dg/template/non-dependent31.C b/gcc/testsuite/g++.dg/template/non-dependent31.C new file mode 100644 index 00000000000..3fa68f40fe1 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/non-dependent31.C @@ -0,0 +1,18 @@ +// PR c++/113908 +// { dg-do compile { target c++11 } } + +struct A { + A(); +private: + A(const A&); +}; + +struct B { + A a; + + template + static void f() { new B(); } +}; + +template void B::f(); +static_assert(!__is_constructible(B, const B&), ""); diff --git a/gcc/testsuite/g++.dg/template/non-dependent32.C b/gcc/testsuite/g++.dg/template/non-dependent32.C new file mode 100644 index 00000000000..246654c5b50 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/non-dependent32.C @@ -0,0 +1,20 @@ +// PR c++/113332 +// { dg-do compile { target c++11 } } + +struct tuple { + template + static constexpr bool __is_implicitly_default_constructible() { return true; } + + template()> + tuple(); +}; + +struct DBusStruct { +private: + tuple data_; +}; + +struct IBusService { + int m = [] { DBusStruct{}; return 42; }(); +}; -- 2.44.0.rc0.46.g2996f11c1d