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, -- 2.46.2