From patchwork Thu Oct 3 16:40:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 1992432 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=XEehCmJ1; 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 4XKHWH1ltTz1xt2 for ; Fri, 4 Oct 2024 02:41:31 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E8B9738460A6 for ; Thu, 3 Oct 2024 16:41:28 +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 3D93A384A820 for ; Thu, 3 Oct 2024 16:41:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3D93A384A820 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 3D93A384A820 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=1727973667; cv=none; b=TQaH9dpc4+asgIxBcili7ziCL9CklQEF3BlfeDcV30hNkoqViGMaUiNg6FqMhVw9T5n0at4m6nnZCOFcf0t3n/KRvURHoCgj4/ryJ9NaqTLkBCn9OMneh4B0OBdEysRONgjns8itl3HuGwYvp4NctmKYAuUeHs6+qAk91utyISY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1727973667; c=relaxed/simple; bh=ib0ltzy0L7Xorpj3BLe18N9fuJhECwLry3LsrAoHUtY=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=OB8go/Kd9YfCSqEN8XXKv/Rk+ygP00Bg5tYzR+S0OXHzZZKbK3Q35JdjIWQhV2SxlpEJVwoWdntJXecbVi3mjmBFIX+0JuOIrYI4+LxqEXxtHs4DEUEIIGm4PPBK3DVM/XJl+7YyPUNzlcBsg2+orfR8MQ/2zqzvng6kVhgE4m4= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1727973665; 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: in-reply-to:in-reply-to:references:references; bh=ncKNKIYh7q+qMmX7bcjzJpCLqMyJ0EA6BLQUoKj9nEk=; b=XEehCmJ1KXMvp54+vltQL6NqHYeHXHsHfevuOylmKcHig4DURaeHqhiBCT8wECNxpOEFdp EIva9mV7M96KWNkDQQPlQUElmxdiQo9B7flKJbLgWJCtKjNAtBatOZussDbaiMDALN4gga VyqNTavRM1rTrMr+xipeSaDd5AMnqoI= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-421-yjwhgsIgPl-vFlHaTF0QLQ-1; Thu, 03 Oct 2024 12:41:03 -0400 X-MC-Unique: yjwhgsIgPl-vFlHaTF0QLQ-1 Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-7a9cfe4442cso146384885a.3 for ; Thu, 03 Oct 2024 09:41:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727973662; x=1728578462; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ncKNKIYh7q+qMmX7bcjzJpCLqMyJ0EA6BLQUoKj9nEk=; b=Pm0XF58rr5ziX3jJzK/XEarzX+Ts4OEwfz2TIYlAypifsoLdnij8Whg/XrIbLyRfRG kLcloeCdyvckt13gTcRlCwhb2f3s8Zd2LEyXbxTdaH3fyfYZ3S3nnSe9DSPbCgpKSER6 eqzmHQczAOvk2SQCSDlrcbE1MJgbC/1Ex6VYVwlRYSda5xDUxtsM2wDr3l9oD+Zbez51 2A7wsgCPECMx1N0/6GHCzI92M29aGN7r3kDjKtvJhbj89/oeKpU4zFnWv/Sm2iP4Oawi 9GsZ8zuqgJDH24mGBC/sGB4WG39fo/VzI/rcJRrsHtdLRcpoVm5ePIgSWdI0MR/+Vz0l l8lA== X-Gm-Message-State: AOJu0Ywv4Fvxe9j36keuVyTRSYx6EoCipVQxGMOi3Gww7gOP3j5ZPg3L eLlc+PDPY7/AWR563vbdWVjndMrMer7CETZH4hImUZgthYz0beRa2gzSaANBhloUrqStxt0VoCC j/LPLLd+O7NG40G2X4e+RNsX2tUS4xlyQlIixF6xmdVZnSUvPbZSEiOVFX8vuV6jo2n5sXCJFqT WpV8MJ2mcOzq5El301wkxSPV6yYPMpv6lYY6I= X-Received: by 2002:a05:620a:c4e:b0:7a7:fdef:27a with SMTP id af79cd13be357-7ae6274f6eamr1229371785a.58.1727973661965; Thu, 03 Oct 2024 09:41:01 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFuuxVRfeN3ZYMUHb5xf0A0ByvG0UnBICQvKM1Y8ppqC+EWusy/EU6CxiQFldVxZxHZp53+mg== X-Received: by 2002:a05:620a:c4e:b0:7a7:fdef:27a with SMTP id af79cd13be357-7ae6274f6eamr1229366985a.58.1727973661378; Thu, 03 Oct 2024 09:41:01 -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 af79cd13be357-7ae6b3a306asm63455885a.62.2024.10.03.09.41.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Oct 2024 09:41:00 -0700 (PDT) From: Jason Merrill To: gcc-patches@gcc.gnu.org Subject: [PATCH 2/2] c++: -Wdeprecated enables later standard deprecations Date: Thu, 3 Oct 2024 12:40:00 -0400 Message-ID: <20241003164057.1087609-2-jason@redhat.com> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241003164057.1087609-1-jason@redhat.com> References: <20241003164057.1087609-1-jason@redhat.com> 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< -- By default -Wdeprecated warns about deprecations in the active standard. When specified explicitly, let's also warn about deprecations in later standards. gcc/c-family/ChangeLog: * c-opts.cc (c_common_post_options): Explicit -Wdeprecated enables deprecations from later standards. gcc/ChangeLog: * doc/invoke.texi: Explicit -Wdeprecated enables more warnings. --- gcc/doc/invoke.texi | 22 ++++++++++++++++------ gcc/c-family/c-opts.cc | 17 ++++++++++++----- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index c90f5b4d58e..d38c1feb86f 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -3864,8 +3864,10 @@ for code that is not valid in C++23 but used to be valid but deprecated in C++20 with a pedantic warning that can be disabled with @option{-Wno-comma-subscript}. -Enabled by default with @option{-std=c++20} unless @option{-Wno-deprecated}, -and with @option{-std=c++23} regardless of @option{-Wno-deprecated}. +Enabled by default with @option{-std=c++20} unless +@option{-Wno-deprecated}, and after @option{-std=c++23} regardless of +@option{-Wno-deprecated}. Before @option{-std=c++20}, enabled with +explicit @option{-Wdeprecated}. This warning is upgraded to an error by @option{-pedantic-errors} in C++23 mode or later. @@ -4012,7 +4014,7 @@ int k = f - e; @option{-Wdeprecated-enum-enum-conversion} is enabled by default with @option{-std=c++20}. In pre-C++20 dialects, this warning can be enabled -by @option{-Wenum-conversion}. +by @option{-Wenum-conversion} or @option{-Wdeprecated}. @opindex Wdeprecated-enum-float-conversion @opindex Wno-deprecated-enum-float-conversion @@ -4030,14 +4032,14 @@ bool b = e <= 3.7; @option{-Wdeprecated-enum-float-conversion} is enabled by default with @option{-std=c++20}. In pre-C++20 dialects, this warning can be enabled -by @option{-Wenum-conversion}. +by @option{-Wenum-conversion} or @option{-Wdeprecated}. @opindex Wdeprecated-literal-operator @opindex Wno-deprecated-literal-operator @item -Wdeprecated-literal-operator @r{(C++ and Objective-C++ only)} Warn that the declaration of a user-defined literal operator with a space before the suffix is deprecated. This warning is enabled by -default in C++23. +default in C++23, or with explicit @option{-Wdeprecated}. @smallexample string operator "" _i18n(const char*, std::size_t); // deprecated @@ -4740,7 +4742,8 @@ non-class type, @code{volatile}-qualified function return type, @code{volatile}-qualified parameter type, and structured bindings of a @code{volatile}-qualified type. This usage was deprecated in C++20. -Enabled by default with @option{-std=c++20}. +Enabled by default with @option{-std=c++20}. Before +@option{-std=c++20}, enabled with explicit @option{-Wdeprecated}. @opindex Wzero-as-null-pointer-constant @opindex Wno-zero-as-null-pointer-constant @@ -10389,6 +10392,13 @@ disable the error when compiled with @option{-Werror} flag. @item -Wno-deprecated Do not warn about usage of deprecated features. @xref{Deprecated Features}. +In C++, explicitly specifying @option{-Wdeprecated} also enables +warnings about some features that are deprecated in later language +standards, specifically @option{-Wcomma-subscript}, +@option{-Wvolatile}, @option{-Wdeprecated-enum-float-conversion}, +@option{-Wdeprecated-enum-enum-conversion}, and +@option{-Wdeprecated-literal-operator}. + @opindex Wno-deprecated-declarations @opindex Wdeprecated-declarations @item -Wno-deprecated-declarations diff --git a/gcc/c-family/c-opts.cc b/gcc/c-family/c-opts.cc index 8ff3d966bb6..510e0870140 100644 --- a/gcc/c-family/c-opts.cc +++ b/gcc/c-family/c-opts.cc @@ -996,30 +996,37 @@ c_common_post_options (const char **pfilename) SET_OPTION_IF_UNSET (&global_options, &global_options_set, warn_register, cxx_dialect >= cxx17); + /* Explicit -Wdeprecated turns on warnings from later standards. */ + auto deprecated_in = [&](enum cxx_dialect d) + { + if (OPTION_SET_P (warn_deprecated)) return !!warn_deprecated; + return (warn_deprecated && cxx_dialect >= d); + }; + /* -Wcomma-subscript is enabled by default in C++20. */ SET_OPTION_IF_UNSET (&global_options, &global_options_set, warn_comma_subscript, cxx_dialect >= cxx23 - || (cxx_dialect == cxx20 && warn_deprecated)); + || deprecated_in (cxx20)); /* -Wvolatile is enabled by default in C++20. */ SET_OPTION_IF_UNSET (&global_options, &global_options_set, warn_volatile, - cxx_dialect >= cxx20 && warn_deprecated); + deprecated_in (cxx20)); /* -Wdeprecated-enum-enum-conversion is enabled by default in C++20. */ SET_OPTION_IF_UNSET (&global_options, &global_options_set, warn_deprecated_enum_enum_conv, - cxx_dialect >= cxx20 && warn_deprecated); + deprecated_in (cxx20)); /* -Wdeprecated-enum-float-conversion is enabled by default in C++20. */ SET_OPTION_IF_UNSET (&global_options, &global_options_set, warn_deprecated_enum_float_conv, - cxx_dialect >= cxx20 && warn_deprecated); + deprecated_in (cxx20)); /* -Wdeprecated-literal-operator is enabled by default in C++23. */ SET_OPTION_IF_UNSET (&global_options, &global_options_set, warn_deprecated_literal_operator, - cxx_dialect >= cxx23 && warn_deprecated); + deprecated_in (cxx23)); /* -Wtemplate-id-cdtor is enabled by default in C++20. */ SET_OPTION_IF_UNSET (&global_options, &global_options_set,