From patchwork Wed Sep 11 21:26:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1984222 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=JKMHL9gt; dkim-atps=neutral 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=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 [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 (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4X3tv21GLDz1y1y for ; Thu, 12 Sep 2024 07:27:10 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id EDAB4385828B for ; Wed, 11 Sep 2024 21:27:07 +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.133.124]) by sourceware.org (Postfix) with ESMTP id 8F3643858C98 for ; Wed, 11 Sep 2024 21:26:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8F3643858C98 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 8F3643858C98 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=1726090003; cv=none; b=WeQ2CJ4CgIkFm4phTi5L+gSyRo+z3dd9l99xQoSp9ERCE3dKQWv/MWHtlv1JwwHdVV30sOlPFv6LytAqIT1226n4r/spqTlf2y5MS40JSwPLO+dGSbXFa7u0JDEcJ9WdKD7u+hveBJOekdSpGsnYFTB/u/LY3tgoOKhra13lksU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1726090003; c=relaxed/simple; bh=Q/Q1sSO2pDJjt06n7WzeXVegIkQwWRoBrqwuZ601tZk=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=EQSgR9hzIYOM393LmyJkoWh+U86PWK+N/Geq2pwAsc/6o9w3uSjGnoA5GtpVVCpM33cxVYlWghw54RI4m0fxUJCO/f0gaZvIvY2SY4ilR9NOBpQObbdy2ybDzlOzW6Ueu8+7zGDcToVBAkJimmAm35USB12Z5O3fbCMO5oPP+WQ= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1726090001; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=TLrehQLKQdUQrPciVxrmNbJoBGPUkDp4PvwdBChWca8=; b=JKMHL9gtHOvw/7mSszExbwH8UOK4kiMnKq59vzueadD78e4vfD4NKjYxs8uUDpGP5spE9D 89XRHdAeWivjP/7dnV3vrKLEIkyBZukFML8rz1ifFWu25fXOpDiwfj8Kkv4GL9krgu8bBB VFu1ko2LTfVN+rNv3XF/kVKmnx7FXpY= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-62-uBAKuRBAP3iOBCJTaIjA1Q-1; Wed, 11 Sep 2024 17:26:40 -0400 X-MC-Unique: uBAKuRBAP3iOBCJTaIjA1Q-1 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 32D0019560A2 for ; Wed, 11 Sep 2024 21:26:39 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.45.224.29]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 645E119560B1; Wed, 11 Sep 2024 21:26:38 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 48BLQZB91717745 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 11 Sep 2024 23:26:35 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 48BLQZHc1717744; Wed, 11 Sep 2024 23:26:35 +0200 Date: Wed, 11 Sep 2024 23:26:35 +0200 From: Jakub Jelinek To: Jason Merrill Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] c++: Disable deprecated/unavailable diagnostics when creating thunks for methods with such attributes [PR116636] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, 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: , Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org Hi! On the following testcase, we emit false positive warnings/errors about using the deprecated or unavailable methods when creating thunks for them, even when nothing (in the testcase so far) actually used those. The following patch temporarily disables that diagnostics when creating the thunks. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2024-09-11 Jakub Jelinek PR c++/116636 * method.cc: Include decl.h. (use_thunk): Temporarily change deprecated_state to UNAVAILABLE_DEPRECATED_SUPPRESS. * g++.dg/warn/deprecated-19.C: New test. Jakub --- gcc/cp/method.cc.jj 2024-09-06 13:43:37.823301244 +0200 +++ gcc/cp/method.cc 2024-09-11 12:19:57.420486173 +0200 @@ -26,6 +26,7 @@ along with GCC; see the file COPYING3. #include "coretypes.h" #include "target.h" #include "cp-tree.h" +#include "decl.h" #include "stringpool.h" #include "cgraph.h" #include "varasm.h" @@ -283,6 +284,11 @@ use_thunk (tree thunk_fndecl, bool emit_ /* Thunks are always addressable; they only appear in vtables. */ TREE_ADDRESSABLE (thunk_fndecl) = 1; + /* Don't diagnose deprecated or unavailable functions just because they + have thunks emitted for them. */ + auto du = make_temp_override (deprecated_state, + UNAVAILABLE_DEPRECATED_SUPPRESS); + /* Figure out what function is being thunked to. It's referenced in this translation unit. */ TREE_ADDRESSABLE (function) = 1; --- gcc/testsuite/g++.dg/warn/deprecated-19.C.jj 2024-09-11 12:50:25.342634444 +0200 +++ gcc/testsuite/g++.dg/warn/deprecated-19.C 2024-09-11 13:05:29.210222060 +0200 @@ -0,0 +1,22 @@ +// PR c++/116636 +// { dg-do compile } +// { dg-options "-pedantic -Wdeprecated" } + +struct A { + virtual int foo () = 0; +}; +struct B : virtual A { + [[deprecated]] int foo () { return 0; } // { dg-message "declared here" } +}; // { dg-warning "C\\\+\\\+11 attributes only available with" "" { target c++98_only } .-1 } +struct C : virtual A { + [[gnu::unavailable]] int foo () { return 0; } // { dg-message "declared here" } +}; // { dg-warning "C\\\+\\\+11 attributes only available with" "" { target c++98_only } .-1 } + +void +bar () +{ + B b; + b.foo (); // { dg-warning "'virtual int B::foo\\\(\\\)' is deprecated" } + C c; + c.foo (); // { dg-error "'virtual int C::foo\\\(\\\)' is unavailable" } +}