[PATCH] libcpp, c-family, libstdc++: Add -Wdeprecated-octal-literal warning
Jason Merrill
jason@redhat.com
Sat Nov 21 12:10:49 GMT 2026
On 11/21/26 4:36 AM, Jakub Jelinek wrote:
> Hi!
>
> On Fri, Nov 20, 2026 at 08:09:41AM -0500, Jason Merrill wrote:
>> How many people do you think are already using -std=c++29? I think it's
>> useful to add the warning in 29 mode only.
>>
>>> I think we can add the
>>> deprecation as one of the last steps of C2Y or C++29 implementation in a
>>> year or three. Sure, for C++ adding the deprecation is easier because
>>> there is a FTM, but still unsure if people want to do
>>> #if __cpp_0o_octals >= 202611L
>>> 0o1234
>>> #else
>>> 01234
>>> #endif
>>> or
>>> #if __cpp_0o_octals >= 202611L
>>> #define OCTAL(o) 0o##o
>>> #else
>>> #define OCTAL(o) 0##o
>>> #endif
>>> OCTAL(1234)
>>> all around their code immediately, but sure, at some point they will have
>>> to.
>>
>> I suspect there's too much existing code to ever actually remove the old
>> form.
>
> Ok, based on this I've written the following incremental patch on top of
> https://gcc.gnu.org/pipermail/gcc-patches/2026-November/740000.html
Makes sense, so the earlier patch is OK.
> which adds a new warning. Separate because it is not just for C++, but
> also for C. Right now it is enabled by default for C++29 and not for C2Y,
> but the defaults can be certainly changed, whether to postpone making it
> the default for C++29 for now, or also enable it by default for C2Y.
>
> The patch also shows (quite randomly) on the testsuite as well on 3
> libstdc++ affected headers what users can do to deal with this (everything
> is admittedly ugly). The options are conditionalize code on
> the #if __cpp_0o_octals >= 202611L and duplicate small parts of code,
> similarly but use something like the OCTAL macro above (not actually used
> in the patch at all), rewrite 00 as 0, rewrite non-zero octal literals
> as decimal/hexadecimal instead (and possibly make errors in that), use
> pargmas to temporarily disable the warning around some code, use command
> line option to disable it (or enable it if say coding style rules somewhere
> require that) or just live with the warnings.
>
> +++ b/gcc/c-family/c-opts.cc 2026-11-20 19:50:50.297920599 +0100
> @@ -994,6 +994,16 @@ c_common_post_options (const char **pfil
> cpp_opts->cpp_warn_keyword_macro = warn_keyword_macro;
> }
>
> + /* For C++29 default to -Wdeprecated-octal-literal. */
> + if (cxx_dialect >= cxx29)
> + {
> + SET_OPTION_IF_UNSET (&global_options, &global_options_set,
> + warn_deprecated_octal_literal, 1);
Generally options like this should use the pattern of
> /* -Wvolatile is enabled by default in C++20. */
> SET_OPTION_IF_UNSET (&global_options, &global_options_set, warn_volatile,
> deprecated_in (cxx20));
rather than an enclosing if. It might make sense to hold off for now on
enabling it with explicit -Wdeprecated and so not use deprecated_in, but
there should still be a comment about that.
Jason
> + if (warn_deprecated_octal_literal)
> + cpp_opts->cpp_warn_deprecated_octal_literal
> + = warn_deprecated_octal_literal;
> + }
More information about the Libstdc++
mailing list