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 E61C8385E02E for ; Wed, 14 Feb 2024 13:53:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E61C8385E02E 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 E61C8385E02E 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=1707918799; cv=none; b=NTCrLGPmNhql7svaUYVbvcL1ro//lQvTGOHfOcVOykmcjtreuuTIYq2WoEyuykBkoG0TSsXzSYvKPGZ7ag2yqcRD6Bm3LmiQFoBwpwJL/2+yt4Ye3uEfEGfDS9Em/tFD3tRdNlkuto3+/Zi+iDESCRrKBAVXgHFSlpaF9NvUDzc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707918799; c=relaxed/simple; bh=b5gbOuP2rgaQEttbxLaF1X6tu0EZcdok1DS+UJ1MvIs=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=aJ+GSwAPIzOuYXfkGi45j1si9eV9IDeFfa1S+doExexyjUnwgOYiD8eWqFYydtz3btgFSwEBfukwG2AFXGD+Kw7Uqx3eWY9CDAuWlSz/ENdieJJ800g0u4JXJCBzPOBcWizZpGP5hYErGQIU+i017u3NNkL2qFaSdY12N0SijGw= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1707918797; 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=PAradzGz5ygAMhqKHLxq+9L2iadyKW5zvguEmWehKyY=; b=gHsDiezKZlQn/BKDnrddN0mrvIQmZHtHCKCrwG7vnHZLyjYjwmK9maghFUiH9WUEtq4rLU iwdqRMsRK4RUMrbNcjf4ZH1R8px9sx0m4/qYjeCsjY1FvI085VC+qNjV8KQ4eAaRGP2mYH Thbseva/qS8s95UKzIIkGQPbuQIBBOA= Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-108-3T_rOcnyOGOiTIxbcTuJlA-1; Wed, 14 Feb 2024 08:53:14 -0500 X-MC-Unique: 3T_rOcnyOGOiTIxbcTuJlA-1 Received: by mail-qv1-f70.google.com with SMTP id 6a1803df08f44-68f0167d7cdso6890756d6.2 for ; Wed, 14 Feb 2024 05:53:14 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707918793; x=1708523593; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=PAradzGz5ygAMhqKHLxq+9L2iadyKW5zvguEmWehKyY=; b=weVUnKAc/YHhqTHBHUCJWpYWxrFHx1UTatw+WfhRluSV15Si83DjceWayX+axAoquT VOQQnv+mUd2UGOuJuNxiz6o+U22NZ49J0faXFpdjXPit4hs/b4S1+YJiCUnXkWGh5s4f 2Ypzix9vB8WgFj+gCFanwAfkyuoYU8TFVY1qwIbpDA0yt/qo5CHDaAYFrG9J5AjsNDSx Kv9G7mx9JLswTTf4XhZ3kUqfa/qBOIrwjG6o3veRFa36ugYoBOx2RmMT3eliaPGkifP3 BigsVV0yFHB0PPaLeTJTDzKzLcvjWJEfdYGvtz27smJck28aKg/6BWWRTTTVXPZXOc7e olnQ== X-Gm-Message-State: AOJu0Yw5FqVZqcwq7d1Q36+K8UtMogojoVbZAUJLEnmn9iIxPbdHE0O7 ahlUTWEcNh+1l2wFvg1k/XwFoiRQSEt/V1YjhoI+jKO0wccfU3hRhG4IvfmeIlnrJcpaC7L/L1q HUOpdnqaSHYET5ANlNd+wUD8kDyr/aJ9rYQubFyAzqTZAc4y1XbyPNRqtWTEI8c8= X-Received: by 2002:a05:6214:f22:b0:68c:9ac4:59b5 with SMTP id iw2-20020a0562140f2200b0068c9ac459b5mr2878717qvb.53.1707918793238; Wed, 14 Feb 2024 05:53:13 -0800 (PST) X-Google-Smtp-Source: AGHT+IHkNOQ40qqOHAhEDIDvNCQKjTSLgTPhqFI9uxo4G/6eysPnmQpoKF1+dGi9Mtacgb/k2R13FQ== X-Received: by 2002:a05:6214:f22:b0:68c:9ac4:59b5 with SMTP id iw2-20020a0562140f2200b0068c9ac459b5mr2878698qvb.53.1707918792868; Wed, 14 Feb 2024 05:53:12 -0800 (PST) Received: from [192.168.1.130] (130-44-146-16.s12558.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.146.16]) by smtp.gmail.com with ESMTPSA id ng3-20020a0562143bc300b0068c4f1da09csm2272827qvb.120.2024.02.14.05.53.11 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 14 Feb 2024 05:53:12 -0800 (PST) Message-ID: Date: Wed, 14 Feb 2024 08:53:11 -0500 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] c++: implicitly_declare_fn and access checks [PR113908] To: Patrick Palka Cc: gcc-patches@gcc.gnu.org References: <20240213164907.3648858-1-ppalka@redhat.com> <6477dc34-e936-40cc-b3f6-31d1e885a201@redhat.com> <4b01fcb6-9a97-3d30-c00e-58d04da73448@idea> From: Jason Merrill In-Reply-To: <4b01fcb6-9a97-3d30-c00e-58d04da73448@idea> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit 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_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 2/14/24 08:46, Patrick Palka wrote: > 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? OK. > -- >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 + bool = __is_implicitly_default_constructible<_Tp>()> > + tuple(); > +}; > + > +struct DBusStruct { > +private: > + tuple data_; > +}; > + > +struct IBusService { > + int m = [] { DBusStruct{}; return 42; }(); > +};