aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gcc/testsuite/gcc.dg/binary-constants-2.c4
-rw-r--r--gcc/testsuite/gcc.dg/binary-constants-3.c4
-rw-r--r--gcc/testsuite/gcc.dg/c11-binary-constants-1.c11
-rw-r--r--gcc/testsuite/gcc.dg/c11-binary-constants-2.c11
-rw-r--r--gcc/testsuite/gcc.dg/c2x-binary-constants-1.c5
-rw-r--r--gcc/testsuite/gcc.dg/c2x-binary-constants-2.c11
-rw-r--r--gcc/testsuite/gcc.dg/c2x-binary-constants-3.c9
-rw-r--r--gcc/testsuite/gcc.dg/system-binary-constants-1.c2
-rw-r--r--libcpp/expr.c23
-rw-r--r--libcpp/init.c4
10 files changed, 69 insertions, 15 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..4379427d
--- /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" } */
}
diff --git a/libcpp/expr.c b/libcpp/expr.c
index e01a47a..b98c038 100644
--- a/libcpp/expr.c
+++ b/libcpp/expr.c
@@ -812,14 +812,21 @@ cpp_classify_number (cpp_reader *pfile, const cpp_token *token,
if ((result & CPP_N_IMAGINARY) && CPP_PEDANTIC (pfile))
cpp_error_with_line (pfile, CPP_DL_PEDWARN, virtual_location, 0,
"imaginary constants are a GCC extension");
- if (radix == 2
- && !CPP_OPTION (pfile, binary_constants)
- && CPP_PEDANTIC (pfile))
- cpp_error_with_line (pfile, CPP_DL_PEDWARN, virtual_location, 0,
- CPP_OPTION (pfile, cplusplus)
- ? N_("binary constants are a C++14 feature "
- "or GCC extension")
- : N_("binary constants are a GCC extension"));
+ if (radix == 2)
+ {
+ if (!CPP_OPTION (pfile, binary_constants)
+ && CPP_PEDANTIC (pfile))
+ cpp_error_with_line (pfile, CPP_DL_PEDWARN, virtual_location, 0,
+ CPP_OPTION (pfile, cplusplus)
+ ? N_("binary constants are a C++14 feature "
+ "or GCC extension")
+ : N_("binary constants are a C2X feature "
+ "or GCC extension"));
+ else if (CPP_OPTION (pfile, cpp_warn_c11_c2x_compat) > 0)
+ cpp_warning_with_line (pfile, CPP_W_C11_C2X_COMPAT,
+ virtual_location, 0,
+ "binary constants are a C2X feature");
+ }
if (radix == 10)
result |= CPP_N_DECIMAL;
diff --git a/libcpp/init.c b/libcpp/init.c
index 1b43802..76882bc 100644
--- a/libcpp/init.c
+++ b/libcpp/init.c
@@ -102,13 +102,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 },
/* GNUC11 */ { 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0 },
/* GNUC17 */ { 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0 },
- /* GNUC2X */ { 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1 },
+ /* GNUC2X */ { 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 1 },
/* STDC89 */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 },
/* STDC94 */ { 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 },
/* STDC99 */ { 1, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 },
/* STDC11 */ { 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0 },
/* STDC17 */ { 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0 },
- /* STDC2X */ { 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 1, 1 },
+ /* STDC2X */ { 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1 },
/* GNUCXX */ { 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0 },
/* CXX98 */ { 0, 1, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0 },
/* GNUCXX11 */ { 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0 },