https://gcc.gnu.org/g:0ad6fa4c66a0cf31dece5ed63152ab4f65cbd71a
commit r17-6625-g0ad6fa4c66a0cf31dece5ed63152ab4f65cbd71a Author: Jakub Jelinek <[email protected]> Date: Tue Nov 24 09:19:30 2026 +0100 libcpp, c-family, libstdc++: Add -Wdeprecated-octal-literal warning 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 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 pragmas 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. 2026-11-24 Jakub Jelinek <[email protected]> gcc/ * doc/invoke.texi (Wdeprecated-octal-literal): Document. gcc/c-family/ * c.opt (Wdeprecated-octal-literal): New warning. * c.opt.urls: Regenerate. * c-opts.cc (c_common_post_options): Enable -Wdeprecated-octal-literal by default for C++29. gcc/testsuite/ * c-c++-common/Wdeprecated-octal-literal-1.c: New test. * c-c++-common/Wdeprecated-octal-literal-2.c: New test. * c-c++-common/Wdeprecated-octal-literal-3.c: New test. * c-c++-common/Wdeprecated-octal-literal-4.c: New test. * c-c++-common/Wdeprecated-octal-literal-5.c: New test. * c-c++-common/Wdeprecated-octal-literal-6.c: New test. * c-c++-common/Wprio-ctor-dtor.c: Expect extra warning for C++29. * c-c++-common/gomp/doacross-6.c: Likewise. * c-c++-common/analyzer/deref-before-check-pr108455-git-pack-revindex.c: Use 0 instead of 00. * c-c++-common/analyzer/stdarg-pr111289-int.c: Expect extra warning for C++29. * g++.dg/ubsan/pr80349.C: Add -Wno-deprecated-octal-literal to dg-options. * g++.dg/ext/va-arg-pack-len-1.C: Likewise. * g++.dg/ext/va-arg-pack-len-2.C: Likewise. * g++.dg/cpp1y/digit-sep.C: Add -Wno-deprecated-octal-literal as dg-additional-options for C++29. * g++.dg/cpp1y/digit-sep-neg.C: Expect extra warnings for C++29. * g++.dg/warn/pr13358-4.C: Likewise. * g++.dg/warn/pr13358-3.C: Likewise. * g++.dg/cpp0x/udlit-raw-op.C: Likewise. * g++.dg/cpp0x/udlit-raw-length.C: Likewise. * g++.dg/vect/pr98064.cc: Add -Wno-deprecated-octal-literal to dg-additional-options. * g++.dg/vect/pr95297.cc: Likewise. * g++.old-deja/g++.niklas/t119.C: Expect extra warning for C++29. * g++.old-deja/g++.law/enum2.C: Add -Wno-deprecated-octal-literal to dg-options. * g++.old-deja/g++.other/mutable1.C: Add -Wno-deprecated-octal-literal as dg-additional-options for C++29. * g++.old-deja/g++.mike/p811.C: Add -Wno-deprecated-octal-literal to dg-options. libcpp/ * include/cpplib.h (struct cpp_options): Add cpp_warn_deprecated_octal_literal member. (enum cpp_warning_reason): Add CPP_W_DEPRECATED_OCTAL_LITERAL. * expr.cc (cpp_classify_number): Emit -Wdeprecated-octal-literal. libstdc++-v3/ * include/std/charconv (std::__detail::__to_chars_8): Use conditionally 0o prefixed literals instead of 0 prefixed ones or rewrite into decimal. * include/bits/fs_fwd.h (std::filesystem::perms): Temporarily ignore -Wdeprecated-octal-literal warning. * include/experimental/bits/fs_fwd.h (std::experimental::filesystem::perms): Likewise. * testsuite/std/time/format/pr120114.cc: Expect extra warning for C++29. * testsuite/20_util/to_chars/constexpr.cc (test_base8): Use conditionally 0o prefixed literals instead of 0 prefixed ones. * testsuite/23_containers/mdspan/layouts/stride_neg.cc: Replace 00 with 0. Reviewed-by: Jason Merrill <[email protected]> Diff: --- gcc/c-family/c-opts.cc | 17 +++++++++++++++++ gcc/c-family/c.opt | 4 ++++ gcc/c-family/c.opt.urls | 3 +++ gcc/doc/invoke.texi | 12 +++++++++++- .../c-c++-common/Wdeprecated-octal-literal-1.c | 13 +++++++++++++ .../c-c++-common/Wdeprecated-octal-literal-2.c | 13 +++++++++++++ .../c-c++-common/Wdeprecated-octal-literal-3.c | 13 +++++++++++++ .../c-c++-common/Wdeprecated-octal-literal-4.c | 10 ++++++++++ .../c-c++-common/Wdeprecated-octal-literal-5.c | 10 ++++++++++ .../c-c++-common/Wdeprecated-octal-literal-6.c | 10 ++++++++++ gcc/testsuite/c-c++-common/Wprio-ctor-dtor.c | 2 +- ...deref-before-check-pr108455-git-pack-revindex.c | 2 +- .../c-c++-common/analyzer/stdarg-pr111289-int.c | 2 +- gcc/testsuite/c-c++-common/gomp/doacross-6.c | 2 +- gcc/testsuite/g++.dg/cpp0x/udlit-raw-length.C | 2 +- gcc/testsuite/g++.dg/cpp0x/udlit-raw-op.C | 2 +- gcc/testsuite/g++.dg/cpp1y/digit-sep-neg.C | 1 + gcc/testsuite/g++.dg/cpp1y/digit-sep.C | 1 + gcc/testsuite/g++.dg/ext/va-arg-pack-len-1.C | 2 +- gcc/testsuite/g++.dg/ext/va-arg-pack-len-2.C | 2 +- gcc/testsuite/g++.dg/ubsan/pr80349.C | 2 +- gcc/testsuite/g++.dg/vect/pr95297.cc | 2 +- gcc/testsuite/g++.dg/vect/pr98064.cc | 2 +- gcc/testsuite/g++.dg/warn/pr13358-3.C | 4 ++-- gcc/testsuite/g++.dg/warn/pr13358-4.C | 4 ++-- gcc/testsuite/g++.old-deja/g++.law/enum2.C | 2 +- gcc/testsuite/g++.old-deja/g++.mike/p811.C | 2 +- gcc/testsuite/g++.old-deja/g++.niklas/t119.C | 2 +- gcc/testsuite/g++.old-deja/g++.other/mutable1.C | 3 ++- libcpp/expr.cc | 22 ++++++++++++++++++++++ libcpp/include/cpplib.h | 6 +++++- libstdc++-v3/include/bits/fs_fwd.h | 3 +++ libstdc++-v3/include/experimental/bits/fs_fwd.h | 3 +++ libstdc++-v3/include/std/charconv | 13 +++++++++++-- .../testsuite/20_util/to_chars/constexpr.cc | 16 ++++++++++++++++ .../23_containers/mdspan/layouts/stride_neg.cc | 8 ++++---- libstdc++-v3/testsuite/std/time/format/pr120114.cc | 2 +- 37 files changed, 191 insertions(+), 28 deletions(-) diff --git a/gcc/c-family/c-opts.cc b/gcc/c-family/c-opts.cc index 9d275e60d35e..bdff3a47499f 100644 --- a/gcc/c-family/c-opts.cc +++ b/gcc/c-family/c-opts.cc @@ -1107,6 +1107,23 @@ c_common_post_options (const char **pfilename) warn_template_id_cdtor, cxx_dialect >= cxx20 || warn_cxx20_compat); + /* For C++29 default to -Wdeprecated-octal-literal. At least + for the time being, don't use deprecated_in (cxx29) here, warning + with -Wdeprecated in C++26 and older modes for octal literal means + we warn even on correctly portable code using + #if __cpp_0o_octals >= 202611L + 0o4561375437615437 + #else + 04561375437615437 + #endif + and one can't easily use 0o prefixed octal literals in C++26 and + older code because there will be pedwarn for those or no support + in older compilers at all. So, that just tells developers not to use + octal literals at all. */ + SET_OPTION_IF_UNSET (&global_options, &global_options_set, + warn_deprecated_octal_literal, cxx_dialect >= cxx29); + cpp_opts->cpp_warn_deprecated_octal_literal = warn_deprecated_octal_literal; + /* Declone C++ 'structors if -Os. */ if (flag_declone_ctor_dtor == -1) flag_declone_ctor_dtor = optimize_size; diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt index d5b973baa855..0e429bd1cd9b 100644 --- a/gcc/c-family/c.opt +++ b/gcc/c-family/c.opt @@ -695,6 +695,10 @@ Wdeprecated-non-prototype C ObjC Var(warn_deprecated_non_prototype) Init(-1) Warning Warn about calls with arguments to functions declared without parameters. +Wdeprecated-octal-literal +C ObjC C++ ObjC++ Warning Var(warn_deprecated_octal_literal) CPP(cpp_warn_deprecated_octal_literal) CppReason(CPP_W_DEPRECATED_OCTAL_LITERAL) Init(0) +Warn on octal literals with 0 prefix rather than 0o or 0O. + Wdeprecated-openmp C ObjC C++ ObjC++ Warning Var(warn_deprecated_openmp) Init(1) Warn about deprecated OpenMP code. diff --git a/gcc/c-family/c.opt.urls b/gcc/c-family/c.opt.urls index 6efeea9b42fe..387808f6ead6 100644 --- a/gcc/c-family/c.opt.urls +++ b/gcc/c-family/c.opt.urls @@ -487,6 +487,9 @@ UrlSuffix(gcc/C_002b_002b-Dialect-Options.html#index-Wdeprecated-literal-operato Wdeprecated-non-prototype UrlSuffix(gcc/Warning-Options.html#index-Wdeprecated-non-prototype) +Wdeprecated-octal-literal +UrlSuffix(gcc/Warning-Options.html#index-Wdeprecated-octal-literal) + Wdeprecated-openmp UrlSuffix(gcc/Warning-Options.html#index-Wdeprecated-openmp) LangUrlSuffix_Fortran(gfortran/Error-and-Warning-Options.html#index-Wdeprecated-openmp) diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index c0e97db9a012..d724cad22f0d 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -392,7 +392,7 @@ Objective-C and Objective-C++ Dialects}. -Wdangling-else -Wdangling-pointer -Wdangling-pointer=@var{n} -Wdate-time -Wno-deprecated -Wno-deprecated-declarations -Wno-designated-init --Wno-deprecated-openmp +-Wdeprecated-octal-literal -Wno-deprecated-openmp -Wdisabled-optimization -Wno-discarded-array-qualifiers -Wno-discarded-qualifiers -Wno-div-by-zero -Wdouble-promotion @@ -11615,6 +11615,16 @@ Suppress warnings when a positional initializer is used to initialize a structure that has been marked with the @code{designated_init} attribute. +@opindex Wdeprecated-octal-literal +@opindex Wno-deprecated-octal-literal +@item -Wdeprecated-octal-literal +Warn on 0 prefixed octal literals other than 0. In C++29 and C2Y +octal literals should be specified with 0o or 0O prefix and the older +0 prefixed octal literals are deprecated. 0 is not deprecated, but +00 or 0177 is and should be written in C++29 or C2Y as 0o0 (or in this +case 0) or 0o177 (or 0O177). +This flag is enabled by default for @option{-std=c++29}. + @opindex Wzero-init-padding-bits= @item -Wzero-init-padding-bits=@var{value} Warn about automatic variable initializers that might not zero diff --git a/gcc/testsuite/c-c++-common/Wdeprecated-octal-literal-1.c b/gcc/testsuite/c-c++-common/Wdeprecated-octal-literal-1.c new file mode 100644 index 000000000000..8862a4b71113 --- /dev/null +++ b/gcc/testsuite/c-c++-common/Wdeprecated-octal-literal-1.c @@ -0,0 +1,13 @@ +/* { dg-do compile } */ +/* { dg-options "-Wdeprecated-octal-literal" } */ +/* { dg-additional-options "-std=c23" { target c } } */ + +int a = 0; +int b = 00; /* { dg-warning "octal literals without '0o' or '0O' prefix other than '0' are deprecated in" } */ +unsigned long long d = 042ULL; /* { dg-warning "octal literals without '0o' or '0O' prefix other than '0' are deprecated in" } */ +#if 0U == 0 +#endif +#if 00l == 0 /* { dg-warning "octal literals without '0o' or '0O' prefix other than '0' are deprecated in" } */ +#endif +#if 042 == 0 /* { dg-warning "octal literals without '0o' or '0O' prefix other than '0' are deprecated in" } */ +#endif diff --git a/gcc/testsuite/c-c++-common/Wdeprecated-octal-literal-2.c b/gcc/testsuite/c-c++-common/Wdeprecated-octal-literal-2.c new file mode 100644 index 000000000000..d66b9d26bae2 --- /dev/null +++ b/gcc/testsuite/c-c++-common/Wdeprecated-octal-literal-2.c @@ -0,0 +1,13 @@ +/* { dg-do compile } */ +/* { dg-options "-Wno-deprecated-octal-literal" } */ +/* { dg-additional-options "-std=c23" { target c } } */ + +int a = 0; +int b = 00; +unsigned long long d = 042ULL; +#if 0U == 0 +#endif +#if 00l == 0 +#endif +#if 042 == 0 +#endif diff --git a/gcc/testsuite/c-c++-common/Wdeprecated-octal-literal-3.c b/gcc/testsuite/c-c++-common/Wdeprecated-octal-literal-3.c new file mode 100644 index 000000000000..e86b350f3500 --- /dev/null +++ b/gcc/testsuite/c-c++-common/Wdeprecated-octal-literal-3.c @@ -0,0 +1,13 @@ +/* { dg-do compile } */ +/* { dg-options "" } */ +/* { dg-additional-options "-std=c2y" { target c } } */ + +int a = 0; +int b = 00; /* { dg-warning "octal literals without '0o' or '0O' prefix other than '0' are deprecated in" "" { target c++29 } } */ +unsigned long long d = 042ULL; /* { dg-warning "octal literals without '0o' or '0O' prefix other than '0' are deprecated in" "" { target c++29 } } */ +#if 0U == 0 +#endif +#if 00l == 0 /* { dg-warning "octal literals without '0o' or '0O' prefix other than '0' are deprecated in" "" { target c++29 } } */ +#endif +#if 042 == 0 /* { dg-warning "octal literals without '0o' or '0O' prefix other than '0' are deprecated in" "" { target c++29 } } */ +#endif diff --git a/gcc/testsuite/c-c++-common/Wdeprecated-octal-literal-4.c b/gcc/testsuite/c-c++-common/Wdeprecated-octal-literal-4.c new file mode 100644 index 000000000000..884128e3cafe --- /dev/null +++ b/gcc/testsuite/c-c++-common/Wdeprecated-octal-literal-4.c @@ -0,0 +1,10 @@ +/* { dg-do compile { target { c || c++14 } } } */ +/* { dg-options "-Wdeprecated-octal-literal" } */ +/* { dg-additional-options "-std=c23" { target c } } */ + +int a = 0'0; /* { dg-warning "octal literals without '0o' or '0O' prefix other than '0' are deprecated in" } */ +unsigned long b = 000'000'001UL; /* { dg-warning "octal literals without '0o' or '0O' prefix other than '0' are deprecated in" } */ +#if 0'0U == 0 /* { dg-warning "octal literals without '0o' or '0O' prefix other than '0' are deprecated in" } */ +#endif +#if 01'23'45'67ul == 0 /* { dg-warning "octal literals without '0o' or '0O' prefix other than '0' are deprecated in" } */ +#endif diff --git a/gcc/testsuite/c-c++-common/Wdeprecated-octal-literal-5.c b/gcc/testsuite/c-c++-common/Wdeprecated-octal-literal-5.c new file mode 100644 index 000000000000..9e96b2b58a68 --- /dev/null +++ b/gcc/testsuite/c-c++-common/Wdeprecated-octal-literal-5.c @@ -0,0 +1,10 @@ +/* { dg-do compile { target { c || c++14 } } } */ +/* { dg-options "-Wno-deprecated-octal-literal" } */ +/* { dg-additional-options "-std=c23" { target c } } */ + +int a = 0'0; +unsigned long b = 000'000'001UL; +#if 0'0U == 0 +#endif +#if 01'23'45'67ul == 0 +#endif diff --git a/gcc/testsuite/c-c++-common/Wdeprecated-octal-literal-6.c b/gcc/testsuite/c-c++-common/Wdeprecated-octal-literal-6.c new file mode 100644 index 000000000000..2e1726c6c97c --- /dev/null +++ b/gcc/testsuite/c-c++-common/Wdeprecated-octal-literal-6.c @@ -0,0 +1,10 @@ +/* { dg-do compile { target { c || c++14 } } } */ +/* { dg-options "" } */ +/* { dg-additional-options "-std=c2y" { target c } } */ + +int a = 0'0; /* { dg-warning "octal literals without '0o' or '0O' prefix other than '0' are deprecated in" "" { target c++29 } } */ +unsigned long b = 000'000'001UL; /* { dg-warning "octal literals without '0o' or '0O' prefix other than '0' are deprecated in" "" { target c++29 } } */ +#if 0'0U == 0 /* { dg-warning "octal literals without '0o' or '0O' prefix other than '0' are deprecated in" "" { target c++29 } } */ +#endif +#if 01'23'45'67ul == 0 /* { dg-warning "octal literals without '0o' or '0O' prefix other than '0' are deprecated in" "" { target c++29 } } */ +#endif diff --git a/gcc/testsuite/c-c++-common/Wprio-ctor-dtor.c b/gcc/testsuite/c-c++-common/Wprio-ctor-dtor.c index 9da7254cc6b8..8489fcf24b84 100644 --- a/gcc/testsuite/c-c++-common/Wprio-ctor-dtor.c +++ b/gcc/testsuite/c-c++-common/Wprio-ctor-dtor.c @@ -6,5 +6,5 @@ void construct1 () __attribute__ ((constructor (10))); void construct2 () __attribute__ ((constructor (100))); void construct2 () __attribute__ ((constructor (101))); void destruct1 () __attribute__ ((destructor (1))); -void destruct2 () __attribute__ ((destructor (02))); +void destruct2 () __attribute__ ((destructor (02))); /* { dg-warning "octal literals without '0o' or '0O' prefix other than '0' are deprecated" "" { target c++29 } } */ void destruct2 () __attribute__ ((destructor (102))); diff --git a/gcc/testsuite/c-c++-common/analyzer/deref-before-check-pr108455-git-pack-revindex.c b/gcc/testsuite/c-c++-common/analyzer/deref-before-check-pr108455-git-pack-revindex.c index b79099710441..da1eeb59eb04 100644 --- a/gcc/testsuite/c-c++-common/analyzer/deref-before-check-pr108455-git-pack-revindex.c +++ b/gcc/testsuite/c-c++-common/analyzer/deref-before-check-pr108455-git-pack-revindex.c @@ -69,7 +69,7 @@ int load_revindex_from_disk(char *revindex_name, uint32_t num_objects, size_t revindex_size; struct revindex_header *hdr; - fd = git_open_cloexec(revindex_name, 00); + fd = git_open_cloexec(revindex_name, 0); if (fd < 0) { ret = -1; diff --git a/gcc/testsuite/c-c++-common/analyzer/stdarg-pr111289-int.c b/gcc/testsuite/c-c++-common/analyzer/stdarg-pr111289-int.c index a96a91f3c9f2..197257976a59 100644 --- a/gcc/testsuite/c-c++-common/analyzer/stdarg-pr111289-int.c +++ b/gcc/testsuite/c-c++-common/analyzer/stdarg-pr111289-int.c @@ -22,7 +22,7 @@ test_1 (char const *name, ...) void call_test_1 () { - test_1 ("nonexist.ent/", 0600); + test_1 ("nonexist.ent/", 0600); /* { dg-warning "octal literals without '0o' or '0O' prefix other than '0' are deprecated" "" { target c++29 } } */ } /* Not the same size: small enough for int promotion. */ diff --git a/gcc/testsuite/c-c++-common/gomp/doacross-6.c b/gcc/testsuite/c-c++-common/gomp/doacross-6.c index 65ee8979a4f3..38e789b16e26 100644 --- a/gcc/testsuite/c-c++-common/gomp/doacross-6.c +++ b/gcc/testsuite/c-c++-common/gomp/doacross-6.c @@ -96,7 +96,7 @@ corge (int n) #pragma omp for ordered for (i = 0; i < 8; i += n) { - #pragma omp ordered doacross(sink:omp_cur_iteration - 001) + #pragma omp ordered doacross(sink:omp_cur_iteration - 001) // { dg-warning "octal literals without '0o' or '0O' prefix other than '0' are deprecated" "" { target c++29 } } } #pragma omp for ordered for (i = 0; i < 8; i += n) diff --git a/gcc/testsuite/g++.dg/cpp0x/udlit-raw-length.C b/gcc/testsuite/g++.dg/cpp0x/udlit-raw-length.C index 735484095807..e15000296b81 100644 --- a/gcc/testsuite/g++.dg/cpp0x/udlit-raw-length.C +++ b/gcc/testsuite/g++.dg/cpp0x/udlit-raw-length.C @@ -23,5 +23,5 @@ operator ""_lenraw(const char* digits) static_assert(123_lenraw == 3, "Ouch"); static_assert(1_lenraw == 1, "Ouch"); -static_assert(012_lenraw == 3, "Ouch"); +static_assert(012_lenraw == 3, "Ouch"); // { dg-warning "octal literals without '0o' or '0O' prefix other than '0' are deprecated" "" { target c++29 } } static_assert(0_lenraw == 1, "Ouch"); diff --git a/gcc/testsuite/g++.dg/cpp0x/udlit-raw-op.C b/gcc/testsuite/g++.dg/cpp0x/udlit-raw-op.C index d49e42642c94..041bcc9ff441 100644 --- a/gcc/testsuite/g++.dg/cpp0x/udlit-raw-op.C +++ b/gcc/testsuite/g++.dg/cpp0x/udlit-raw-op.C @@ -13,7 +13,7 @@ operator ""_raw_umber(const char * str) int main() { - int i = 0123012301230123012301230123012301230123012301230123012301230123_raw_umber; + int i = 0123012301230123012301230123012301230123012301230123012301230123_raw_umber; // { dg-warning "octal literals without '0o' or '0O' prefix other than '0' are deprecated" "" { target c++29 } } assert( i == 64 ); int j = 90123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789_raw_umber; diff --git a/gcc/testsuite/g++.dg/cpp1y/digit-sep-neg.C b/gcc/testsuite/g++.dg/cpp1y/digit-sep-neg.C index 300fe51041b6..0046a4d4bb5e 100644 --- a/gcc/testsuite/g++.dg/cpp1y/digit-sep-neg.C +++ b/gcc/testsuite/g++.dg/cpp1y/digit-sep-neg.C @@ -31,3 +31,4 @@ main() // { dg-error "expected ';' before" "expected ';' before" { target *-*-* } 15 } // { dg-error "expected ';' before" "expected ';' before" { target *-*-* } 19 } // { dg-error "expected ';' before" "expected ';' before" { target *-*-* } 26 } +// { dg-warning "octal literals without '0o' or '0O' prefix other than '0' are deprecated" "" { target c++29 } 12 } diff --git a/gcc/testsuite/g++.dg/cpp1y/digit-sep.C b/gcc/testsuite/g++.dg/cpp1y/digit-sep.C index 111e7a55d79d..ea2ca217b183 100644 --- a/gcc/testsuite/g++.dg/cpp1y/digit-sep.C +++ b/gcc/testsuite/g++.dg/cpp1y/digit-sep.C @@ -1,4 +1,5 @@ // { dg-do compile { target c++14 } } +// { dg-additional-options "-Wno-deprecated-octal-literal" { target c++29 } } #define assert(E) if(!(E))__builtin_abort(); diff --git a/gcc/testsuite/g++.dg/ext/va-arg-pack-len-1.C b/gcc/testsuite/g++.dg/ext/va-arg-pack-len-1.C index d3c84091b8f0..6d304a0183cc 100644 --- a/gcc/testsuite/g++.dg/ext/va-arg-pack-len-1.C +++ b/gcc/testsuite/g++.dg/ext/va-arg-pack-len-1.C @@ -1,5 +1,5 @@ // { dg-do run } -// { dg-options "-O2" } +// { dg-options "-O2 -Wno-deprecated-octal-literal" } #include <stdarg.h> diff --git a/gcc/testsuite/g++.dg/ext/va-arg-pack-len-2.C b/gcc/testsuite/g++.dg/ext/va-arg-pack-len-2.C index 0d369bdc9cb8..e83da749afca 100644 --- a/gcc/testsuite/g++.dg/ext/va-arg-pack-len-2.C +++ b/gcc/testsuite/g++.dg/ext/va-arg-pack-len-2.C @@ -1,5 +1,5 @@ // { dg-do compile } -// { dg-options "-O2" } +// { dg-options "-O2 -Wno-deprecated-octal-literal" } #include <stdarg.h> diff --git a/gcc/testsuite/g++.dg/ubsan/pr80349.C b/gcc/testsuite/g++.dg/ubsan/pr80349.C index f705b92caff2..c5bba759c342 100644 --- a/gcc/testsuite/g++.dg/ubsan/pr80349.C +++ b/gcc/testsuite/g++.dg/ubsan/pr80349.C @@ -1,6 +1,6 @@ // PR sanitizer/80349 // { dg-do compile } -// { dg-options "-fsanitize=undefined" } +// { dg-options "-fsanitize=undefined -Wno-deprecated-octal-literal" } extern const long long int v; diff --git a/gcc/testsuite/g++.dg/vect/pr95297.cc b/gcc/testsuite/g++.dg/vect/pr95297.cc index 6ffc92e5fd04..10ec526bd840 100644 --- a/gcc/testsuite/g++.dg/vect/pr95297.cc +++ b/gcc/testsuite/g++.dg/vect/pr95297.cc @@ -1,5 +1,5 @@ // { dg-do compile } -// { dg-additional-options "-O3 -fvect-cost-model=dynamic" } +// { dg-additional-options "-O3 -fvect-cost-model=dynamic -Wno-deprecated-octal-literal" } extern bool var_10; extern int var_16; diff --git a/gcc/testsuite/g++.dg/vect/pr98064.cc b/gcc/testsuite/g++.dg/vect/pr98064.cc index 74043ce77250..489ae6cf98e5 100644 --- a/gcc/testsuite/g++.dg/vect/pr98064.cc +++ b/gcc/testsuite/g++.dg/vect/pr98064.cc @@ -1,5 +1,5 @@ // { dg-do compile } -// { dg-additional-options "-O3" } +// { dg-additional-options "-O3 -Wno-deprecated-octal-literal" } const long long &min(const long long &__a, long long &__b) { if (__b < __a) diff --git a/gcc/testsuite/g++.dg/warn/pr13358-3.C b/gcc/testsuite/g++.dg/warn/pr13358-3.C index 7ae0e2361673..6ea045220206 100644 --- a/gcc/testsuite/g++.dg/warn/pr13358-3.C +++ b/gcc/testsuite/g++.dg/warn/pr13358-3.C @@ -11,7 +11,7 @@ void use_longlong () // make sure it's ok with hex, decimal and octal x1 = 0x1b27da572ef3cd86; x2 = 1956772631100509574; - x3 = 0154476645345674746606; + x3 = 0154476645345674746606; // { dg-warning "octal literals without '0o' or '0O' prefix other than '0' are deprecated" "" { target c++29 } } } void use_longlong2 () @@ -20,5 +20,5 @@ void use_longlong2 () // make sure it's ok with hex, decimal and octal x1 = 0x1b27da572ef3cd86LL; x2 = 1956772631100509574LL; - x3 = 0154476645345674746606LL; + x3 = 0154476645345674746606LL; // { dg-warning "octal literals without '0o' or '0O' prefix other than '0' are deprecated" "" { target c++29 } } } diff --git a/gcc/testsuite/g++.dg/warn/pr13358-4.C b/gcc/testsuite/g++.dg/warn/pr13358-4.C index 3aaeb8573e44..4fb32f46cd3c 100644 --- a/gcc/testsuite/g++.dg/warn/pr13358-4.C +++ b/gcc/testsuite/g++.dg/warn/pr13358-4.C @@ -12,7 +12,7 @@ void use_longlong () x1 = 0x1b27da572ef3cd86; // { dg-warning "integer constant is too large for 'long' type" "long long" { target { llp64 || ilp32 } } } x2 = 1956772631100509574; // { dg-warning "integer constant is too large for 'long' type" "long long" { target { llp64 || ilp32 } } } x3 = 0154476645345674746606; // { dg-warning "integer constant is too large for 'long' type" "long long" { target { llp64 || ilp32 } } } -} +} // { dg-warning "octal literals without '0o' or '0O' prefix other than '0' are deprecated" "" { target c++29 } .-1 } void use_longlong2 () { @@ -21,4 +21,4 @@ void use_longlong2 () x1 = 0x1b27da572ef3cd86LL; // { dg-warning "long long" } x2 = 1956772631100509574LL; // { dg-warning "long long" } x3 = 0154476645345674746606LL; // { dg-warning "long long" } -} +} // { dg-warning "octal literals without '0o' or '0O' prefix other than '0' are deprecated" "" { target c++29 } .-1 } diff --git a/gcc/testsuite/g++.old-deja/g++.law/enum2.C b/gcc/testsuite/g++.old-deja/g++.law/enum2.C index 47ad7fb0597e..db9c684bbd54 100644 --- a/gcc/testsuite/g++.old-deja/g++.law/enum2.C +++ b/gcc/testsuite/g++.old-deja/g++.law/enum2.C @@ -1,5 +1,5 @@ // { dg-do assemble } -// { dg-options "-fshort-enums" } +// { dg-options "-fshort-enums -Wno-deprecated-octal-literal" } // GROUPS passed enums // enum file // From: Jeff Gehlhaar <[email protected]> diff --git a/gcc/testsuite/g++.old-deja/g++.mike/p811.C b/gcc/testsuite/g++.old-deja/g++.mike/p811.C index ee207151a29b..6b5408951dcd 100644 --- a/gcc/testsuite/g++.old-deja/g++.mike/p811.C +++ b/gcc/testsuite/g++.old-deja/g++.mike/p811.C @@ -1,5 +1,5 @@ // { dg-do assemble } -// { dg-options "-Wno-builtin-declaration-mismatch" } +// { dg-options "-Wno-builtin-declaration-mismatch -Wno-deprecated-octal-literal" } // This test case caused the compiler to abort at one point in time. // prms-id: 811 diff --git a/gcc/testsuite/g++.old-deja/g++.niklas/t119.C b/gcc/testsuite/g++.old-deja/g++.niklas/t119.C index 8b411d8ee763..219846f49de1 100644 --- a/gcc/testsuite/g++.old-deja/g++.niklas/t119.C +++ b/gcc/testsuite/g++.old-deja/g++.niklas/t119.C @@ -2,5 +2,5 @@ // GROUPS passed niklas i386 unsigned long foo(unsigned long x) { - return x & ~0104000; + return x & ~0104000; // { dg-warning "octal literals without '0o' or '0O' prefix other than '0' are deprecated" "" { target c++29 } } } diff --git a/gcc/testsuite/g++.old-deja/g++.other/mutable1.C b/gcc/testsuite/g++.old-deja/g++.other/mutable1.C index 0b2dd8d8edae..061bb99708be 100644 --- a/gcc/testsuite/g++.old-deja/g++.other/mutable1.C +++ b/gcc/testsuite/g++.old-deja/g++.other/mutable1.C @@ -1,4 +1,5 @@ -// { dg-do run } +// { dg-do run } +// { dg-additional-options "-Wno-deprecated-octal-literal" { target c++29 } } // Copyright (C) 1999 Free Software Foundation, Inc. // Contributed by Nathan Sidwell 14 Jan 1999 <[email protected]> diff --git a/libcpp/expr.cc b/libcpp/expr.cc index b99bd7076db3..5be6b47df4e2 100644 --- a/libcpp/expr.cc +++ b/libcpp/expr.cc @@ -920,6 +920,28 @@ cpp_classify_number (cpp_reader *pfile, const cpp_token *token, } } + if (radix == 8 + && CPP_OPTION (pfile, cpp_warn_deprecated_octal_literal) + && !zero_o_prefix + && str > token->val.str.text + 1) + { + bool warned + = (CPP_OPTION (pfile, cplusplus) + ? cpp_warning_with_line (pfile, CPP_W_DEPRECATED_OCTAL_LITERAL, + virtual_location, 0, + "octal literals without %<0o%> or " + "%<0O%> prefix other than %<0%> are " + "deprecated in C++29") + : cpp_warning_with_line (pfile, CPP_W_DEPRECATED_OCTAL_LITERAL, + virtual_location, 0, + "octal literals without %<0o%> or " + "%<0O%> prefix other than %<0%> are " + "deprecated in C2Y")); + if (warned) + cpp_error_with_line (pfile, CPP_DL_NOTE, virtual_location, 0, + "use %<0o%> or %<0O%> prefix instead"); + } + result |= CPP_N_INTEGER; } diff --git a/libcpp/include/cpplib.h b/libcpp/include/cpplib.h index 8cef2b30d0f7..0b7426440d88 100644 --- a/libcpp/include/cpplib.h +++ b/libcpp/include/cpplib.h @@ -637,6 +637,9 @@ struct cpp_options /* -Wtrailing-whitespace= value. */ unsigned char cpp_warn_trailing_whitespace; + /* Nonzero means complain about deprecated octal literals. */ + unsigned char cpp_warn_deprecated_octal_literal; + /* -ftabstop= value. */ unsigned int cpp_tabstop; @@ -770,7 +773,8 @@ enum cpp_warning_reason { CPP_W_PRAGMA_ONCE_OUTSIDE_HEADER, CPP_W_LEADING_WHITESPACE, CPP_W_TRAILING_WHITESPACE, - CPP_W_KEYWORD_MACRO + CPP_W_KEYWORD_MACRO, + CPP_W_DEPRECATED_OCTAL_LITERAL }; /* Callback for header lookup for HEADER, which is the name of a diff --git a/libstdc++-v3/include/bits/fs_fwd.h b/libstdc++-v3/include/bits/fs_fwd.h index dea8599d2a10..164227146edf 100644 --- a/libstdc++-v3/include/bits/fs_fwd.h +++ b/libstdc++-v3/include/bits/fs_fwd.h @@ -141,6 +141,8 @@ _GLIBCXX_END_NAMESPACE_CXX11 /// Bitmask type representing file access permissions +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-octal-literal" enum class perms : unsigned { none = 0, owner_read = 0400, @@ -162,6 +164,7 @@ _GLIBCXX_END_NAMESPACE_CXX11 mask = 07777, unknown = 0xFFFF, }; +#pragma GCC diagnostic pop /// @{ /// @relates perms diff --git a/libstdc++-v3/include/experimental/bits/fs_fwd.h b/libstdc++-v3/include/experimental/bits/fs_fwd.h index ccc624c10f6c..cba92e08c332 100644 --- a/libstdc++-v3/include/experimental/bits/fs_fwd.h +++ b/libstdc++-v3/include/experimental/bits/fs_fwd.h @@ -151,6 +151,8 @@ _GLIBCXX_END_NAMESPACE_CXX11 /// @} /// Bitmask type representing file access permissions +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-octal-literal" enum class perms : unsigned { none = 0, owner_read = 0400, @@ -175,6 +177,7 @@ _GLIBCXX_END_NAMESPACE_CXX11 remove_perms = 0x20000, symlink_nofollow = 0x40000 }; +#pragma GCC diagnostic pop /// @{ /// @relates std::experimental::filesystem::perms diff --git a/libstdc++-v3/include/std/charconv b/libstdc++-v3/include/std/charconv index c2767a8671cc..74bade6b4261 100644 --- a/libstdc++-v3/include/std/charconv +++ b/libstdc++-v3/include/std/charconv @@ -248,12 +248,21 @@ namespace __detail if constexpr (__gnu_cxx::__int_traits<_Tp>::__digits <= 16) { +#if __cpp_0o_octals >= 202611L + __len = __val > 0o77777u ? 6u + : __val > 0o7777u ? 5u + : __val > 0o777u ? 4u + : __val > 0o77u ? 3u + : __val > 0o7u ? 2u + : 1u; +#else __len = __val > 077777u ? 6u : __val > 07777u ? 5u : __val > 0777u ? 4u : __val > 077u ? 3u : __val > 07u ? 2u : 1u; +#endif } else __len = (__to_chars_len_2(__val) + 2) / 3; @@ -266,7 +275,7 @@ namespace __detail } unsigned __pos = __len - 1; - while (__val >= 0100) + while (__val >= 8 * 8) { auto __num = __val & 7; __val >>= 3; @@ -276,7 +285,7 @@ namespace __detail __first[__pos - 1] = '0' + __num; __pos -= 2; } - if (__val >= 010) + if (__val >= 8) { auto const __num = __val & 7; __val >>= 3; diff --git a/libstdc++-v3/testsuite/20_util/to_chars/constexpr.cc b/libstdc++-v3/testsuite/20_util/to_chars/constexpr.cc index 86b01ee30535..df0761caf9bf 100644 --- a/libstdc++-v3/testsuite/20_util/to_chars/constexpr.cc +++ b/libstdc++-v3/testsuite/20_util/to_chars/constexpr.cc @@ -80,13 +80,25 @@ test_base8() { std::to_chars_result res; char buf[10] = "XXXXXXXXX"; +#if __cpp_0o_octals >= 202611L + res = std::to_chars(buf, buf+2, 0o1234, 8); +#else res = std::to_chars(buf, buf+2, 01234, 8); +#endif VERIFY( res.ptr == buf+2 ); VERIFY( res.ec == std::errc::value_too_large ); +#if __cpp_0o_octals >= 202611L + res = std::to_chars(buf, buf+3, -0o1234, 8); +#else res = std::to_chars(buf, buf+3, -01234, 8); +#endif VERIFY( res.ptr == buf+3 ); VERIFY( res.ec == std::errc::value_too_large ); +#if __cpp_0o_octals >= 202611L + res = std::to_chars(buf, buf+4, 0o1234, 8); +#else res = std::to_chars(buf, buf+4, 01234, 8); +#endif VERIFY( res.ptr == buf+4 ); VERIFY( res.ec == std::errc{} ); VERIFY( buf[0] == '1' ); @@ -94,7 +106,11 @@ test_base8() VERIFY( buf[2] == '3' ); VERIFY( buf[3] == '4' ); VERIFY( buf[4] == 'X' ); +#if __cpp_0o_octals >= 202611L + res = std::to_chars(buf, buf+10, -0o567, 8); +#else res = std::to_chars(buf, buf+10, -0567, 8); +#endif VERIFY( res.ptr == buf+4 ); VERIFY( res.ec == std::errc{} ); VERIFY( buf[0] == '-' ); diff --git a/libstdc++-v3/testsuite/23_containers/mdspan/layouts/stride_neg.cc b/libstdc++-v3/testsuite/23_containers/mdspan/layouts/stride_neg.cc index 5a818042b5ab..487808bca329 100644 --- a/libstdc++-v3/testsuite/23_containers/mdspan/layouts/stride_neg.cc +++ b/libstdc++-v3/testsuite/23_containers/mdspan/layouts/stride_neg.cc @@ -71,16 +71,16 @@ constexpr auto m20 = mapping<4>(array{3, 4, 5, 6}, array{1, 5, 12, 60}); // { d // Any stride values are allowed for extents 1 constexpr auto m21 = mapping<2>(array{1, 1}, array{88, 99}); // { dg-bogus "expansion of" } constexpr auto m2a = mapping<2>(array{5, 1}, array{88, 99}); // { dg-bogus "expansion of" } -constexpr auto m22 = mapping<3>(array{1, 1, 1}, array{88, 99, 00}); // { dg-bogus "expansion of" } +constexpr auto m22 = mapping<3>(array{1, 1, 1}, array{88, 99, 0}); // { dg-bogus "expansion of" } constexpr auto m2b = mapping<3>(array{1, 5, 1}, array{88, 99, 77}); // { dg-bogus "expansion of" } -constexpr auto m23 = mapping<4>(array{1, 1, 1, 1}, array{77, 99, 00, 88}); // { dg-bogus "expansion of" } +constexpr auto m23 = mapping<4>(array{1, 1, 1, 1}, array{77, 99, 0, 88}); // { dg-bogus "expansion of" } constexpr auto m2c = mapping<4>(array{1, 1, 5, 1}, array{77, 99, 1, 88}); // { dg-bogus "expansion of" } constexpr auto m24 = mapping<5>(array{3, 4, 1, 1, 5}, array{3, 10, 3, 3, 45}); // { dg-bogus "expansion of" } constexpr auto m25 = mapping<5>(array{3, 4, 1, 1, 5}, array{3, 10, 3, 10, 45}); // { dg-bogus "expansion of" } constexpr auto m26 = mapping<5>(array{3, 4, 1, 1, 5}, array{3, 10, 10, 3, 45}); // { dg-bogus "expansion of" } constexpr auto m27 = mapping<5>(array{3, 4, 1, 1, 5}, array{3, 10, 10, 10, 45}); // { dg-bogus "expansion of" } -constexpr auto m2d = mapping<5>(array{3, 4, 1, 1, 5}, array{3, 10, 00, 99, 45}); // { dg-bogus "expansion of" } -constexpr auto m2e = mapping<5>(array{1, 1, 1, 1, 1}, array{00, 77, 88, 99, 00}); // { dg-bogus "expansion of" } +constexpr auto m2d = mapping<5>(array{3, 4, 1, 1, 5}, array{3, 10, 0, 99, 45}); // { dg-bogus "expansion of" } +constexpr auto m2e = mapping<5>(array{1, 1, 1, 1, 1}, array{0, 77, 88, 99, 0}); // { dg-bogus "expansion of" } // { dg-prune-output "non-constant condition for static assertion" } // { dg-prune-output "__glibcxx_assert_fail()" } diff --git a/libstdc++-v3/testsuite/std/time/format/pr120114.cc b/libstdc++-v3/testsuite/std/time/format/pr120114.cc index c9ec16904079..806c1e137a77 100644 --- a/libstdc++-v3/testsuite/std/time/format/pr120114.cc +++ b/libstdc++-v3/testsuite/std/time/format/pr120114.cc @@ -16,7 +16,7 @@ test_from_format_string() { std::basic_string<CharT> res; using namespace std::chrono_literals; - auto date = 2025y/std::chrono::May/05d; + auto date = 2025y/std::chrono::May/05d; // { dg-warning "octal literals without '0o' or '0O' prefix other than '0' are deprecated" "" { target c++29 } } res = std::format(WIDEN("{:+<13%F\U0001f921}"), date); VERIFY( res == WIDEN("2025-05-05\U0001f921+") );
