diff options
author | Joseph Myers <joseph@codesourcery.com> | 2020-11-13 22:45:22 +0000 |
---|---|---|
committer | Joseph Myers <joseph@codesourcery.com> | 2020-11-13 22:45:22 +0000 |
commit | e400a64936efdc2424044aa74c0424df16242d2d (patch) | |
tree | 5306e5a590540d75f925bd5f41600102ed65039c /gcc | |
parent | f3dc991fba095b38b15cd667e5cd15b1c418e809 (diff) | |
download | gcc-e400a64936efdc2424044aa74c0424df16242d2d.zip gcc-e400a64936efdc2424044aa74c0424df16242d2d.tar.gz gcc-e400a64936efdc2424044aa74c0424df16242d2d.tar.bz2 |
c: C2x binary constants
C2x adds binary integer constants (approved at the last WG14 meeting,
though not yet added to the working draft in git). Configure libcpp
to consider these a standard feature in C2x mode, with appropriate
updates to diagnostics including support for diagnosing them with
-std=c2x -Wc11-c2x-compat.
Bootstrapped with no regressions for x86_64-pc-linux-gnu.
gcc/testsuite/
2020-11-13 Joseph Myers <joseph@codesourcery.com>
* gcc.dg/binary-constants-2.c, gcc.dg/binary-constants-3.c,
gcc.dg/system-binary-constants-1.c: Update expected diagnostics.
* gcc.dg/c11-binary-constants-1.c,
gcc.dg/c11-binary-constants-2.c, gcc.dg/c2x-binary-constants-1.c,
gcc.dg/c2x-binary-constants-2.c, gcc.dg/c2x-binary-constants-3.c:
New tests.
libcpp/
2020-11-13 Joseph Myers <joseph@codesourcery.com>
* expr.c (cpp_classify_number): Update diagnostic for binary
constants for C. Also diagnose binary constants for
-Wc11-c2x-compat.
* init.c (lang_defaults): Enable binary constants for GNUC2X and
STDC2X.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/testsuite/gcc.dg/binary-constants-2.c | 4 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/binary-constants-3.c | 4 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/c11-binary-constants-1.c | 11 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/c11-binary-constants-2.c | 11 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/c2x-binary-constants-1.c | 5 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/c2x-binary-constants-2.c | 11 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/c2x-binary-constants-3.c | 9 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/system-binary-constants-1.c | 2 |
8 files changed, 52 insertions, 5 deletions
diff --git a/gcc/testsuite/gcc.dg/binary-constants-2.c b/gcc/testsuite/gcc.dg/binary-constants-2.c index 6c3928a..5339d57 100644 --- a/gcc/testsuite/gcc.dg/binary-constants-2.c +++ b/gcc/testsuite/gcc.dg/binary-constants-2.c @@ -9,8 +9,8 @@ int foo (void) { -#if FOO /* { dg-warning "binary constants are a GCC extension" } */ +#if FOO /* { dg-warning "binary constants are a C2X feature or GCC extension" } */ return 23; #endif - return 0b1101; /* { dg-warning "binary constants are a GCC extension" } */ + return 0b1101; /* { dg-warning "binary constants are a C2X feature or GCC extension" } */ } diff --git a/gcc/testsuite/gcc.dg/binary-constants-3.c b/gcc/testsuite/gcc.dg/binary-constants-3.c index 410fc4c..5b49cb4 100644 --- a/gcc/testsuite/gcc.dg/binary-constants-3.c +++ b/gcc/testsuite/gcc.dg/binary-constants-3.c @@ -9,8 +9,8 @@ int foo (void) { -#if FOO /* { dg-error "binary constants are a GCC extension" } */ +#if FOO /* { dg-error "binary constants are a C2X feature or GCC extension" } */ return 23; #endif - return 0b1101; /* { dg-error "binary constants are a GCC extension" } */ + return 0b1101; /* { dg-error "binary constants are a C2X feature or GCC extension" } */ } diff --git a/gcc/testsuite/gcc.dg/c11-binary-constants-1.c b/gcc/testsuite/gcc.dg/c11-binary-constants-1.c new file mode 100644 index 0000000..fdc7df4 --- /dev/null +++ b/gcc/testsuite/gcc.dg/c11-binary-constants-1.c @@ -0,0 +1,11 @@ +/* Test that binary constants are diagnosed in C11 mode: -pedantic. */ +/* { dg-do compile } */ +/* { dg-options "-std=c11 -pedantic" } */ + +int a = 0b1; /* { dg-warning "binary constants" } */ +#if 0b101 /* { dg-warning "binary constants" } */ +#endif + +int b = 0B1; /* { dg-warning "binary constants" } */ +#if 0B101 /* { dg-warning "binary constants" } */ +#endif diff --git a/gcc/testsuite/gcc.dg/c11-binary-constants-2.c b/gcc/testsuite/gcc.dg/c11-binary-constants-2.c new file mode 100644 index 0000000..6b48a5d --- /dev/null +++ b/gcc/testsuite/gcc.dg/c11-binary-constants-2.c @@ -0,0 +1,11 @@ +/* Test that binary constants are diagnosed in C11 mode: -pedantic-errors. */ +/* { dg-do compile } */ +/* { dg-options "-std=c11 -pedantic-errors" } */ + +int a = 0b1; /* { dg-error "binary constants" } */ +#if 0b101 /* { dg-error "binary constants" } */ +#endif + +int b = 0B1; /* { dg-error "binary constants" } */ +#if 0B101 /* { dg-error "binary constants" } */ +#endif diff --git a/gcc/testsuite/gcc.dg/c2x-binary-constants-1.c b/gcc/testsuite/gcc.dg/c2x-binary-constants-1.c new file mode 100644 index 0000000..bbb2bc8 --- /dev/null +++ b/gcc/testsuite/gcc.dg/c2x-binary-constants-1.c @@ -0,0 +1,5 @@ +/* Test C2x binary constants. Valid syntax and types. */ +/* { dg-do compile } */ +/* { dg-options "-std=c2x -pedantic-errors" } */ + +#include "binary-constants-1.c" diff --git a/gcc/testsuite/gcc.dg/c2x-binary-constants-2.c b/gcc/testsuite/gcc.dg/c2x-binary-constants-2.c new file mode 100644 index 0000000..4379427 --- /dev/null +++ b/gcc/testsuite/gcc.dg/c2x-binary-constants-2.c @@ -0,0 +1,11 @@ +/* Test that binary constants are accepted in C2X mode: compat warnings. */ +/* { dg-do compile } */ +/* { dg-options "-std=c2x -Wc11-c2x-compat" } */ + +int a = 0b1; /* { dg-warning "C2X feature" } */ +#if 0b101 /* { dg-warning "C2X feature" } */ +#endif + +int b = 0B1; /* { dg-warning "C2X feature" } */ +#if 0B101 /* { dg-warning "C2X feature" } */ +#endif diff --git a/gcc/testsuite/gcc.dg/c2x-binary-constants-3.c b/gcc/testsuite/gcc.dg/c2x-binary-constants-3.c new file mode 100644 index 0000000..7604791f --- /dev/null +++ b/gcc/testsuite/gcc.dg/c2x-binary-constants-3.c @@ -0,0 +1,9 @@ +/* Test C2x binary constants. Invalid constants. */ +/* { dg-do compile } */ +/* { dg-options "-std=c2x -pedantic-errors" } */ + +int a = 0b; /* { dg-error "invalid suffix" } */ +int b = 0B2; /* { dg-error "invalid suffix" } */ +int c = 0B02; /* { dg-error "invalid digit" } */ +int d = 0b1.1; /* { dg-error "invalid prefix" } */ +int e = 0B0p0; /* { dg-error "invalid suffix" } */ diff --git a/gcc/testsuite/gcc.dg/system-binary-constants-1.c b/gcc/testsuite/gcc.dg/system-binary-constants-1.c index 921ee20..ca16215 100644 --- a/gcc/testsuite/gcc.dg/system-binary-constants-1.c +++ b/gcc/testsuite/gcc.dg/system-binary-constants-1.c @@ -14,5 +14,5 @@ foo (void) warning. */ return 23; #endif - return 0b1101; /* { dg-warning "binary constants are a GCC extension" } */ + return 0b1101; /* { dg-warning "binary constants are a C2X feature or GCC extension" } */ } |