From patchwork Fri Feb 16 21:33:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 85910 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D102D385782D for ; Fri, 16 Feb 2024 21:34:23 +0000 (GMT) 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 54B31385782D for ; Fri, 16 Feb 2024 21:33:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 54B31385782D 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 54B31385782D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708119238; cv=none; b=uHZdhEM43ZQ6P2lMriDfZgibK+F89arW5IdtTWWkw6tudwAafxmby9LbQn0ztjNNck7Wn2u31jsM6AWnLnFxKOUzlkuN36nEo5IP+aVA/Ty/tKMCdFZNPNOOnBsKlf+K4ukQzjXD9vQXJv9RshdFLTqtc2dOff/IfOVRTXhpcVM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708119238; c=relaxed/simple; bh=Y/NC8vcT7uHea7fFEcTo2mD4g3XqNzytMJsb+Xb8xEo=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=Xfw6Syzp5QzO+gfTXwYam9ZYfn0j8QIrfFOZXlphzAFlA7GFiTE3tM/E6TnljC6iJN+r9qVT0J+wUDTNDy1MQMy8FdmGMbu7bXNS14O5fxTap1hde0nYwslurxFJINXfpB4lAzjd+hjVIJI/Ld91TkcBBaimuUJ3K6Ue59MpWo8= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1708119228; 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=lR6mrL2LpOEHVyTPamE/5gHz7P3jA82388TpiFlNL0s=; b=YJ43tljtzgWn1hU2w6YlTH/iVdCwdnSE9KS2HmO3Kvpplu2Qa0om2QSOtNM9/2NkflY6yA QSuRDjRTIe8CZUjZRqMCqlcAP5kxrxuNF/V7zkOn/vP4hLAB7dCErjbDP7tPdmOSpGN2gr IKNdvaQWFPwwGTXvLZQ7IG8eLQGR7+Q= 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-691-DmBQV8-JMLagthnX26M4rg-1; Fri, 16 Feb 2024 16:33:46 -0500 X-MC-Unique: DmBQV8-JMLagthnX26M4rg-1 Received: by mail-qt1-f199.google.com with SMTP id d75a77b69052e-4297db4eba1so12446641cf.2 for ; Fri, 16 Feb 2024 13:33:46 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708119226; x=1708724026; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lR6mrL2LpOEHVyTPamE/5gHz7P3jA82388TpiFlNL0s=; b=Kq53Tw8UkXLyuiPaRoXoGrZ2NLAL+WZnFHgPisRWLSptYCNwjeJHfD8B4WA3N/HDmX g8CfrRSKE0se96gH6yT+4rEe/NO9QMX6oxbo8mf2hhcbe4q8iokFn+GPD496Kz8WP9g0 tgWMDOUx/18yA3sDhdFpIbsrXa8mzCfE+qF3Yy7Nrx2CAYL6KBV4d2hMnrH/yRRAmsAU FwDM+eW9ZTAKvvhtkq9rlWLnlXw+ANMSfDq4egdXKkThqb83ekh8JMnK1MXsn/x+MCLf udjz7yOlQSKUPlYnnycTkT6xVBWxTAsnU8DG4KrE354jUI0mduqqlfE7gKTHpEcq9FM6 gsgA== X-Gm-Message-State: AOJu0YzCQqICE+qfJtx5LwVjkgP1bdTCqXM4TedFE39Tfm3r7Ni0I/fm W5KA9SuEkW5/OKYJbjpvqM/6ejvUMHeo682X5q4fXaFD8xLCLPN/trIdpYCjI5JbZsS7ofybBkr soYeuzFUcUl2cmzfCoSSwEmtZuCzIgrLWJzGEV4+LWhz/kZVDYoJlxF7uP0BTvWM= X-Received: by 2002:a05:622a:291:b0:42d:c0be:ddff with SMTP id z17-20020a05622a029100b0042dc0beddffmr6816246qtw.22.1708119225915; Fri, 16 Feb 2024 13:33:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IHEJm6/NiB4Je8ZxEv3GYDY3ZxEhQti282JKEBkCqa/CIeTH6xn6uCWNsWwYRboui9YuWh8Ig== X-Received: by 2002:a05:622a:291:b0:42d:c0be:ddff with SMTP id z17-20020a05622a029100b0042dc0beddffmr6816233qtw.22.1708119225548; Fri, 16 Feb 2024 13:33:45 -0800 (PST) Received: from redhat.com (2603-7000-9500-34a5-0000-0000-0000-1db4.res6.spectrum.com. [2603:7000:9500:34a5::1db4]) by smtp.gmail.com with ESMTPSA id e21-20020ac845d5000000b0042defac6fcesm76265qto.51.2024.02.16.13.33.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 13:33:45 -0800 (PST) Date: Fri, 16 Feb 2024 16:33:43 -0500 From: Marek Polacek To: Jason Merrill Cc: GCC Patches Subject: [PATCH v2] c++: wrong looser excep spec for dep noexcept [PR113158] Message-ID: References: <20240215221742.646761-1-polacek@redhat.com> <6db4134a-3a48-4ed4-bbbf-914a4ea66f3d@redhat.com> MIME-Version: 1.0 In-Reply-To: <6db4134a-3a48-4ed4-bbbf-914a4ea66f3d@redhat.com> User-Agent: Mutt/2.2.12 (2023-09-09) X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-12.4 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, 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org On Fri, Feb 16, 2024 at 03:58:02PM -0500, Jason Merrill wrote: > On 2/15/24 17:17, Marek Polacek wrote: > > Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? > > > > By the ??? below I mean that maybe_instantiate_noexcept could return > > a tristate, and then maybe_check_overriding_exception_spec could check > > > > if (maybe_instantiate_noexcept ().is_unknown ()) > > return true; > > > > and we don't have to add any new checks to maybe_check_o_e_spec. > > > > -- >8 -- > > Here we find ourselves in maybe_check_overriding_exception_spec in > > a template context where we can't instantiate a dependent noexcept. > > That's OK, but we have to defer the checking otherwise we give wrong > > errors. > > > > PR c++/113158 > > > > gcc/cp/ChangeLog: > > > > * search.cc (maybe_check_overriding_exception_spec): Defer checking > > when a noexcept couldn't be instantiated. > > > > gcc/testsuite/ChangeLog: > > > > * g++.dg/cpp0x/noexcept83.C: New test. > > --- > > gcc/cp/search.cc | 7 +++++ > > gcc/testsuite/g++.dg/cpp0x/noexcept83.C | 37 +++++++++++++++++++++++++ > > 2 files changed, 44 insertions(+) > > create mode 100644 gcc/testsuite/g++.dg/cpp0x/noexcept83.C > > > > diff --git a/gcc/cp/search.cc b/gcc/cp/search.cc > > index c948839dc53..73d254d6b84 100644 > > --- a/gcc/cp/search.cc > > +++ b/gcc/cp/search.cc > > @@ -1975,6 +1975,13 @@ maybe_check_overriding_exception_spec (tree overrider, tree basefn) > > || UNPARSED_NOEXCEPT_SPEC_P (over_throw)) > > return true; > > + /* We also have to defer checking when we're in a template and couldn't > > + instantiate the noexcept yet. > > + ??? maybe_instantiate_noexcept already checked these. Use tristate? */ > > + if (type_dependent_expression_p (base_throw) > > + || type_dependent_expression_p (over_throw)) > > I think we also want to avoid comparing value-dependent expressions, but > actually checking either one seems like more work than needed here; I'd > think we want to defer in a template if the specifiers aren't both exactly > true or false. Yeah, that'll work too. So like this? Bootstrap/regtest running; dg.exp passed. FWIW, the new check only triggered on the new test. Thanks, -- >8 -- Here we find ourselves in maybe_check_overriding_exception_spec in a template context where we can't instantiate a dependent noexcept. That's OK, but we have to defer the checking otherwise we give wrong errors. PR c++/113158 gcc/cp/ChangeLog: * search.cc (maybe_check_overriding_exception_spec): Defer checking when a noexcept couldn't be instantiated & evaluated to false/true. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/noexcept83.C: New test. --- gcc/cp/search.cc | 11 ++++++++ gcc/testsuite/g++.dg/cpp0x/noexcept83.C | 37 +++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 gcc/testsuite/g++.dg/cpp0x/noexcept83.C base-commit: 40b8d7b73ad2ce498758c1d9bd38ebdbc26b918b diff --git a/gcc/cp/search.cc b/gcc/cp/search.cc index c948839dc53..554ba71f4a7 100644 --- a/gcc/cp/search.cc +++ b/gcc/cp/search.cc @@ -1975,6 +1975,17 @@ maybe_check_overriding_exception_spec (tree overrider, tree basefn) || UNPARSED_NOEXCEPT_SPEC_P (over_throw)) return true; + /* We also have to defer checking when we're in a template and couldn't + instantiate & evaluate the noexcept to true/false. */ + if (processing_template_decl) + if ((base_throw + && (base_throw != noexcept_true_spec + || base_throw != noexcept_false_spec)) + || (over_throw + && (over_throw != noexcept_true_spec + || over_throw != noexcept_false_spec))) + return true; + if (!comp_except_specs (base_throw, over_throw, ce_derived)) { auto_diagnostic_group d; diff --git a/gcc/testsuite/g++.dg/cpp0x/noexcept83.C b/gcc/testsuite/g++.dg/cpp0x/noexcept83.C new file mode 100644 index 00000000000..47832bbb44d --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/noexcept83.C @@ -0,0 +1,37 @@ +// PR c++/113158 +// { dg-do compile { target c++11 } } + +template +struct V { + static constexpr bool t = false; +}; +struct base { + virtual int f() = 0; +}; + +template +struct derived : base { + int f() noexcept(V::t) override; +}; + +struct base2 { + virtual int f() noexcept = 0; +}; + +template +struct W { + static constexpr bool t = B; +}; + +template +struct derived2 : base2 { + int f() noexcept(W::t) override; // { dg-error "looser exception specification" } +}; + +void +g () +{ + derived d1; + derived2 d2; // { dg-message "required from here" } + derived2 d3; +}