diff options
author | Jakub Jelinek <jakub@redhat.com> | 2024-10-17 07:01:44 +0200 |
---|---|---|
committer | Jakub Jelinek <jakub@gcc.gnu.org> | 2024-10-17 07:01:44 +0200 |
commit | e020116db056352d9a7495e85d37e66c36f6ea32 (patch) | |
tree | 868b56e1cc8c6be01c4dadd38d9640b09907704b /gcc | |
parent | 96ba5e5663d4390a7e69735ce3c9de657fc543fc (diff) | |
download | gcc-e020116db056352d9a7495e85d37e66c36f6ea32.zip gcc-e020116db056352d9a7495e85d37e66c36f6ea32.tar.gz gcc-e020116db056352d9a7495e85d37e66c36f6ea32.tar.bz2 |
c, libcpp: Partially implement C2Y N3353 paper [PR117028]
The following patch partially implements the N3353 paper.
In particular, it adds support for the delimited escape sequences
(\u{123}, \x{123}, \o{123}) which were added already for C++23,
all I had to do is split the delimited escape sequence guarding from
named universal character escape sequence guards
(\N{LATIN CAPITAL LETTER C WITH CARON}), which C++23 has but C2Y doesn't
and emit different diagnostics for C from C++ for the delimited escape
sequences.
And it adds support for the new style of octal literals, 0o137 or 0O1777.
I have so far added that just for C and not C++, because I have no idea
whether C++ will want to handle it similarly.
What the patch doesn't do is any kind of diagnostics for obsoletion of
\137 or 0137, as discussed in the PR, I think it is way too early for that.
Perhaps some non-default warning later on.
2024-10-17 Jakub Jelinek <jakub@redhat.com>
PR c/117028
libcpp/
* include/cpplib.h (struct cpp_options): Add named_uc_escape_seqs,
octal_constants and cpp_warn_c23_c2y_compat members.
(enum cpp_warning_reason): Add CPP_W_C23_C2Y_COMPAT enumerator.
* init.cc (struct lang_flags): Add named_uc_escape_seqs and
octal_constants bit-fields.
(lang_defaults): Add initializers for them into the table.
(cpp_set_lang): Initialize named_uc_escape_seqs and octal_constants.
(cpp_create_reader): Initialize cpp_warn_c23_c2y_compat to -1.
* charset.cc (_cpp_valid_ucn): Test
CPP_OPTION (pfile, named_uc_escape_seqs) rather than
CPP_OPTION (pfile, delimited_escape_seqs) in \N{} related tests.
Change wording of C cpp_pedwarning for \u{} and emit
-Wc23-c2y-compat warning for it too if needed. Formatting fixes.
(convert_hex): Change wording of C cpp_pedwarning for \u{} and emit
-Wc23-c2y-compat warning for it too if needed.
(convert_oct): Likewise.
* expr.cc (cpp_classify_number): Handle C2Y 0o or 0O prefixed
octal constants.
(cpp_interpret_integer): Likewise.
gcc/c-family/
* c.opt (Wc23-c2y-compat): Add CPP and CppReason parameters.
* c-opts.cc (set_std_c2y): Use CLK_STDC2Y or CLK_GNUC2Y rather
than CLK_STDC23 and CLK_GNUC23. Formatting fix.
* c-lex.cc (interpret_integer): Handle C2Y 0o or 0O prefixed
and wb/WB/uwb/UWB suffixed octal constants.
gcc/testsuite/
* gcc.dg/bitint-112.c: New test.
* gcc.dg/c23-digit-separators-1.c: Add _Static_assert for
valid binary constant with digit separator.
* gcc.dg/c23-octal-constants-1.c: New test.
* gcc.dg/c23-octal-constants-2.c: New test.
* gcc.dg/c2y-digit-separators-1.c: New test.
* gcc.dg/c2y-digit-separators-2.c: New test.
* gcc.dg/c2y-octal-constants-1.c: New test.
* gcc.dg/c2y-octal-constants-2.c: New test.
* gcc.dg/c2y-octal-constants-3.c: New test.
* gcc.dg/cpp/c23-delimited-escape-seq-1.c: New test.
* gcc.dg/cpp/c23-delimited-escape-seq-2.c: New test.
* gcc.dg/cpp/c2y-delimited-escape-seq-1.c: New test.
* gcc.dg/cpp/c2y-delimited-escape-seq-2.c: New test.
* gcc.dg/cpp/c2y-delimited-escape-seq-3.c: New test.
* gcc.dg/cpp/c2y-delimited-escape-seq-4.c: New test.
* gcc.dg/octal-constants-1.c: New test.
* gcc.dg/octal-constants-2.c: New test.
* gcc.dg/octal-constants-3.c: New test.
* gcc.dg/octal-constants-4.c: New test.
* gcc.dg/system-octal-constants-1.c: New test.
* gcc.dg/system-octal-constants-1.h: New file.
Diffstat (limited to 'gcc')
24 files changed, 760 insertions, 2 deletions
diff --git a/gcc/c-family/c-lex.cc b/gcc/c-family/c-lex.cc index fa46455..f7168ce 100644 --- a/gcc/c-family/c-lex.cc +++ b/gcc/c-family/c-lex.cc @@ -941,6 +941,10 @@ interpret_integer (const cpp_token *token, unsigned int flags, { max_bits_per_digit = 3; prefix_len = 1; + if (token->val.str.len > 2 + && (token->val.str.text[1] == 'o' + || token->val.str.text[1] == 'O')) + prefix_len = 2; } else if ((flags & CPP_N_RADIX) == CPP_N_HEX) { diff --git a/gcc/c-family/c-opts.cc b/gcc/c-family/c-opts.cc index 21ed7c7..afb963d 100644 --- a/gcc/c-family/c-opts.cc +++ b/gcc/c-family/c-opts.cc @@ -1892,7 +1892,7 @@ set_std_c23 (int iso) static void set_std_c2y (int iso) { - cpp_set_lang (parse_in, iso ? CLK_STDC23: CLK_GNUC23); + cpp_set_lang (parse_in, iso ? CLK_STDC2Y : CLK_GNUC2Y); flag_no_asm = iso; flag_no_nonansi_builtin = iso; flag_iso = iso; diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt index f758d7b..d5608ec 100644 --- a/gcc/c-family/c.opt +++ b/gcc/c-family/c.opt @@ -452,7 +452,7 @@ C ObjC Alias(Wc11-c23-compat) Deprecated in favor of -Wc11-c23-compat. Wc23-c2y-compat -C ObjC Var(warn_c23_c2y_compat) Init(-1) Warning +C ObjC CPP(cpp_warn_c23_c2y_compat) CppReason(CPP_W_C23_C2Y_COMPAT) Var(warn_c23_c2y_compat) Init(-1) Warning Warn about features not present in ISO C23, but present in ISO C2Y. Wc90-c99-compat diff --git a/gcc/testsuite/gcc.dg/bitint-112.c b/gcc/testsuite/gcc.dg/bitint-112.c new file mode 100644 index 0000000..354dd8f --- /dev/null +++ b/gcc/testsuite/gcc.dg/bitint-112.c @@ -0,0 +1,5 @@ +/* { dg-do compile { target bitint575 } } */ +/* { dg-options "-std=c2y" } */ + +static_assert (0o177777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777wb / 2wb * 2wb + 1wb == 0x3fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffwb, ""); +static_assert (0O3211423263360473024126605062402061031423012516423720422320324010721642021266620206352436541213777372642147046071532121506001467430513304743521547653653136162305775772330633147605317353126354wb == 0x1a2626b3784ec2856c28ca04310cc4c154e89f4224d06a023a3a208adb20867547ac28bffbeb4467130e6b451a30066f18a5b13c751b3eaf565e39317fbfa6c66ccf8567bacacecwb, ""); diff --git a/gcc/testsuite/gcc.dg/c23-digit-separators-1.c b/gcc/testsuite/gcc.dg/c23-digit-separators-1.c index 4b5f4f6..03fe1f4 100644 --- a/gcc/testsuite/gcc.dg/c23-digit-separators-1.c +++ b/gcc/testsuite/gcc.dg/c23-digit-separators-1.c @@ -5,6 +5,7 @@ _Static_assert (123'45'6 == 123456); _Static_assert (0'123 == 0123); _Static_assert (0x1'23 == 0x123); +_Static_assert (0b1'01 == 0b101); #define m(x) 0 diff --git a/gcc/testsuite/gcc.dg/c23-octal-constants-1.c b/gcc/testsuite/gcc.dg/c23-octal-constants-1.c new file mode 100644 index 0000000..2696073 --- /dev/null +++ b/gcc/testsuite/gcc.dg/c23-octal-constants-1.c @@ -0,0 +1,11 @@ +/* Test that octal constants are diagnosed in C23 mode: -pedantic. */ +/* { dg-do compile } */ +/* { dg-options "-std=c23 -pedantic" } */ + +int a = 0o7; /* { dg-warning "'0o' prefixed constants" } */ +#if 0o107 /* { dg-warning "'0o' prefixed constants" } */ +#endif + +int b = 0O7; /* { dg-warning "'0o' prefixed constants" } */ +#if 0O107 /* { dg-warning "'0o' prefixed constants" } */ +#endif diff --git a/gcc/testsuite/gcc.dg/c23-octal-constants-2.c b/gcc/testsuite/gcc.dg/c23-octal-constants-2.c new file mode 100644 index 0000000..8ee9609 --- /dev/null +++ b/gcc/testsuite/gcc.dg/c23-octal-constants-2.c @@ -0,0 +1,11 @@ +/* Test that octal constants are diagnosed in C23 mode: -pedantic-errors. */ +/* { dg-do compile } */ +/* { dg-options "-std=c23 -pedantic-errors" } */ + +int a = 0o7; /* { dg-error "'0o' prefixed constants" } */ +#if 0o107 /* { dg-error "'0o' prefixed constants" } */ +#endif + +int b = 0O7; /* { dg-error "'0o' prefixed constants" } */ +#if 0O107 /* { dg-error "'0o' prefixed constants" } */ +#endif diff --git a/gcc/testsuite/gcc.dg/c2y-digit-separators-1.c b/gcc/testsuite/gcc.dg/c2y-digit-separators-1.c new file mode 100644 index 0000000..b600328 --- /dev/null +++ b/gcc/testsuite/gcc.dg/c2y-digit-separators-1.c @@ -0,0 +1,6 @@ +/* Test C2Y digit separators. Valid usages. */ +/* { dg-do compile } */ +/* { dg-options "-std=c2y -pedantic-errors" } */ + +_Static_assert (0o3'703 == 0O3703); +_Static_assert (0O1'7'7'7 == 0o1777); diff --git a/gcc/testsuite/gcc.dg/c2y-digit-separators-2.c b/gcc/testsuite/gcc.dg/c2y-digit-separators-2.c new file mode 100644 index 0000000..e634c38 --- /dev/null +++ b/gcc/testsuite/gcc.dg/c2y-digit-separators-2.c @@ -0,0 +1,11 @@ +/* Test C2Y digit separators. Invalid usages. */ +/* { dg-do compile } */ +/* { dg-options "-std=c2y -pedantic-errors" } */ + +void +tf (void) +{ + int i; + i = 0o'0; /* { dg-error "digit separator after base indicator" } */ + i = 0O'7; /* { dg-error "digit separator after base indicator" } */ +} diff --git a/gcc/testsuite/gcc.dg/c2y-octal-constants-1.c b/gcc/testsuite/gcc.dg/c2y-octal-constants-1.c new file mode 100644 index 0000000..9a338967 --- /dev/null +++ b/gcc/testsuite/gcc.dg/c2y-octal-constants-1.c @@ -0,0 +1,5 @@ +/* Test C2Y octal constants. Valid syntax and types. */ +/* { dg-do compile } */ +/* { dg-options "-std=c2y -pedantic-errors" } */ + +#include "octal-constants-1.c" diff --git a/gcc/testsuite/gcc.dg/c2y-octal-constants-2.c b/gcc/testsuite/gcc.dg/c2y-octal-constants-2.c new file mode 100644 index 0000000..df29236 --- /dev/null +++ b/gcc/testsuite/gcc.dg/c2y-octal-constants-2.c @@ -0,0 +1,11 @@ +/* Test that octal constants are accepted in C2Y mode: compat warnings. */ +/* { dg-do compile } */ +/* { dg-options "-std=c2y -Wc23-c2y-compat" } */ + +int a = 0o7; /* { dg-warning "C2Y feature" } */ +#if 0o107 /* { dg-warning "C2Y feature" } */ +#endif + +int b = 0O7; /* { dg-warning "C2Y feature" } */ +#if 0O107 /* { dg-warning "C2Y feature" } */ +#endif diff --git a/gcc/testsuite/gcc.dg/c2y-octal-constants-3.c b/gcc/testsuite/gcc.dg/c2y-octal-constants-3.c new file mode 100644 index 0000000..dc79739 --- /dev/null +++ b/gcc/testsuite/gcc.dg/c2y-octal-constants-3.c @@ -0,0 +1,9 @@ +/* Test C2Y octal constants. Invalid constants. */ +/* { dg-do compile } */ +/* { dg-options "-std=c2y -pedantic-errors" } */ + +int a = 0o; /* { dg-error "invalid suffix" } */ +int b = 0Oa; /* { dg-error "invalid suffix" } */ +int c = 0O08; /* { dg-error "invalid digit" } */ +int d = 0o1.1; /* { dg-error "invalid prefix" } */ +int e = 0O0p0; /* { dg-error "invalid suffix" } */ diff --git a/gcc/testsuite/gcc.dg/cpp/c23-delimited-escape-seq-1.c b/gcc/testsuite/gcc.dg/cpp/c23-delimited-escape-seq-1.c new file mode 100644 index 0000000..bb73e8a --- /dev/null +++ b/gcc/testsuite/gcc.dg/cpp/c23-delimited-escape-seq-1.c @@ -0,0 +1,87 @@ +/* N3353 - Delimited escape sequences */ +/* { dg-do compile } */ +/* { dg-require-effective-target wchar } */ +/* { dg-options "-std=c23 -pedantic -Wno-c++-compat" } */ + +#include <wchar.h> +typedef __CHAR16_TYPE__ char16_t; +typedef __CHAR32_TYPE__ char32_t; + +const char32_t *a = U"\u{1234}\u{10fffd}\u{000000000000000000000000000000000000000000000000000000000001234}\u{10FFFD}"; /* { dg-warning "delimited escape sequences are only valid in" } */ +const char32_t *b = U"\x{1234}\x{10fffd}\x{000000000000000000000000000000000000000000000000000000000001234}"; /* { dg-warning "delimited escape sequences are only valid in" } */ +const char32_t *c = U"\o{1234}\o{4177775}\o{000000000000000000000000000000000000000000000000000000000000000000000000004177775}";/* { dg-warning "delimited escape sequences are only valid in" } */ +const char16_t *d = u"\u{1234}\u{bFFd}\u{00000000000000000000000000000001234}"; /* { dg-warning "delimited escape sequences are only valid in" } */ +const char16_t *e = u"\x{1234}\x{BffD}\x{000001234}"; /* { dg-warning "delimited escape sequences are only valid in" } */ +const char16_t *f = u"\o{1234}\o{137775}\o{000000000000000137775}"; /* { dg-warning "delimited escape sequences are only valid in" } */ +const wchar_t *g = L"\u{1234}\u{bFFd}\u{00000000000000000000000000000001234}"; /* { dg-warning "delimited escape sequences are only valid in" } */ +const wchar_t *h = L"\x{1234}\x{bFFd}\x{000001234}"; /* { dg-warning "delimited escape sequences are only valid in" } */ +const wchar_t *i = L"\o{1234}\o{137775}\o{000000000000000137775}"; /* { dg-warning "delimited escape sequences are only valid in" } */ +const char *k = "\x{34}\x{000000000000000003D}"; /* { dg-warning "delimited escape sequences are only valid in" } */ +const char *l = "\o{34}\o{000000000000000176}"; /* { dg-warning "delimited escape sequences are only valid in" } */ + +#if U'\u{1234}' != U'\u1234' || U'\u{10fffd}' != U'\U0010FFFD' \ + || U'\x{00000001234}' != U'\x1234' || U'\x{010fffd}' != U'\x10FFFD' \ + || U'\o{1234}' != U'\x29c' || U'\o{004177775}' != U'\x10FFFD' \ + || u'\u{1234}' != u'\u1234' || u'\u{0bffd}' != u'\uBFFD' \ + || u'\x{00000001234}' != u'\x1234' || u'\x{0Bffd}' != u'\x0bFFD' \ + || u'\o{1234}' != u'\x29c' || u'\o{00137775}' != u'\xBFFD' \ + || L'\u{1234}' != L'\u1234' || L'\u{0bffd}' != L'\uBFFD' \ + || L'\x{00000001234}' != L'\x1234' || L'\x{0bffd}' != L'\x0bFFD' \ + || L'\o{1234}' != L'\x29c' || L'\o{00137775}' != L'\xBFFD' \ + || '\x{34}' != '\x034' || '\x{0003d}' != '\x003D' \ + || '\o{34}' != '\x1C' || '\o{176}' != '\x007E' +/* { dg-warning "delimited escape sequences are only valid in" "" { target *-*-* } .-11 } */ +/* { dg-warning "delimited escape sequences are only valid in" "" { target *-*-* } .-11 } */ +/* { dg-warning "delimited escape sequences are only valid in" "" { target *-*-* } .-11 } */ +/* { dg-warning "delimited escape sequences are only valid in" "" { target *-*-* } .-11 } */ +/* { dg-warning "delimited escape sequences are only valid in" "" { target *-*-* } .-11 } */ +/* { dg-warning "delimited escape sequences are only valid in" "" { target *-*-* } .-11 } */ +/* { dg-warning "delimited escape sequences are only valid in" "" { target *-*-* } .-11 } */ +/* { dg-warning "delimited escape sequences are only valid in" "" { target *-*-* } .-11 } */ +/* { dg-warning "delimited escape sequences are only valid in" "" { target *-*-* } .-11 } */ +/* { dg-warning "delimited escape sequences are only valid in" "" { target *-*-* } .-11 } */ +/* { dg-warning "delimited escape sequences are only valid in" "" { target *-*-* } .-11 } */ +#error Bad +#endif + +int +main () +{ + if (a[0] != U'\u1234' || a[0] != U'\u{1234}' /* { dg-warning "delimited escape sequences are only valid in" } */ + || a[1] != U'\U0010FFFD' || a[1] != U'\u{000010fFfD}' /* { dg-warning "delimited escape sequences are only valid in" } */ + || a[2] != a[0] + || a[3] != a[1] + || b[0] != U'\x1234' || b[0] != U'\x{001234}' /* { dg-warning "delimited escape sequences are only valid in" } */ + || b[1] != U'\x10FFFD' || b[1] != U'\x{0010fFfD}' /* { dg-warning "delimited escape sequences are only valid in" } */ + || b[2] != b[0] + || c[0] != U'\x29c' || c[0] != U'\o{001234}' /* { dg-warning "delimited escape sequences are only valid in" } */ + || c[1] != U'\x10FFFD' || c[1] != U'\o{4177775}' /* { dg-warning "delimited escape sequences are only valid in" } */ + || c[2] != c[1]) + __builtin_abort (); + if (d[0] != u'\u1234' || d[0] != u'\u{1234}' /* { dg-warning "delimited escape sequences are only valid in" } */ + || d[1] != u'\U0000BFFD' || d[1] != u'\u{00000bFfD}' /* { dg-warning "delimited escape sequences are only valid in" } */ + || d[2] != d[0] + || e[0] != u'\x1234' || e[0] != u'\x{001234}' /* { dg-warning "delimited escape sequences are only valid in" } */ + || e[1] != u'\xBFFD' || e[1] != u'\x{00bFfD}' /* { dg-warning "delimited escape sequences are only valid in" } */ + || e[2] != e[0] + || f[0] != u'\x29c' || f[0] != u'\o{001234}' /* { dg-warning "delimited escape sequences are only valid in" } */ + || f[1] != u'\xbFFD' || f[1] != u'\o{137775}' /* { dg-warning "delimited escape sequences are only valid in" } */ + || f[2] != f[1]) + __builtin_abort (); + if (g[0] != L'\u1234' || g[0] != L'\u{1234}' /* { dg-warning "delimited escape sequences are only valid in" } */ + || g[1] != L'\U0000BFFD' || g[1] != L'\u{00000bFfD}' /* { dg-warning "delimited escape sequences are only valid in" } */ + || g[2] != g[0] + || h[0] != L'\x1234' || h[0] != L'\x{001234}' /* { dg-warning "delimited escape sequences are only valid in" } */ + || h[1] != L'\xBFFD' || h[1] != L'\x{00bFfD}' /* { dg-warning "delimited escape sequences are only valid in" } */ + || h[2] != h[0] + || i[0] != L'\x29c' || i[0] != L'\o{001234}' /* { dg-warning "delimited escape sequences are only valid in" } */ + || i[1] != L'\xbFFD' || i[1] != L'\o{137775}' /* { dg-warning "delimited escape sequences are only valid in" } */ + || i[2] != i[1]) + __builtin_abort (); + if (k[0] != '\x034' || k[0] != '\x{0034}' /* { dg-warning "delimited escape sequences are only valid in" } */ + || k[1] != '\x3D' || k[1] != '\x{3d}' /* { dg-warning "delimited escape sequences are only valid in" } */ + || l[0] != '\x1c' || l[0] != '\o{0034}' /* { dg-warning "delimited escape sequences are only valid in" } */ + || l[1] != '\x07e' || l[1] != '\o{176}' || l[1] != '\176') /* { dg-warning "delimited escape sequences are only valid in" } */ + __builtin_abort (); + return 0; +} diff --git a/gcc/testsuite/gcc.dg/cpp/c23-delimited-escape-seq-2.c b/gcc/testsuite/gcc.dg/cpp/c23-delimited-escape-seq-2.c new file mode 100644 index 0000000..04a5243 --- /dev/null +++ b/gcc/testsuite/gcc.dg/cpp/c23-delimited-escape-seq-2.c @@ -0,0 +1,87 @@ +/* N3353 - Delimited escape sequences */ +/* { dg-do compile } */ +/* { dg-require-effective-target wchar } */ +/* { dg-options "-std=c23 -pedantic-errors -Wno-c++-compat" } */ + +#include <wchar.h> +typedef __CHAR16_TYPE__ char16_t; +typedef __CHAR32_TYPE__ char32_t; + +const char32_t *a = U"\u{1234}\u{10fffd}\u{000000000000000000000000000000000000000000000000000000000001234}\u{10FFFD}"; /* { dg-error "delimited escape sequences are only valid in" } */ +const char32_t *b = U"\x{1234}\x{10fffd}\x{000000000000000000000000000000000000000000000000000000000001234}"; /* { dg-error "delimited escape sequences are only valid in" } */ +const char32_t *c = U"\o{1234}\o{4177775}\o{000000000000000000000000000000000000000000000000000000000000000000000000004177775}";/* { dg-error "delimited escape sequences are only valid in" } */ +const char16_t *d = u"\u{1234}\u{bFFd}\u{00000000000000000000000000000001234}"; /* { dg-error "delimited escape sequences are only valid in" } */ +const char16_t *e = u"\x{1234}\x{BffD}\x{000001234}"; /* { dg-error "delimited escape sequences are only valid in" } */ +const char16_t *f = u"\o{1234}\o{137775}\o{000000000000000137775}"; /* { dg-error "delimited escape sequences are only valid in" } */ +const wchar_t *g = L"\u{1234}\u{bFFd}\u{00000000000000000000000000000001234}"; /* { dg-error "delimited escape sequences are only valid in" } */ +const wchar_t *h = L"\x{1234}\x{bFFd}\x{000001234}"; /* { dg-error "delimited escape sequences are only valid in" } */ +const wchar_t *i = L"\o{1234}\o{137775}\o{000000000000000137775}"; /* { dg-error "delimited escape sequences are only valid in" } */ +const char *k = "\x{34}\x{000000000000000003D}"; /* { dg-error "delimited escape sequences are only valid in" } */ +const char *l = "\o{34}\o{000000000000000176}"; /* { dg-error "delimited escape sequences are only valid in" } */ + +#if U'\u{1234}' != U'\u1234' || U'\u{10fffd}' != U'\U0010FFFD' \ + || U'\x{00000001234}' != U'\x1234' || U'\x{010fffd}' != U'\x10FFFD' \ + || U'\o{1234}' != U'\x29c' || U'\o{004177775}' != U'\x10FFFD' \ + || u'\u{1234}' != u'\u1234' || u'\u{0bffd}' != u'\uBFFD' \ + || u'\x{00000001234}' != u'\x1234' || u'\x{0Bffd}' != u'\x0bFFD' \ + || u'\o{1234}' != u'\x29c' || u'\o{00137775}' != u'\xBFFD' \ + || L'\u{1234}' != L'\u1234' || L'\u{0bffd}' != L'\uBFFD' \ + || L'\x{00000001234}' != L'\x1234' || L'\x{0bffd}' != L'\x0bFFD' \ + || L'\o{1234}' != L'\x29c' || L'\o{00137775}' != L'\xBFFD' \ + || '\x{34}' != '\x034' || '\x{0003d}' != '\x003D' \ + || '\o{34}' != '\x1C' || '\o{176}' != '\x007E' +/* { dg-error "delimited escape sequences are only valid in" "" { target *-*-* } .-11 } */ +/* { dg-error "delimited escape sequences are only valid in" "" { target *-*-* } .-11 } */ +/* { dg-error "delimited escape sequences are only valid in" "" { target *-*-* } .-11 } */ +/* { dg-error "delimited escape sequences are only valid in" "" { target *-*-* } .-11 } */ +/* { dg-error "delimited escape sequences are only valid in" "" { target *-*-* } .-11 } */ +/* { dg-error "delimited escape sequences are only valid in" "" { target *-*-* } .-11 } */ +/* { dg-error "delimited escape sequences are only valid in" "" { target *-*-* } .-11 } */ +/* { dg-error "delimited escape sequences are only valid in" "" { target *-*-* } .-11 } */ +/* { dg-error "delimited escape sequences are only valid in" "" { target *-*-* } .-11 } */ +/* { dg-error "delimited escape sequences are only valid in" "" { target *-*-* } .-11 } */ +/* { dg-error "delimited escape sequences are only valid in" "" { target *-*-* } .-11 } */ +#error Bad +#endif + +int +main () +{ + if (a[0] != U'\u1234' || a[0] != U'\u{1234}' /* { dg-error "delimited escape sequences are only valid in" } */ + || a[1] != U'\U0010FFFD' || a[1] != U'\u{000010fFfD}' /* { dg-error "delimited escape sequences are only valid in" } */ + || a[2] != a[0] + || a[3] != a[1] + || b[0] != U'\x1234' || b[0] != U'\x{001234}' /* { dg-error "delimited escape sequences are only valid in" } */ + || b[1] != U'\x10FFFD' || b[1] != U'\x{0010fFfD}' /* { dg-error "delimited escape sequences are only valid in" } */ + || b[2] != b[0] + || c[0] != U'\x29c' || c[0] != U'\o{001234}' /* { dg-error "delimited escape sequences are only valid in" } */ + || c[1] != U'\x10FFFD' || c[1] != U'\o{4177775}' /* { dg-error "delimited escape sequences are only valid in" } */ + || c[2] != c[1]) + __builtin_abort (); + if (d[0] != u'\u1234' || d[0] != u'\u{1234}' /* { dg-error "delimited escape sequences are only valid in" } */ + || d[1] != u'\U0000BFFD' || d[1] != u'\u{00000bFfD}' /* { dg-error "delimited escape sequences are only valid in" } */ + || d[2] != d[0] + || e[0] != u'\x1234' || e[0] != u'\x{001234}' /* { dg-error "delimited escape sequences are only valid in" } */ + || e[1] != u'\xBFFD' || e[1] != u'\x{00bFfD}' /* { dg-error "delimited escape sequences are only valid in" } */ + || e[2] != e[0] + || f[0] != u'\x29c' || f[0] != u'\o{001234}' /* { dg-error "delimited escape sequences are only valid in" } */ + || f[1] != u'\xbFFD' || f[1] != u'\o{137775}' /* { dg-error "delimited escape sequences are only valid in" } */ + || f[2] != f[1]) + __builtin_abort (); + if (g[0] != L'\u1234' || g[0] != L'\u{1234}' /* { dg-error "delimited escape sequences are only valid in" } */ + || g[1] != L'\U0000BFFD' || g[1] != L'\u{00000bFfD}' /* { dg-error "delimited escape sequences are only valid in" } */ + || g[2] != g[0] + || h[0] != L'\x1234' || h[0] != L'\x{001234}' /* { dg-error "delimited escape sequences are only valid in" } */ + || h[1] != L'\xBFFD' || h[1] != L'\x{00bFfD}' /* { dg-error "delimited escape sequences are only valid in" } */ + || h[2] != h[0] + || i[0] != L'\x29c' || i[0] != L'\o{001234}' /* { dg-error "delimited escape sequences are only valid in" } */ + || i[1] != L'\xbFFD' || i[1] != L'\o{137775}' /* { dg-error "delimited escape sequences are only valid in" } */ + || i[2] != i[1]) + __builtin_abort (); + if (k[0] != '\x034' || k[0] != '\x{0034}' /* { dg-error "delimited escape sequences are only valid in" } */ + || k[1] != '\x3D' || k[1] != '\x{3d}' /* { dg-error "delimited escape sequences are only valid in" } */ + || l[0] != '\x1c' || l[0] != '\o{0034}' /* { dg-error "delimited escape sequences are only valid in" } */ + || l[1] != '\x07e' || l[1] != '\o{176}' || l[1] != '\176') /* { dg-error "delimited escape sequences are only valid in" } */ + __builtin_abort (); + return 0; +} diff --git a/gcc/testsuite/gcc.dg/cpp/c2y-delimited-escape-seq-1.c b/gcc/testsuite/gcc.dg/cpp/c2y-delimited-escape-seq-1.c new file mode 100644 index 0000000..59468af --- /dev/null +++ b/gcc/testsuite/gcc.dg/cpp/c2y-delimited-escape-seq-1.c @@ -0,0 +1,6 @@ +/* N3353 - Delimited escape sequences */ +/* { dg-do run } */ +/* { dg-require-effective-target wchar } */ +/* { dg-options "-std=c2y -pedantic-errors -Wno-c++-compat" } */ + +#include "../../c-c++-common/cpp/delimited-escape-seq-1.c" diff --git a/gcc/testsuite/gcc.dg/cpp/c2y-delimited-escape-seq-2.c b/gcc/testsuite/gcc.dg/cpp/c2y-delimited-escape-seq-2.c new file mode 100644 index 0000000..7cc841c --- /dev/null +++ b/gcc/testsuite/gcc.dg/cpp/c2y-delimited-escape-seq-2.c @@ -0,0 +1,5 @@ +/* N3353 - Delimited escape sequences */ +/* { dg-do compile } */ +/* { dg-options "-std=c2y -pedantic-errors -Wno-c++-compat" } */ + +#include "../../c-c++-common/cpp/delimited-escape-seq-2.c" diff --git a/gcc/testsuite/gcc.dg/cpp/c2y-delimited-escape-seq-3.c b/gcc/testsuite/gcc.dg/cpp/c2y-delimited-escape-seq-3.c new file mode 100644 index 0000000..211dc84 --- /dev/null +++ b/gcc/testsuite/gcc.dg/cpp/c2y-delimited-escape-seq-3.c @@ -0,0 +1,30 @@ +/* N3353 - Delimited escape sequences */ +/* { dg-do compile } */ +/* { dg-require-effective-target wchar } */ +/* { dg-options "-std=c2y -pedantic-errors -Wno-c++-compat" } */ + +typedef __CHAR32_TYPE__ char32_t; + +const char32_t *a = U"\u{}"; /* { dg-error "empty delimited escape sequence" } */ + /* { dg-error "is not a valid universal character" "" { target c } .-1 } */ +const char32_t *b = U"\u{12" "34}"; /* { dg-error "'\\\\u\\{' not terminated with '\\}' after" } */ +const char32_t *c = U"\u{0000ffffffff}"; /* { dg-error "is not a valid universal character" } */ +const char32_t *d = U"\u{010000edcb}"; /* { dg-error "is not a valid universal character" } */ +const char32_t *e = U"\u{02000000000000000000edcb}"; /* { dg-error "is not a valid universal character" } */ +const char32_t *f = U"\u{123ghij}"; /* { dg-error "'\\\\u\\{' not terminated with '\\}' after" } */ +const char32_t *g = U"\u{123.}"; /* { dg-error "'\\\\u\\{' not terminated with '\\}' after" } */ +const char32_t *h = U"\u{.}"; /* { dg-error "'\\\\u\\{' not terminated with '\\}' after" } */ +const char32_t *i = U"\x{}"; /* { dg-error "empty delimited escape sequence" } */ +const char32_t *j = U"\x{12" "34}"; /* { dg-error "'\\\\x\\{' not terminated with '\\}' after" } */ +const char32_t *k = U"\x{0000ffffffff}"; +const char32_t *l = U"\x{010000edcb}"; /* { dg-error "hex escape sequence out of range" } */ +const char32_t *m = U"\x{02000000000000000000edcb}"; /* { dg-error "hex escape sequence out of range" } */ +const char32_t *n = U"\x{123ghij}"; /* { dg-error "'\\\\x\\{' not terminated with '\\}' after" } */ +const char32_t *o = U"\x{123.}"; /* { dg-error "'\\\\x\\{' not terminated with '\\}' after" } */ +const char32_t *p = U"\o{}"; /* { dg-error "empty delimited escape sequence" } */ +const char32_t *q = U"\o{12" "34}"; /* { dg-error "'\\\\o\\{' not terminated with '\\}' after" } */ +const char32_t *r = U"\o{0000037777777777}"; +const char32_t *s = U"\o{040000166713}"; /* { dg-error "octal escape sequence out of range" } */ +const char32_t *t = U"\o{02000000000000000000000166713}";/* { dg-error "octal escape sequence out of range" } */ +const char32_t *u = U"\o{1238}"; /* { dg-error "'\\\\o\\{' not terminated with '\\}' after" } */ +const char32_t *v = U"\o{.}"; /* { dg-error "'\\\\o\\{' not terminated with '\\}' after" } */ diff --git a/gcc/testsuite/gcc.dg/cpp/c2y-delimited-escape-seq-4.c b/gcc/testsuite/gcc.dg/cpp/c2y-delimited-escape-seq-4.c new file mode 100644 index 0000000..bdb0e47 --- /dev/null +++ b/gcc/testsuite/gcc.dg/cpp/c2y-delimited-escape-seq-4.c @@ -0,0 +1,87 @@ +/* N3353 - Delimited escape sequences */ +/* { dg-do compile } */ +/* { dg-require-effective-target wchar } */ +/* { dg-options "-std=c2y -Wc23-c2y-compat -Wno-c++-compat" } */ + +#include <wchar.h> +typedef __CHAR16_TYPE__ char16_t; +typedef __CHAR32_TYPE__ char32_t; + +const char32_t *a = U"\u{1234}\u{10fffd}\u{000000000000000000000000000000000000000000000000000000000001234}\u{10FFFD}"; /* { dg-warning "delimited escape sequences are only valid in" } */ +const char32_t *b = U"\x{1234}\x{10fffd}\x{000000000000000000000000000000000000000000000000000000000001234}"; /* { dg-warning "delimited escape sequences are only valid in" } */ +const char32_t *c = U"\o{1234}\o{4177775}\o{000000000000000000000000000000000000000000000000000000000000000000000000004177775}";/* { dg-warning "delimited escape sequences are only valid in" } */ +const char16_t *d = u"\u{1234}\u{bFFd}\u{00000000000000000000000000000001234}"; /* { dg-warning "delimited escape sequences are only valid in" } */ +const char16_t *e = u"\x{1234}\x{BffD}\x{000001234}"; /* { dg-warning "delimited escape sequences are only valid in" } */ +const char16_t *f = u"\o{1234}\o{137775}\o{000000000000000137775}"; /* { dg-warning "delimited escape sequences are only valid in" } */ +const wchar_t *g = L"\u{1234}\u{bFFd}\u{00000000000000000000000000000001234}"; /* { dg-warning "delimited escape sequences are only valid in" } */ +const wchar_t *h = L"\x{1234}\x{bFFd}\x{000001234}"; /* { dg-warning "delimited escape sequences are only valid in" } */ +const wchar_t *i = L"\o{1234}\o{137775}\o{000000000000000137775}"; /* { dg-warning "delimited escape sequences are only valid in" } */ +const char *k = "\x{34}\x{000000000000000003D}"; /* { dg-warning "delimited escape sequences are only valid in" } */ +const char *l = "\o{34}\o{000000000000000176}"; /* { dg-warning "delimited escape sequences are only valid in" } */ + +#if U'\u{1234}' != U'\u1234' || U'\u{10fffd}' != U'\U0010FFFD' \ + || U'\x{00000001234}' != U'\x1234' || U'\x{010fffd}' != U'\x10FFFD' \ + || U'\o{1234}' != U'\x29c' || U'\o{004177775}' != U'\x10FFFD' \ + || u'\u{1234}' != u'\u1234' || u'\u{0bffd}' != u'\uBFFD' \ + || u'\x{00000001234}' != u'\x1234' || u'\x{0Bffd}' != u'\x0bFFD' \ + || u'\o{1234}' != u'\x29c' || u'\o{00137775}' != u'\xBFFD' \ + || L'\u{1234}' != L'\u1234' || L'\u{0bffd}' != L'\uBFFD' \ + || L'\x{00000001234}' != L'\x1234' || L'\x{0bffd}' != L'\x0bFFD' \ + || L'\o{1234}' != L'\x29c' || L'\o{00137775}' != L'\xBFFD' \ + || '\x{34}' != '\x034' || '\x{0003d}' != '\x003D' \ + || '\o{34}' != '\x1C' || '\o{176}' != '\x007E' +/* { dg-warning "delimited escape sequences are only valid in" "" { target *-*-* } .-11 } */ +/* { dg-warning "delimited escape sequences are only valid in" "" { target *-*-* } .-11 } */ +/* { dg-warning "delimited escape sequences are only valid in" "" { target *-*-* } .-11 } */ +/* { dg-warning "delimited escape sequences are only valid in" "" { target *-*-* } .-11 } */ +/* { dg-warning "delimited escape sequences are only valid in" "" { target *-*-* } .-11 } */ +/* { dg-warning "delimited escape sequences are only valid in" "" { target *-*-* } .-11 } */ +/* { dg-warning "delimited escape sequences are only valid in" "" { target *-*-* } .-11 } */ +/* { dg-warning "delimited escape sequences are only valid in" "" { target *-*-* } .-11 } */ +/* { dg-warning "delimited escape sequences are only valid in" "" { target *-*-* } .-11 } */ +/* { dg-warning "delimited escape sequences are only valid in" "" { target *-*-* } .-11 } */ +/* { dg-warning "delimited escape sequences are only valid in" "" { target *-*-* } .-11 } */ +#error Bad +#endif + +int +main () +{ + if (a[0] != U'\u1234' || a[0] != U'\u{1234}' /* { dg-warning "delimited escape sequences are only valid in" } */ + || a[1] != U'\U0010FFFD' || a[1] != U'\u{000010fFfD}' /* { dg-warning "delimited escape sequences are only valid in" } */ + || a[2] != a[0] + || a[3] != a[1] + || b[0] != U'\x1234' || b[0] != U'\x{001234}' /* { dg-warning "delimited escape sequences are only valid in" } */ + || b[1] != U'\x10FFFD' || b[1] != U'\x{0010fFfD}' /* { dg-warning "delimited escape sequences are only valid in" } */ + || b[2] != b[0] + || c[0] != U'\x29c' || c[0] != U'\o{001234}' /* { dg-warning "delimited escape sequences are only valid in" } */ + || c[1] != U'\x10FFFD' || c[1] != U'\o{4177775}' /* { dg-warning "delimited escape sequences are only valid in" } */ + || c[2] != c[1]) + __builtin_abort (); + if (d[0] != u'\u1234' || d[0] != u'\u{1234}' /* { dg-warning "delimited escape sequences are only valid in" } */ + || d[1] != u'\U0000BFFD' || d[1] != u'\u{00000bFfD}' /* { dg-warning "delimited escape sequences are only valid in" } */ + || d[2] != d[0] + || e[0] != u'\x1234' || e[0] != u'\x{001234}' /* { dg-warning "delimited escape sequences are only valid in" } */ + || e[1] != u'\xBFFD' || e[1] != u'\x{00bFfD}' /* { dg-warning "delimited escape sequences are only valid in" } */ + || e[2] != e[0] + || f[0] != u'\x29c' || f[0] != u'\o{001234}' /* { dg-warning "delimited escape sequences are only valid in" } */ + || f[1] != u'\xbFFD' || f[1] != u'\o{137775}' /* { dg-warning "delimited escape sequences are only valid in" } */ + || f[2] != f[1]) + __builtin_abort (); + if (g[0] != L'\u1234' || g[0] != L'\u{1234}' /* { dg-warning "delimited escape sequences are only valid in" } */ + || g[1] != L'\U0000BFFD' || g[1] != L'\u{00000bFfD}' /* { dg-warning "delimited escape sequences are only valid in" } */ + || g[2] != g[0] + || h[0] != L'\x1234' || h[0] != L'\x{001234}' /* { dg-warning "delimited escape sequences are only valid in" } */ + || h[1] != L'\xBFFD' || h[1] != L'\x{00bFfD}' /* { dg-warning "delimited escape sequences are only valid in" } */ + || h[2] != h[0] + || i[0] != L'\x29c' || i[0] != L'\o{001234}' /* { dg-warning "delimited escape sequences are only valid in" } */ + || i[1] != L'\xbFFD' || i[1] != L'\o{137775}' /* { dg-warning "delimited escape sequences are only valid in" } */ + || i[2] != i[1]) + __builtin_abort (); + if (k[0] != '\x034' || k[0] != '\x{0034}' /* { dg-warning "delimited escape sequences are only valid in" } */ + || k[1] != '\x3D' || k[1] != '\x{3d}' /* { dg-warning "delimited escape sequences are only valid in" } */ + || l[0] != '\x1c' || l[0] != '\o{0034}' /* { dg-warning "delimited escape sequences are only valid in" } */ + || l[1] != '\x07e' || l[1] != '\o{176}' || l[1] != '\176') /* { dg-warning "delimited escape sequences are only valid in" } */ + __builtin_abort (); + return 0; +} diff --git a/gcc/testsuite/gcc.dg/octal-constants-1.c b/gcc/testsuite/gcc.dg/octal-constants-1.c new file mode 100644 index 0000000..5e22853 --- /dev/null +++ b/gcc/testsuite/gcc.dg/octal-constants-1.c @@ -0,0 +1,311 @@ +/* Test for octal integer constants. */ + +/* Derived from: binary-constants-1.c, by Jakub Jelinek <jakub@redhat.com>. */ +/* Origin: Joerg Wunsch <j.gnu@uriah.heep.sax.de>. */ +/* { dg-do compile } */ +/* { dg-options "-std=gnu99" } */ + +#include <limits.h> + +/* Assertion that constant C is of type T. */ +#define ASSERT_CONST_TYPE(C, T) \ + do { \ + typedef T type; \ + typedef type **typepp; \ + typedef __typeof__((C)) ctype; \ + typedef ctype **ctypepp; \ + typepp x = 0; \ + ctypepp y = 0; \ + x = y; \ + y = x; \ + } while (0) + +/* (T *) if E is zero, (void *) otherwise. */ +#define type_if_not(T, E) __typeof__(0 ? (T *)0 : (void *)(E)) + +/* (T *) if E is nonzero, (void *) otherwise. */ +#define type_if(T, E) type_if_not(T, !(E)) + +/* Combine pointer types, all but one (void *). */ +#define type_comb2(T1, T2) __typeof__(0 ? (T1)0 : (T2)0) +#define type_comb3(T1, T2, T3) type_comb2(T1, type_comb2(T2, T3)) +#define type_comb4(T1, T2, T3, T4) \ + type_comb2(T1, type_comb2(T2, type_comb2(T3, T4))) +#define type_comb6(T1, T2, T3, T4, T5, T6) \ + type_comb2(T1, \ + type_comb2(T2, \ + type_comb2(T3, \ + type_comb2(T4, \ + type_comb2(T5, T6))))) + +/* (T1 *) if E1, otherwise (T2 *) if E2. */ +#define first_of2p(T1, E1, T2, E2) type_comb2(type_if(T1, (E1)), \ + type_if(T2, (!(E1) && (E2)))) +/* (T1 *) if E1, otherwise (T2 *) if E2, otherwise (T3 *) if E3. */ +#define first_of3p(T1, E1, T2, E2, T3, E3) \ + type_comb3(type_if(T1, (E1)), \ + type_if(T2, (!(E1) && (E2))), \ + type_if(T3, (!(E1) && !(E2) && (E3)))) +/* (T1 *) if E1, otherwise (T2 *) if E2, otherwise (T3 *) if E3, otherwise + (T4 *) if E4. */ +#define first_of4p(T1, E1, T2, E2, T3, E3, T4, E4) \ + type_comb4(type_if(T1, (E1)), \ + type_if(T2, (!(E1) && (E2))), \ + type_if(T3, (!(E1) && !(E2) && (E3))), \ + type_if(T4, (!(E1) && !(E2) && !(E3) && (E4)))) +/* (T1 *) if E1, otherwise (T2 *) if E2, otherwise (T3 *) if E3, otherwise + (T4 *) if E4, otherwise (T5 *) if E5, otherwise (T6 *) if E6. */ +#define first_of6p(T1, E1, T2, E2, T3, E3, T4, E4, T5, E5, T6, E6) \ + type_comb6(type_if(T1, (E1)), \ + type_if(T2, (!(E1) && (E2))), \ + type_if(T3, (!(E1) && !(E2) && (E3))), \ + type_if(T4, (!(E1) && !(E2) && !(E3) && (E4))), \ + type_if(T5, (!(E1) && !(E2) && !(E3) && !(E4) && (E5))), \ + type_if(T6, (!(E1) && !(E2) && !(E3) \ + && !(E4) && !(E5) && (E6)))) + +/* Likewise, but return the original type rather than a pointer type. */ +#define first_of2(T1, E1, T2, E2) \ + __typeof__(*((first_of2p(T1, (E1), T2, (E2)))0)) +#define first_of3(T1, E1, T2, E2, T3, E3) \ + __typeof__(*((first_of3p(T1, (E1), T2, (E2), T3, (E3)))0)) +#define first_of4(T1, E1, T2, E2, T3, E3, T4, E4) \ + __typeof__(*((first_of4p(T1, (E1), T2, (E2), T3, (E3), T4, (E4)))0)) +#define first_of6(T1, E1, T2, E2, T3, E3, T4, E4, T5, E5, T6, E6) \ + __typeof__(*((first_of6p(T1, (E1), T2, (E2), T3, (E3), \ + T4, (E4), T5, (E5), T6, (E6)))0)) + +/* Types of constants according to the C99 rules. */ +#define C99_UNSUF_TYPE(C) \ + first_of6(int, (C) <= INT_MAX, \ + unsigned int, (C) <= UINT_MAX, \ + long int, (C) <= LONG_MAX, \ + unsigned long int, (C) <= ULONG_MAX, \ + long long int, (C) <= LLONG_MAX, \ + unsigned long long int, (C) <= ULLONG_MAX) +#define C99_SUFu_TYPE(C) \ + first_of3(unsigned int, (C) <= UINT_MAX, \ + unsigned long int, (C) <= ULONG_MAX, \ + unsigned long long int, (C) <= ULLONG_MAX) +#define C99_SUFl_TYPE(C) \ + first_of4(long int, (C) <= LONG_MAX, \ + unsigned long int, (C) <= ULONG_MAX, \ + long long int, (C) <= LLONG_MAX, \ + unsigned long long int, (C) <= ULLONG_MAX) +#define C99_SUFul_TYPE(C) \ + first_of2(unsigned long int, (C) <= ULONG_MAX, \ + unsigned long long int, (C) <= ULLONG_MAX) +#define C99_SUFll_TYPE(C) \ + first_of2(long long int, (C) <= LLONG_MAX, \ + unsigned long long int, (C) <= ULLONG_MAX) + +/* Checks that constants have correct type. */ +#define CHECK_UNSUF_TYPE(C) \ + ASSERT_CONST_TYPE((C), C99_UNSUF_TYPE((C))) +#define CHECK_SUFu_TYPE(C) ASSERT_CONST_TYPE((C), C99_SUFu_TYPE((C))) +#define CHECK_SUFl_TYPE(C) \ + ASSERT_CONST_TYPE((C), C99_SUFl_TYPE((C))) +#define CHECK_SUFul_TYPE(C) ASSERT_CONST_TYPE((C), C99_SUFul_TYPE((C))) +#define CHECK_SUFll_TYPE(C) \ + ASSERT_CONST_TYPE((C), C99_SUFll_TYPE((C))) +#define CHECK_SUFull_TYPE(C) ASSERT_CONST_TYPE((C), unsigned long long int) + +/* Check an octal or hexadecimal value, with all suffixes. */ +#define CHECK_CONST(C) \ + CHECK_UNSUF_TYPE(C); \ + CHECK_SUFu_TYPE(C##u); \ + CHECK_SUFu_TYPE(C##U); \ + CHECK_SUFl_TYPE(C##l); \ + CHECK_SUFl_TYPE(C##L); \ + CHECK_SUFul_TYPE(C##ul); \ + CHECK_SUFul_TYPE(C##uL); \ + CHECK_SUFul_TYPE(C##Ul); \ + CHECK_SUFul_TYPE(C##UL); \ + CHECK_SUFll_TYPE(C##ll); \ + CHECK_SUFll_TYPE(C##LL); \ + CHECK_SUFull_TYPE(C##ull); \ + CHECK_SUFull_TYPE(C##uLL); \ + CHECK_SUFull_TYPE(C##Ull); \ + CHECK_SUFull_TYPE(C##ULL); + +#define CHECK_OCT_CONST(C) \ + CHECK_CONST(0o##C); \ + CHECK_CONST(0O##C); + +/* True iff "long long" is at least B bits. This presumes that (B-2)/3 is at + most 63. */ +#define LLONG_AT_LEAST(B) \ + (LLONG_MAX >> ((B)-2)/3 >> ((B)-2)/3 \ + >> ((B)-2 - ((B)-2)/3 - ((B)-2)/3)) + +#define LLONG_HAS_BITS(B) (LLONG_AT_LEAST((B)) && !LLONG_AT_LEAST((B) + 1)) + +#define FOO 0o1307 +#if !FOO +# error "preprocessor does not accept octal constants" +#endif + +void +foo (void) +{ + /* Check all 2^n and 2^n - 1 up to 2^72 - 1. */ + CHECK_OCT_CONST(1); + CHECK_OCT_CONST(2); + CHECK_OCT_CONST(3); + CHECK_OCT_CONST(4); + CHECK_OCT_CONST(7); + CHECK_OCT_CONST(10); + CHECK_OCT_CONST(17); + CHECK_OCT_CONST(20); + CHECK_OCT_CONST(37); + CHECK_OCT_CONST(40); + CHECK_OCT_CONST(77); + CHECK_OCT_CONST(100); + CHECK_OCT_CONST(177); + CHECK_OCT_CONST(200); + CHECK_OCT_CONST(377); + CHECK_OCT_CONST(400); + CHECK_OCT_CONST(777); + CHECK_OCT_CONST(1000); + CHECK_OCT_CONST(1777); + CHECK_OCT_CONST(2000); + CHECK_OCT_CONST(3777); + CHECK_OCT_CONST(4000); + CHECK_OCT_CONST(7777); + CHECK_OCT_CONST(10000); + CHECK_OCT_CONST(17777); + CHECK_OCT_CONST(20000); + CHECK_OCT_CONST(37777); + CHECK_OCT_CONST(40000); + CHECK_OCT_CONST(77777); + CHECK_OCT_CONST(100000); + CHECK_OCT_CONST(177777); + CHECK_OCT_CONST(200000); + CHECK_OCT_CONST(377777); + CHECK_OCT_CONST(400000); + CHECK_OCT_CONST(777777); + CHECK_OCT_CONST(1000000); + CHECK_OCT_CONST(1777777); + CHECK_OCT_CONST(2000000); + CHECK_OCT_CONST(3777777); + CHECK_OCT_CONST(4000000); + CHECK_OCT_CONST(7777777); + CHECK_OCT_CONST(10000000); + CHECK_OCT_CONST(17777777); + CHECK_OCT_CONST(20000000); + CHECK_OCT_CONST(37777777); + CHECK_OCT_CONST(40000000); + CHECK_OCT_CONST(77777777); + CHECK_OCT_CONST(100000000); + CHECK_OCT_CONST(177777777); + CHECK_OCT_CONST(200000000); + CHECK_OCT_CONST(377777777); + CHECK_OCT_CONST(400000000); + CHECK_OCT_CONST(777777777); + CHECK_OCT_CONST(1000000000); + CHECK_OCT_CONST(1777777777); + CHECK_OCT_CONST(2000000000); + CHECK_OCT_CONST(3777777777); + CHECK_OCT_CONST(4000000000); + CHECK_OCT_CONST(7777777777); + CHECK_OCT_CONST(10000000000); + CHECK_OCT_CONST(17777777777); + CHECK_OCT_CONST(20000000000); + CHECK_OCT_CONST(37777777777); + CHECK_OCT_CONST(40000000000); + CHECK_OCT_CONST(77777777777); + CHECK_OCT_CONST(100000000000); + CHECK_OCT_CONST(177777777777); + CHECK_OCT_CONST(200000000000); + CHECK_OCT_CONST(377777777777); + CHECK_OCT_CONST(400000000000); + CHECK_OCT_CONST(777777777777); + CHECK_OCT_CONST(1000000000000); + CHECK_OCT_CONST(1777777777777); + CHECK_OCT_CONST(2000000000000); + CHECK_OCT_CONST(3777777777777); + CHECK_OCT_CONST(4000000000000); + CHECK_OCT_CONST(7777777777777); + CHECK_OCT_CONST(10000000000000); + CHECK_OCT_CONST(17777777777777); + CHECK_OCT_CONST(20000000000000); + CHECK_OCT_CONST(37777777777777); + CHECK_OCT_CONST(40000000000000); + CHECK_OCT_CONST(77777777777777); + CHECK_OCT_CONST(100000000000000); + CHECK_OCT_CONST(177777777777777); + CHECK_OCT_CONST(200000000000000); + CHECK_OCT_CONST(377777777777777); + CHECK_OCT_CONST(400000000000000); + CHECK_OCT_CONST(777777777777777); + CHECK_OCT_CONST(1000000000000000); + CHECK_OCT_CONST(1777777777777777); + CHECK_OCT_CONST(2000000000000000); + CHECK_OCT_CONST(3777777777777777); + CHECK_OCT_CONST(4000000000000000); + CHECK_OCT_CONST(7777777777777777); + CHECK_OCT_CONST(10000000000000000); + CHECK_OCT_CONST(17777777777777777); + CHECK_OCT_CONST(20000000000000000); + CHECK_OCT_CONST(37777777777777777); + CHECK_OCT_CONST(40000000000000000); + CHECK_OCT_CONST(77777777777777777); + CHECK_OCT_CONST(100000000000000000); + CHECK_OCT_CONST(177777777777777777); + CHECK_OCT_CONST(200000000000000000); + CHECK_OCT_CONST(377777777777777777); + CHECK_OCT_CONST(400000000000000000); + CHECK_OCT_CONST(777777777777777777); + CHECK_OCT_CONST(1000000000000000000); + CHECK_OCT_CONST(1777777777777777777); + CHECK_OCT_CONST(2000000000000000000); + CHECK_OCT_CONST(3777777777777777777); + CHECK_OCT_CONST(4000000000000000000); + CHECK_OCT_CONST(7777777777777777777); + CHECK_OCT_CONST(10000000000000000000); + CHECK_OCT_CONST(17777777777777777777); + CHECK_OCT_CONST(20000000000000000000); + CHECK_OCT_CONST(37777777777777777777); + CHECK_OCT_CONST(40000000000000000000); + CHECK_OCT_CONST(77777777777777777777); + CHECK_OCT_CONST(100000000000000000000); + CHECK_OCT_CONST(177777777777777777777); + CHECK_OCT_CONST(200000000000000000000); + CHECK_OCT_CONST(377777777777777777777); + CHECK_OCT_CONST(400000000000000000000); + CHECK_OCT_CONST(777777777777777777777); + CHECK_OCT_CONST(1000000000000000000000); + CHECK_OCT_CONST(1777777777777777777777); +#if LLONG_AT_LEAST(65) + CHECK_OCT_CONST(2000000000000000000000); + CHECK_OCT_CONST(3777777777777777777777); +#endif +#if LLONG_AT_LEAST(66) + CHECK_OCT_CONST(4000000000000000000000); + CHECK_OCT_CONST(7777777777777777777777); +#endif +#if LLONG_AT_LEAST(67) + CHECK_OCT_CONST(10000000000000000000000); + CHECK_OCT_CONST(17777777777777777777777); +#endif +#if LLONG_AT_LEAST(68) + CHECK_OCT_CONST(20000000000000000000000); + CHECK_OCT_CONST(37777777777777777777777); +#endif +#if LLONG_AT_LEAST(69) + CHECK_OCT_CONST(40000000000000000000000); + CHECK_OCT_CONST(77777777777777777777777); +#endif +#if LLONG_AT_LEAST(70) + CHECK_OCT_CONST(100000000000000000000000); + CHECK_OCT_CONST(177777777777777777777777); +#endif +#if LLONG_AT_LEAST(71) + CHECK_OCT_CONST(200000000000000000000000); + CHECK_OCT_CONST(377777777777777777777777); +#endif +#if LLONG_AT_LEAST(72) + CHECK_OCT_CONST(400000000000000000000000); + CHECK_OCT_CONST(777777777777777777777777); +#endif +} diff --git a/gcc/testsuite/gcc.dg/octal-constants-2.c b/gcc/testsuite/gcc.dg/octal-constants-2.c new file mode 100644 index 0000000..85c9529 --- /dev/null +++ b/gcc/testsuite/gcc.dg/octal-constants-2.c @@ -0,0 +1,16 @@ +/* Test for octal integer constants: -pedantic warnings. */ + +/* Origin: Joerg Wunsch <j.gnu@uriah.heep.sax.de>. */ +/* { dg-do compile } */ +/* { dg-options "-std=iso9899:1999 -pedantic -ftrack-macro-expansion=0" } */ + +#define FOO 0o1307 + +int +foo (void) +{ +#if FOO /* { dg-warning "'0o' prefixed constants are a C2Y feature or GCC extension" } */ + return 23; +#endif + return 0o1307; /* { dg-warning "'0o' prefixed constants are a C2Y feature or GCC extension" } */ +} diff --git a/gcc/testsuite/gcc.dg/octal-constants-3.c b/gcc/testsuite/gcc.dg/octal-constants-3.c new file mode 100644 index 0000000..0697172 --- /dev/null +++ b/gcc/testsuite/gcc.dg/octal-constants-3.c @@ -0,0 +1,16 @@ +/* Test for octal integer constants: -pedantic-errors. */ + +/* Origin: Joerg Wunsch <j.gnu@uriah.heep.sax.de>. */ +/* { dg-do compile } */ +/* { dg-options "-std=iso9899:1999 -pedantic-errors -ftrack-macro-expansion=0" } */ + +#define FOO 0o1307 + +int +foo (void) +{ +#if FOO /* { dg-error "'0o' prefixed constants are a C2Y feature or GCC extension" } */ + return 23; +#endif + return 0o1307; /* { dg-error "'0o' prefixed constants are a C2Y feature or GCC extension" } */ +} diff --git a/gcc/testsuite/gcc.dg/octal-constants-4.c b/gcc/testsuite/gcc.dg/octal-constants-4.c new file mode 100644 index 0000000..d2141de --- /dev/null +++ b/gcc/testsuite/gcc.dg/octal-constants-4.c @@ -0,0 +1,18 @@ +/* Test for octal integer constants: random errors. */ + +/* Origin: Joerg Wunsch <j.gnu@uriah.heep.sax.de>. */ +/* { dg-do compile } */ +/* { dg-options "-std=gnu99" } */ + +void +foo(void) +{ + double d; + int i; + + d = 0o1307; + d = 0o1307p1; /* { dg-error "invalid suffix 'p1' on integer constant" } */ + d = 0x1307p1; + i = 0oa011; /* { dg-error "invalid suffix 'oa011' on integer constant" } */ + i = 0o118; /* { dg-error "invalid digit '8' in octal constant" } */ +} diff --git a/gcc/testsuite/gcc.dg/system-octal-constants-1.c b/gcc/testsuite/gcc.dg/system-octal-constants-1.c new file mode 100644 index 0000000..a6b8160 --- /dev/null +++ b/gcc/testsuite/gcc.dg/system-octal-constants-1.c @@ -0,0 +1,18 @@ +/* + Origin: Dodji Seketeli <dodji@redhat.com> + { dg-options "-std=iso9899:1999 -pedantic" } + { dg-do compile } + */ + +#include "system-octal-constants-1.h" + +int +foo (void) +{ +#if OCTAL_INT_CONSTANT_IN_SYSTEM_HEADER /* A octal constant defined + in system header. No + warning. */ + return 23; +#endif + return 0o1307; /* { dg-warning "'0o' prefixed constants are a C2Y feature or GCC extension" } */ +} diff --git a/gcc/testsuite/gcc.dg/system-octal-constants-1.h b/gcc/testsuite/gcc.dg/system-octal-constants-1.h new file mode 100644 index 0000000..ec9dbe3 --- /dev/null +++ b/gcc/testsuite/gcc.dg/system-octal-constants-1.h @@ -0,0 +1,3 @@ +#pragma GCC system_header + +#define OCTAL_INT_CONSTANT_IN_SYSTEM_HEADER 0o1307 |