From patchwork Sat Sep 7 22:54:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 1982175 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=BQEJwHBV; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.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 ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4X1T2t1KhVz1y1f for ; Sun, 8 Sep 2024 08:55:32 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7B1C6385C6C1 for ; Sat, 7 Sep 2024 22:55:30 +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 ESMTP id 9D2F63858C33 for ; Sat, 7 Sep 2024 22:55:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9D2F63858C33 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 9D2F63858C33 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=1725749712; cv=none; b=l/p+fEWqmiC7BYw2nAD7gXISLLLYRpowzzoQu0k0G0y6MFG1Y3UaqYvGhGMergPtDWQWplq3v7/V5mnVIJ2HgSm2nYe+K/XGKBYjFz4oh2W+ofHEX/kpFyOTJsFJSNeBjUmkxX5oy2ZHV1qWpXKmlXsl1G6aGw7sxwde4qurIRo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1725749712; c=relaxed/simple; bh=Kt14pZjV+Wa/PigUr+v1Pm+IHmTdpkFCFcI0VgN/h0c=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=vpFV7BoWS0mxv/7Cmyf0DQJOm8LZmEwzb1j+ybKH8cyGFHG+148PgMYAnOZnjs33JGSjyz4Yj69JLNc6DHvRUW/APh9USSJ41nowMF+NRlBW3lqX2jW9ew/g2JSsgAeUaB5XrA9102up/qMby5/cNBiC+gC4y6BGixSX7nkVVOU= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1725749710; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=crdwfnJMt3T/+4qb2Ecb5yDd04r4l6boD1z4ShoI2B4=; b=BQEJwHBVGh2X/b3fEpHPwPfKZlpqq1bVG0k5lGOX7CoFpyMAUI9ZFfQSFXO+1ASwynH0Ch DIvIfoN3ruiZ1UwXiozveRn8H9vE4o97VB9WqF7YMk2kCTsLk1+LgWRyg6hpIHfkxIh/0x 66hh7I01mMGJBn+UUC+9V4eEErVPGoA= Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-389-jmLAn7C6NZG7HZtNivpynA-1; Sat, 07 Sep 2024 18:55:08 -0400 X-MC-Unique: jmLAn7C6NZG7HZtNivpynA-1 Received: by mail-qv1-f69.google.com with SMTP id 6a1803df08f44-6c3554020afso44311096d6.3 for ; Sat, 07 Sep 2024 15:55:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725749708; x=1726354508; 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=crdwfnJMt3T/+4qb2Ecb5yDd04r4l6boD1z4ShoI2B4=; b=UQQh2nxoDMjfp6ndSb6yAoYmszPQnAp7xyTXuV3VIYEDkAXYFZcUNWonPe84ESVkMg GMjLYJ2kQiwjpq2pfNGKDtmjpV6Vkjy4vDCyYbvjIOW9uk17Q69kq5jfPXoLZ06DGkz9 6+23kl51pcqHjwUWGULeELbH6XejYGd0HWtHHlNwXmZRAzoS5UvfcAslpDYByEO8cOgv 5Q4mT9JKUTdw8R/I04kESMaWT0MGm4schgA++8PbuXDiykXs1ayLDUm+bdlskJwlH25d rNhiimtZL+EDtzl/Xoolx4VAlxouracrj5+A1ojkfYNzmexPwadqCJuKRUYcj1YJ7JjT xVPA== X-Gm-Message-State: AOJu0YzqKIHcsNqu5AESJjHxaSZmOocsFHRC77ZFFJnKbG+DaNp8wJ/x dATMuJ8Q5QgUIqQC6ooYk+7sxL/LgMAlVrtHTFuDLyycppt5A/FKOKA8zwA2CD001HFEAP6QSRo MtBF6SfHt2Z5xgdicGuakYZsa7CsZdfnNS79AMVIILBMM5pfTyb2PMto6HDXstfaSltCfaRdF7+ XyaPbVHIAEoCnGxNQFzADTZ8RKdCCgQZ23pvk= X-Received: by 2002:a05:6214:4b12:b0:6c3:5833:260f with SMTP id 6a1803df08f44-6c532b2c8d3mr59527496d6.39.1725749707838; Sat, 07 Sep 2024 15:55:07 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFpiVPIsMlfsnJBteygDc1UIkpf7g6nMCHeadWLxkC5bpTBkMfHUx7pdsNERQMgL9EDvc+mMw== X-Received: by 2002:a05:6214:4b12:b0:6c3:5833:260f with SMTP id 6a1803df08f44-6c532b2c8d3mr59527156d6.39.1725749707270; Sat, 07 Sep 2024 15:55:07 -0700 (PDT) Received: from jason-thinkpadp1gen4i.rmtusma.csb (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 6a1803df08f44-6c5343294cbsm8270866d6.12.2024.09.07.15.55.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Sep 2024 15:55:06 -0700 (PDT) From: Jason Merrill To: gcc-patches@gcc.gnu.org Subject: [pushed] c++: exception spec and stdlib specialization Date: Sat, 7 Sep 2024 18:54:51 -0400 Message-ID: <20240907225505.3414902-1-jason@redhat.com> X-Mailer: git-send-email 2.46.0 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.3 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_H3, RCVD_IN_MSPIKE_WL, 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org Tested x86_64-pc-linux-gnu, applying to trunk. -- 8< -- We were silently accepting the pr65923.C specialization of std::swap with the wrong exception specification; it should be declared noexcept. Let's limit ignoring mismatch with system headers to extern "C" functions so we get a diagnostic for the C++ library. In the case of an omitted exception-specification, let's also lower the error to a pedwarn, and copy the missing spec over, to avoid a hard break for code that accidentally relied on the old behavior. ...except extern "C" functions keep the new spec, to avoid breaking dubious code like noexcept-type19.C. gcc/cp/ChangeLog: * decl.cc (check_redeclaration_exception_specification): Remove OPT_Wsystem_headers from pedwarn when the old declaration is in a system header. Also check std namespace. gcc/testsuite/ChangeLog: * g++.dg/diagnostic/pr65923.C: Add noexcept. * g++.dg/cpp1z/aligned-new3.C: Expect pedwarn. * g++.dg/cpp1z/noexcept-type19.C: Add comment. --- gcc/cp/decl.cc | 20 ++++++++++++++++++-- gcc/testsuite/g++.dg/cpp1z/aligned-new3.C | 3 ++- gcc/testsuite/g++.dg/cpp1z/noexcept-type19.C | 2 +- gcc/testsuite/g++.dg/diagnostic/pr65923.C | 2 +- 4 files changed, 22 insertions(+), 5 deletions(-) base-commit: 69d82c1dccb3583464228eb5449e29918eeb4ee4 diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc index f0271308d92..2190ede745b 100644 --- a/gcc/cp/decl.cc +++ b/gcc/cp/decl.cc @@ -1395,17 +1395,33 @@ check_redeclaration_exception_specification (tree new_decl, bool complained = true; location_t new_loc = DECL_SOURCE_LOCATION (new_decl); auto_diagnostic_group d; - if (DECL_IN_SYSTEM_HEADER (old_decl)) + + if (DECL_IN_SYSTEM_HEADER (old_decl) && DECL_EXTERN_C_P (old_decl)) + /* Don't fuss about the C library; the C library functions are not + specified to have exception specifications (just behave as if they + have them), but some implementations include them. */ complained = pedwarn (new_loc, OPT_Wsystem_headers, msg, new_decl); else if (!flag_exceptions) /* We used to silently permit mismatched eh specs with - -fno-exceptions, so make them a pedwarn now. */ + -fno-exceptions, so only complain if -pedantic. */ complained = pedwarn (new_loc, OPT_Wpedantic, msg, new_decl); + else if (!new_exceptions) + /* Reduce to pedwarn for omitted exception specification. No warning + flag for this; silence the warning by correcting the code. */ + complained = pedwarn (new_loc, 0, msg, new_decl); else error_at (new_loc, msg, new_decl); + if (complained) inform (DECL_SOURCE_LOCATION (old_decl), "from previous declaration %qF", old_decl); + + /* Copy the old exception specification if new_decl has none. Unless the + old decl is extern "C", as obscure code might depend on the type of + the new declaration (e.g. noexcept-type19.C). */ + if (!new_exceptions && !DECL_EXTERN_C_P (old_decl)) + TREE_TYPE (new_decl) + = build_exception_variant (TREE_TYPE (new_decl), old_exceptions); } } diff --git a/gcc/testsuite/g++.dg/cpp1z/aligned-new3.C b/gcc/testsuite/g++.dg/cpp1z/aligned-new3.C index 08cd732ac7b..165c3771ab9 100644 --- a/gcc/testsuite/g++.dg/cpp1z/aligned-new3.C +++ b/gcc/testsuite/g++.dg/cpp1z/aligned-new3.C @@ -1,4 +1,5 @@ // { dg-do run { target c++17 } } +// { dg-options "" } #include @@ -12,7 +13,7 @@ void* operator new (std::size_t n, std::align_val_t) } bool deleted = false; -void operator delete (void *p, std::size_t, std::align_val_t) +void operator delete (void *p, std::size_t, std::align_val_t) // { dg-warning "exception specifier" } { deleted = true; operator delete (p); diff --git a/gcc/testsuite/g++.dg/cpp1z/noexcept-type19.C b/gcc/testsuite/g++.dg/cpp1z/noexcept-type19.C index 571c426aa67..9beadd08298 100644 --- a/gcc/testsuite/g++.dg/cpp1z/noexcept-type19.C +++ b/gcc/testsuite/g++.dg/cpp1z/noexcept-type19.C @@ -2,7 +2,7 @@ #include "noexcept-type19.h" -extern "C" void *malloc (size_t); +extern "C" void *malloc (size_t); // silently discard throw() from system header template void f(T*); diff --git a/gcc/testsuite/g++.dg/diagnostic/pr65923.C b/gcc/testsuite/g++.dg/diagnostic/pr65923.C index 036f4478181..40b6b5965fa 100644 --- a/gcc/testsuite/g++.dg/diagnostic/pr65923.C +++ b/gcc/testsuite/g++.dg/diagnostic/pr65923.C @@ -16,7 +16,7 @@ struct X2 namespace std { - template<> void swap(X&, X&) + template<> void swap(X&, X&) noexcept { constexpr std::chrono::duration operator""s(long double); }