https://gcc.gnu.org/g:8be369dce1c33033dfa4efbd3071cc1082b4a87f
commit r17-6553-g8be369dce1c33033dfa4efbd3071cc1082b4a87f Author: Jakub Jelinek <[email protected]> Date: Sat Nov 21 13:50:39 2026 +0100 c++: Partially implement P0085R5 - Oo... adding a coherent character sequence to begin octal-literals The following patch partially implements the C++29 P0085R5 - Oo... adding a coherent character sequence to begin octal-literals paper. The partial word is there because it doesn't add any deprecation for the 000 and 042 etc. literals, only adds support for the new 0o42 and 0O42 literals. Deprecation will be done in a separate patch. Yes, this is a new feature for C++, but as the patch shows, except for the testcase it is just a few lines, because all the support is already there, just restricted to C until now. 2026-11-21 Jakub Jelinek <[email protected]> P0085R5 gcc/c-family/ * c-cppbuiltin.cc (c_cpp_builtins): Predefine __cpp_0o_octals for C++29. gcc/testsuite/ * g++.dg/DRs/dr2581-1.C: Add __cpp_0o_octals test. * g++.dg/DRs/dr2581-2.C: Likewise. * g++.dg/cpp29/feat-cxx29.C: Likewise. * g++.dg/cpp29/octal1.C: New test. * g++.dg/cpp29/octal2.C: New test. * g++.dg/cpp29/octal3.C: New test. * g++.dg/cpp29/octal4.C: New test. libcpp/ * init.cc (lang_defaults): Set octal_constants for C++29. * expr.cc (cpp_classify_number): Parse 0o and 0O prefixes even for C++. Emit different diagnostics for C++ if octal_constants is false. Reviewed-by: Jason Merrill <[email protected]> Diff: --- gcc/c-family/c-cppbuiltin.cc | 1 + gcc/testsuite/g++.dg/DRs/dr2581-1.C | 1 + gcc/testsuite/g++.dg/DRs/dr2581-2.C | 1 + gcc/testsuite/g++.dg/cpp29/feat-cxx29.C | 6 ++ gcc/testsuite/g++.dg/cpp29/octal1.C | 104 +++++++++++++++++++++++++++++++ gcc/testsuite/g++.dg/cpp29/octal2.C | 5 ++ gcc/testsuite/g++.dg/cpp29/octal3.C | 105 ++++++++++++++++++++++++++++++++ gcc/testsuite/g++.dg/cpp29/octal4.C | 9 +++ libcpp/expr.cc | 20 ++++-- libcpp/init.cc | 4 +- 10 files changed, 249 insertions(+), 7 deletions(-) diff --git a/gcc/c-family/c-cppbuiltin.cc b/gcc/c-family/c-cppbuiltin.cc index 2c68681a3684..116408a1eced 100644 --- a/gcc/c-family/c-cppbuiltin.cc +++ b/gcc/c-family/c-cppbuiltin.cc @@ -1138,6 +1138,7 @@ c_cpp_builtins (cpp_reader *pfile) /* Set feature test macros for C++29. */ cpp_define (pfile, "__cpp_pp_embed=202606L"); cpp_define (pfile, "__cpp_designated_initializers=202606L"); + cpp_define (pfile, "__cpp_0o_octals=202611L"); } if (flag_concepts && cxx_dialect > cxx14) { diff --git a/gcc/testsuite/g++.dg/DRs/dr2581-1.C b/gcc/testsuite/g++.dg/DRs/dr2581-1.C index 7298f3162b5b..7cd109b1da79 100644 --- a/gcc/testsuite/g++.dg/DRs/dr2581-1.C +++ b/gcc/testsuite/g++.dg/DRs/dr2581-1.C @@ -25,6 +25,7 @@ #undef __STDC_ISO_10646__ // { dg-warning "undefining '__STDC_ISO_10646__'" "" { xfail { ! *-*-linux* } } } #undef __STDCPP_THREADS__ // { dg-warning "undefining '__STDCPP_THREADS__'" "" { target c++11 } } #undef __STDCPP_STRICT_POINTER_SAFETY__ // { dg-warning "undefining '__STDCPP_STRICT_POINTER_SAFETY__'" "" { target { c++11 && c++20_down } } } +#undef __cpp_0o_octals // { dg-warning "undefining '__cpp_0o_octals'" "" { target c++29 } } #undef __cpp_aggregate_bases // { dg-warning "undefining '__cpp_aggregate_bases'" "" { target c++20 } } #undef __cpp_aggregate_nsdmi // { dg-warning "undefining '__cpp_aggregate_nsdmi'" "" { target c++20 } } #undef __cpp_aggregate_paren_init // { dg-warning "undefining '__cpp_aggregate_paren_init'" "" { target c++20 } } diff --git a/gcc/testsuite/g++.dg/DRs/dr2581-2.C b/gcc/testsuite/g++.dg/DRs/dr2581-2.C index 45d1d823adea..9d4330904c9c 100644 --- a/gcc/testsuite/g++.dg/DRs/dr2581-2.C +++ b/gcc/testsuite/g++.dg/DRs/dr2581-2.C @@ -26,6 +26,7 @@ #define __STDC_ISO_10646__ // { dg-error "'__STDC_ISO_10646__' redefined" "" { xfail { ! *-*-linux* } } } #define __STDCPP_THREADS__ // { dg-message "'__STDCPP_THREADS__' (?:re)?defined" "" { target c++11 } } #define __STDCPP_STRICT_POINTER_SAFETY__ // { dg-warning "'__STDCPP_STRICT_POINTER_SAFETY__' defined" "" { target { c++11 && c++20_down } } } +#define __cpp_0o_octals 202611L // { dg-error "'__cpp_0o_octals' redefined" "" { target c++29 } } #define __cpp_aggregate_bases 201603L // { dg-error "'__cpp_aggregate_bases' redefined" "" { target c++20 } } #define __cpp_aggregate_nsdmi 201304L // { dg-error "'__cpp_aggregate_nsdmi' redefined" "" { target c++20 } } #define __cpp_aggregate_paren_init 201902L // { dg-error "'__cpp_aggregate_paren_init' redefined" "" { target c++20 } } diff --git a/gcc/testsuite/g++.dg/cpp29/feat-cxx29.C b/gcc/testsuite/g++.dg/cpp29/feat-cxx29.C index cb20e0488b40..d8aa256fdaee 100644 --- a/gcc/testsuite/g++.dg/cpp29/feat-cxx29.C +++ b/gcc/testsuite/g++.dg/cpp29/feat-cxx29.C @@ -670,3 +670,9 @@ #else # error "__has_cpp_attribute" #endif + +#ifndef __cpp_0o_octals +# error "__cpp_0o_octals" +#elif __cpp_0o_octals != 202611 +# error "__cpp_0o_octals != 202611" +#endif diff --git a/gcc/testsuite/g++.dg/cpp29/octal1.C b/gcc/testsuite/g++.dg/cpp29/octal1.C new file mode 100644 index 000000000000..f5c15c8fc04f --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp29/octal1.C @@ -0,0 +1,104 @@ +// P0085R5 - Oo... adding a coherent character sequence to begin octal-literals +// { dg-do compile { target c++11 } } + +template <typename T, typename U> +struct is_same { static constexpr bool value = false; }; +template <typename T> +struct is_same <T, T> { static constexpr bool value = true; }; +auto a = 0O4; // { dg-error "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (is_same <decltype (a), int>::value, ""); +auto b = 0O777U; // { dg-error "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (is_same <decltype (b), unsigned>::value, ""); +auto c = 0O4l; // { dg-error "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (is_same <decltype (c), long>::value, ""); +auto d = 0O777UL; // { dg-error "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (is_same <decltype (d), unsigned long>::value, ""); +auto e = 0O4LL; // { dg-error "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (is_same <decltype (e), long long>::value, ""); +auto f = 0O123456701234567ull; // { dg-error "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (is_same <decltype (f), unsigned long long>::value, ""); +#if 0o107 // { dg-error "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +#endif +#if 0O107 // { dg-error "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +#endif +#if 0o107 != 0x47 // { dg-error "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +#error +#endif +#if 0O13507 != 5959 // { dg-error "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +#error +#endif +static_assert (0o1 == 0x1, ""); // { dg-error "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0O2 == 0x2, ""); // { dg-error "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0o3 == 0x3, ""); // { dg-error "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0O4 == 0x4, ""); // { dg-error "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0o7U == 0x7U, ""); // { dg-error "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0O10 == 0x8, ""); // { dg-error "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0o17 == 0xf, ""); // { dg-error "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0O20L == 0x10L, ""); // { dg-error "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0o37 == 0x1f, ""); // { dg-error "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0O40 == 0x20, ""); // { dg-error "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0o77 == 0x3f, ""); // { dg-error "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0O100 == 0x40, ""); // { dg-error "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0o177 == 0x7f, ""); // { dg-error "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0O200 == 0x80, ""); // { dg-error "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0o377 == 0xff, ""); // { dg-error "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0O400u == 0x100u, ""); // { dg-error "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0o777 == 0x1ff, ""); // { dg-error "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0O1000 == 0x200, ""); // { dg-error "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0o1777 == 0x3ff, ""); // { dg-error "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0O2000 == 0x400, ""); // { dg-error "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0o3777 == 0x7ff, ""); // { dg-error "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0O4000U == 0x800U, ""); // { dg-error "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0o7777u == 0xfffu, ""); // { dg-error "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0O10000L == 0x1000L, ""); // { dg-error "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0o17777l == 0x1fffl, ""); // { dg-error "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0O20000UL == 0x2000UL, ""); // { dg-error "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0o37777ULL == 0x3fffULL, ""); // { dg-error "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0O40000L == 0x4000L, ""); // { dg-error "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0o77777 == 0x7fff, ""); // { dg-error "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0O100000U == 0x8000U, ""); // { dg-error "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0o177777L == 0xffffL, ""); // { dg-error "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0O200000UL == 0x10000UL, ""); // { dg-error "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0o377777L == 0x1ffffL, ""); // { dg-error "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0O400000l == 0x20000l, ""); // { dg-error "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0o777777UL == 0x3ffffUL, ""); // { dg-error "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0O1000000L == 0x40000L, ""); // { dg-error "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0o1777777l == 0x7ffffl, ""); // { dg-error "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0O2000000L == 0x80000L, ""); // { dg-error "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0o3777777UL == 0xfffffUL, ""); // { dg-error "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0O4000000l == 0x100000l, ""); // { dg-error "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0o7777777UL == 0x1fffffUL, ""); // { dg-error "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0O10000000L == 0x200000L, ""); // { dg-error "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0o17777777l == 0x3fffffl, ""); // { dg-error "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0O20000000ULL == 0x400000ULL, ""); // { dg-error "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0o37777777UL == 0x7fffffUL, ""); // { dg-error "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0O40000000L == 0x800000L, ""); // { dg-error "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +#if __cplusplus >= 201402L +static_assert (0o7'7'7'7'7'7'77l == 0xffffffl, ""); // { dg-error "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target { c++14 && c++26_down } } } +static_assert (0O10'00'00'00'0L == 0x1000000L, ""); // { dg-error "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target { c++14 && c++26_down } } } +static_assert (0o1'77'77'77'77UL == 0x1ffffffUL, ""); // { dg-error "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target { c++14 && c++26_down } } } +static_assert (0O200'000'000L == 0x2000000L, ""); // { dg-error "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target { c++14 && c++26_down } } } +static_assert (0o3'777'7'7'7'7'7L == 0x3ffffffL, ""); // { dg-error "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target { c++14 && c++26_down } } } +#endif +static_assert (0O400000000UL == 0x4000000UL, ""); // { dg-error "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0o777777777L == 0x7ffffffL, ""); // { dg-error "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0O1000000000l == 0x8000000l, ""); // { dg-error "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0o1777777777UL == 0xfffffffUL, ""); // { dg-error "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0O2000000000L == 0x10000000L, ""); // { dg-error "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0o3777777777L == 0x1fffffffL, ""); // { dg-error "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0O4000000000UL == 0x20000000UL, ""); // { dg-error "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0o7777777777UL == 0x3fffffffUL, ""); // { dg-error "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0O10000000000l == 0x40000000l, ""); // { dg-error "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0o17777777777L == 0x7fffffffL, ""); // { dg-error "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0O20000000000UL == 0x80000000UL, ""); // { dg-error "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0O25053250513UL == 0xa8ad514bUL, ""); // { dg-error "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0o37777777777ul == 0xfffffffful, ""); // { dg-error "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0O40000000000LL == 0x100000000LL, ""); // { dg-error "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0o77777777777ll == 0x1ffffffffll, ""); // { dg-error "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0O100000000000LL == 0x200000000LL, ""); // { dg-error "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0o177777777777ULL == 0x3ffffffffULL, ""); // { dg-error "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0O200000000000ll == 0x400000000ll, ""); // { dg-error "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0o777777777777777777777LL == 0x7fffffffffffffffLL, ""); // { dg-error "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0O1000000000000000000000ULL == 0x8000000000000000ULL, ""); // { dg-error "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0O1011617105572074461270ULL == 0x8271e45bd0f262b8ULL, ""); // { dg-error "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0o1777777777777777777777ULL == 0xffffffffffffffffULL, ""); // { dg-error "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } diff --git a/gcc/testsuite/g++.dg/cpp29/octal2.C b/gcc/testsuite/g++.dg/cpp29/octal2.C new file mode 100644 index 000000000000..154652b73c1a --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp29/octal2.C @@ -0,0 +1,5 @@ +// P0085R5 - Oo... adding a coherent character sequence to begin octal-literals +// { dg-do compile { target c++11 } } +// { dg-options "" } + +#include "octal1.C" diff --git a/gcc/testsuite/g++.dg/cpp29/octal3.C b/gcc/testsuite/g++.dg/cpp29/octal3.C new file mode 100644 index 000000000000..6d7b10e06cbc --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp29/octal3.C @@ -0,0 +1,105 @@ +// P0085R5 - Oo... adding a coherent character sequence to begin octal-literals +// { dg-do compile { target c++11 } } +// { dg-options "-pedantic" } + +template <typename T, typename U> +struct is_same { static constexpr bool value = false; }; +template <typename T> +struct is_same <T, T> { static constexpr bool value = true; }; +auto a = 0O4; // { dg-warning "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (is_same <decltype (a), int>::value, ""); +auto b = 0O777U; // { dg-warning "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (is_same <decltype (b), unsigned>::value, ""); +auto c = 0O4l; // { dg-warning "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (is_same <decltype (c), long>::value, ""); +auto d = 0O777UL; // { dg-warning "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (is_same <decltype (d), unsigned long>::value, ""); +auto e = 0O4LL; // { dg-warning "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (is_same <decltype (e), long long>::value, ""); +auto f = 0O123456701234567ull; // { dg-warning "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (is_same <decltype (f), unsigned long long>::value, ""); +#if 0o107 // { dg-warning "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +#endif +#if 0O107 // { dg-warning "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +#endif +#if 0o107 != 0x47 // { dg-warning "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +#error +#endif +#if 0O13507 != 5959 // { dg-warning "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +#error +#endif +static_assert (0o1 == 0x1, ""); // { dg-warning "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0O2 == 0x2, ""); // { dg-warning "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0o3 == 0x3, ""); // { dg-warning "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0O4 == 0x4, ""); // { dg-warning "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0o7U == 0x7U, ""); // { dg-warning "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0O10 == 0x8, ""); // { dg-warning "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0o17 == 0xf, ""); // { dg-warning "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0O20L == 0x10L, ""); // { dg-warning "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0o37 == 0x1f, ""); // { dg-warning "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0O40 == 0x20, ""); // { dg-warning "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0o77 == 0x3f, ""); // { dg-warning "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0O100 == 0x40, ""); // { dg-warning "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0o177 == 0x7f, ""); // { dg-warning "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0O200 == 0x80, ""); // { dg-warning "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0o377 == 0xff, ""); // { dg-warning "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0O400u == 0x100u, ""); // { dg-warning "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0o777 == 0x1ff, ""); // { dg-warning "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0O1000 == 0x200, ""); // { dg-warning "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0o1777 == 0x3ff, ""); // { dg-warning "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0O2000 == 0x400, ""); // { dg-warning "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0o3777 == 0x7ff, ""); // { dg-warning "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0O4000U == 0x800U, ""); // { dg-warning "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0o7777u == 0xfffu, ""); // { dg-warning "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0O10000L == 0x1000L, ""); // { dg-warning "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0o17777l == 0x1fffl, ""); // { dg-warning "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0O20000UL == 0x2000UL, ""); // { dg-warning "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0o37777ULL == 0x3fffULL, ""); // { dg-warning "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0O40000L == 0x4000L, ""); // { dg-warning "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0o77777 == 0x7fff, ""); // { dg-warning "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0O100000U == 0x8000U, ""); // { dg-warning "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0o177777L == 0xffffL, ""); // { dg-warning "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0O200000UL == 0x10000UL, ""); // { dg-warning "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0o377777L == 0x1ffffL, ""); // { dg-warning "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0O400000l == 0x20000l, ""); // { dg-warning "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0o777777UL == 0x3ffffUL, ""); // { dg-warning "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0O1000000L == 0x40000L, ""); // { dg-warning "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0o1777777l == 0x7ffffl, ""); // { dg-warning "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0O2000000L == 0x80000L, ""); // { dg-warning "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0o3777777UL == 0xfffffUL, ""); // { dg-warning "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0O4000000l == 0x100000l, ""); // { dg-warning "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0o7777777UL == 0x1fffffUL, ""); // { dg-warning "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0O10000000L == 0x200000L, ""); // { dg-warning "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0o17777777l == 0x3fffffl, ""); // { dg-warning "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0O20000000ULL == 0x400000ULL, ""); // { dg-warning "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0o37777777UL == 0x7fffffUL, ""); // { dg-warning "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0O40000000L == 0x800000L, ""); // { dg-warning "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +#if __cplusplus >= 201402L +static_assert (0o7'7'7'7'7'7'77l == 0xffffffl, ""); // { dg-warning "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target { c++14 && c++26_down } } } +static_assert (0O10'00'00'00'0L == 0x1000000L, ""); // { dg-warning "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target { c++14 && c++26_down } } } +static_assert (0o1'77'77'77'77UL == 0x1ffffffUL, ""); // { dg-warning "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target { c++14 && c++26_down } } } +static_assert (0O200'000'000L == 0x2000000L, ""); // { dg-warning "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target { c++14 && c++26_down } } } +static_assert (0o3'777'7'7'7'7'7L == 0x3ffffffL, ""); // { dg-warning "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target { c++14 && c++26_down } } } +#endif +static_assert (0O400000000UL == 0x4000000UL, ""); // { dg-warning "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0o777777777L == 0x7ffffffL, ""); // { dg-warning "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0O1000000000l == 0x8000000l, ""); // { dg-warning "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0o1777777777UL == 0xfffffffUL, ""); // { dg-warning "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0O2000000000L == 0x10000000L, ""); // { dg-warning "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0o3777777777L == 0x1fffffffL, ""); // { dg-warning "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0O4000000000UL == 0x20000000UL, ""); // { dg-warning "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0o7777777777UL == 0x3fffffffUL, ""); // { dg-warning "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0O10000000000l == 0x40000000l, ""); // { dg-warning "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0o17777777777L == 0x7fffffffL, ""); // { dg-warning "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0O20000000000UL == 0x80000000UL, ""); // { dg-warning "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0O25053250513UL == 0xa8ad514bUL, ""); // { dg-warning "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0o37777777777ul == 0xfffffffful, ""); // { dg-warning "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0O40000000000LL == 0x100000000LL, ""); // { dg-warning "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0o77777777777ll == 0x1ffffffffll, ""); // { dg-warning "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0O100000000000LL == 0x200000000LL, ""); // { dg-warning "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0o177777777777ULL == 0x3ffffffffULL, ""); // { dg-warning "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0O200000000000ll == 0x400000000ll, ""); // { dg-warning "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0o777777777777777777777LL == 0x7fffffffffffffffLL, ""); // { dg-warning "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0O1000000000000000000000ULL == 0x8000000000000000ULL, ""); // { dg-warning "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0O1011617105572074461270ULL == 0x8271e45bd0f262b8ULL, ""); // { dg-warning "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } +static_assert (0o1777777777777777777777ULL == 0xffffffffffffffffULL, ""); // { dg-warning "'0o' prefixed constants are a C\\\+\\\+29 feature or GCC extension" "" { target c++26_down } } diff --git a/gcc/testsuite/g++.dg/cpp29/octal4.C b/gcc/testsuite/g++.dg/cpp29/octal4.C new file mode 100644 index 000000000000..3ee84184f5c6 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp29/octal4.C @@ -0,0 +1,9 @@ +// P0085R5 - Oo... adding a coherent character sequence to begin octal-literals +// { dg-do compile { target c++14 } } +// { dg-options "" } + +int a = 0o; // { dg-error "unable to find numeric literal operator 'operator\"\"o'" } +int b = 0Oa; // { dg-error "unable to find numeric literal operator 'operator\"\"Oa'" } +int c = 0O08; // { dg-error "invalid digit" } +int d = 0o1.1; // { dg-error "invalid prefix" } +int e = 0O0p0; // { dg-error "unable to find numeric literal operator 'operator\"\"p0'" } diff --git a/libcpp/expr.cc b/libcpp/expr.cc index 1e2a7e30784f..b99bd7076db3 100644 --- a/libcpp/expr.cc +++ b/libcpp/expr.cc @@ -617,7 +617,7 @@ cpp_classify_number (cpp_reader *pfile, const cpp_token *token, SYNTAX_ERROR_AT (virtual_location, "digit separator after base indicator"); } - else if ((*str == 'o' || *str == 'O') && !CPP_OPTION (pfile, cplusplus)) + else if (*str == 'o' || *str == 'O') { if (ISDIGIT (str[1])) { @@ -969,10 +969,20 @@ cpp_classify_number (cpp_reader *pfile, const cpp_token *token, { bool warned = false; if (!CPP_OPTION (pfile, octal_constants) && CPP_PEDANTIC (pfile)) - warned - = cpp_pedwarning_with_line (pfile, CPP_W_PEDANTIC, virtual_location, - 0, "%<0o%> prefixed constants are a C2Y " - "feature or GCC extension"); + { + if (CPP_OPTION (pfile, cplusplus)) + warned + = cpp_pedwarning_with_line (pfile, CPP_W_CXX29_EXTENSIONS, + virtual_location, 0, + "%<0o%> prefixed constants are a " + "C++29 feature or GCC extension"); + else + warned + = cpp_pedwarning_with_line (pfile, CPP_W_PEDANTIC, + virtual_location, 0, + "%<0o%> prefixed constants are a " + "C2Y feature or GCC extension"); + } if (!warned && CPP_OPTION (pfile, cpp_warn_c23_c2y_compat) > 0) cpp_warning_with_line (pfile, CPP_W_C23_C2Y_COMPAT, virtual_location, 0, diff --git a/libcpp/init.cc b/libcpp/init.cc index 4b919a423cf0..87759dc217c6 100644 --- a/libcpp/init.cc +++ b/libcpp/init.cc @@ -151,8 +151,8 @@ static const struct lang_flags lang_defaults[] = { /* CXX23 */ { 1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,0,1,1,1,1,1,0,1,0,0,1 }, /* GNUCXX26 */ { 1,1,1,1,1,1,0,1,1,1,1,1,1,0,1,1,1,0,1,1,1,1,1,0,1,1,0,1 }, /* CXX26 */ { 1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,0,1,1,1,1,1,0,1,1,0,1 }, - /* GNUCXX29 */ { 1,1,1,1,1,1,0,1,1,1,1,1,1,0,1,1,1,0,1,1,1,1,1,0,1,1,0,1 }, - /* CXX29 */ { 1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,0,1,1,1,1,1,0,1,1,0,1 }, + /* GNUCXX29 */ { 1,1,1,1,1,1,0,1,1,1,1,1,1,0,1,1,1,0,1,1,1,1,1,1,1,1,0,1 }, + /* CXX29 */ { 1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,0,1,1,1,1,1,1,1,1,0,1 }, /* ASM */ { 0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } };
