preprocessor: Enable digit separators for C2X
C2X adds digit separators, as in C++. Enable them accordingly in libcpp and c-lex.c. Some basic tests are added that digit separators behave as expected for C2X and are properly disabled for C11; further test coverage is included in the existing g++.dg/cpp1y/digit-sep*.C tests. Bootstrapped with no regressions for x86_64-pc-linux-gnu. gcc/c-family/ * c-lex.c (interpret_float): Handle digit separators for C2X. libcpp/ * init.c (lang_defaults): Enable digit separators for GNUC2X and STDC2X. gcc/testsuite/ * gcc.dg/c11-digit-separators-1.c, gcc.dg/c2x-digit-separators-1.c, gcc.dg/c2x-digit-separators-2.c: New tests.
This commit is contained in:
parent
010d4a5047
commit
5ea40269a7
5 changed files with 74 additions and 3 deletions
|
@ -1001,7 +1001,7 @@ interpret_float (const cpp_token *token, unsigned int flags,
|
|||
}
|
||||
|
||||
copy = (char *) alloca (copylen + 1);
|
||||
if (cxx_dialect > cxx11)
|
||||
if (c_dialect_cxx () ? cxx_dialect > cxx11 : flag_isoc2x)
|
||||
{
|
||||
size_t maxlen = 0;
|
||||
for (size_t i = 0; i < copylen; ++i)
|
||||
|
|
7
gcc/testsuite/gcc.dg/c11-digit-separators-1.c
Normal file
7
gcc/testsuite/gcc.dg/c11-digit-separators-1.c
Normal file
|
@ -0,0 +1,7 @@
|
|||
/* Test C2x digit separators not in C11. */
|
||||
/* { dg-do compile } */
|
||||
/* { dg-options "-std=c11 -pedantic-errors" } */
|
||||
|
||||
#define m(x) 0
|
||||
|
||||
_Static_assert (m(1'2)+(3'4) == 0, "digit separators");
|
39
gcc/testsuite/gcc.dg/c2x-digit-separators-1.c
Normal file
39
gcc/testsuite/gcc.dg/c2x-digit-separators-1.c
Normal file
|
@ -0,0 +1,39 @@
|
|||
/* Test C2x digit separators. Valid usages. */
|
||||
/* { dg-do run } */
|
||||
/* { dg-options "-std=c2x -pedantic-errors" } */
|
||||
|
||||
_Static_assert (123'45'6 == 123456);
|
||||
_Static_assert (0'123 == 0123);
|
||||
_Static_assert (0x1'23 == 0x123);
|
||||
|
||||
#define m(x) 0
|
||||
|
||||
_Static_assert (m(1'2)+(3'4) == 34);
|
||||
|
||||
_Static_assert (0x0'e-0xe == 0);
|
||||
|
||||
#define a0 '.' -
|
||||
#define acat(x) a ## x
|
||||
_Static_assert (acat (0'.') == 0);
|
||||
|
||||
#define c0(x) 0
|
||||
#define b0 c0 (
|
||||
#define bcat(x) b ## x
|
||||
_Static_assert (bcat (0'\u00c0')) == 0);
|
||||
|
||||
extern void exit (int);
|
||||
extern void abort (void);
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
if (314'159e-0'5f != 3.14159f)
|
||||
abort ();
|
||||
exit (0);
|
||||
}
|
||||
|
||||
#line 0'123
|
||||
_Static_assert (__LINE__ == 123);
|
||||
|
||||
#line 4'56'7'8'9
|
||||
_Static_assert (__LINE__ == 456789);
|
25
gcc/testsuite/gcc.dg/c2x-digit-separators-2.c
Normal file
25
gcc/testsuite/gcc.dg/c2x-digit-separators-2.c
Normal file
|
@ -0,0 +1,25 @@
|
|||
/* Test C2x digit separators. Invalid usages. */
|
||||
/* { dg-do compile } */
|
||||
/* { dg-options "-std=c2x -pedantic-errors" } */
|
||||
|
||||
void
|
||||
tf (void)
|
||||
{
|
||||
int i;
|
||||
i = 1''2; /* { dg-error "adjacent digit separators" } */
|
||||
i = 0x'0; /* { dg-error "digit separator after base indicator" } */
|
||||
i = 0X'1; /* { dg-error "digit separator after base indicator" } */
|
||||
i = 0b'0; /* { dg-error "digit separator after base indicator" } */
|
||||
i = 0B'1; /* { dg-error "digit separator after base indicator" } */
|
||||
i = 1'u; /* { dg-error "digit separator outside digit sequence" } */
|
||||
float f = 1.2e-3'f; /* { dg-error "digit separator outside digit sequence" } */
|
||||
i = 1'2'3'; /* { dg-error "12:missing terminating" } */
|
||||
;
|
||||
double d;
|
||||
d = 1'.2'3e-4; /* { dg-warning "multi-character" } */
|
||||
/* { dg-error "expected" "parse error" { target *-*-* } .-1 } */
|
||||
d = 1.2''3; /* { dg-error "adjacent digit separators" } */
|
||||
d = 1.23e-4''5; /* { dg-error "adjacent digit separators" } */
|
||||
d = 1.2'3e-4'5'; /* { dg-error "17:missing terminating" } */
|
||||
/* { dg-error "expected" "parse error" { target *-*-* } .-1 } */
|
||||
}
|
|
@ -103,13 +103,13 @@ static const struct lang_flags lang_defaults[] =
|
|||
/* GNUC99 */ { 1, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0 },
|
||||
/* GNUC11 */ { 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0 },
|
||||
/* GNUC17 */ { 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0 },
|
||||
/* GNUC2X */ { 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 1, 0 },
|
||||
/* GNUC2X */ { 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0 },
|
||||
/* STDC89 */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0 },
|
||||
/* STDC94 */ { 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0 },
|
||||
/* STDC99 */ { 1, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0 },
|
||||
/* STDC11 */ { 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0 },
|
||||
/* STDC17 */ { 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0 },
|
||||
/* STDC2X */ { 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 0 },
|
||||
/* STDC2X */ { 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 0 },
|
||||
/* GNUCXX */ { 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0 },
|
||||
/* CXX98 */ { 0, 1, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0 },
|
||||
/* GNUCXX11 */ { 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0 },
|
||||
|
|
Loading…
Add table
Reference in a new issue