Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src tests/lint: test binary integer literals and underscores



details:   https://anonhg.NetBSD.org/src/rev/2ab574aebd52
branches:  trunk
changeset: 984609:2ab574aebd52
user:      rillig <rillig%NetBSD.org@localhost>
date:      Tue Jul 13 19:38:10 2021 +0000

description:
tests/lint: test binary integer literals and underscores

diffstat:

 distrib/sets/lists/tests/mi                      |   4 ++-
 tests/usr.bin/xlint/lint1/Makefile               |   4 ++-
 tests/usr.bin/xlint/lint1/lex_integer.c          |   9 ++++++-
 tests/usr.bin/xlint/lint1/lex_integer_binary.c   |  30 ++++++++++++++++++++++++
 tests/usr.bin/xlint/lint1/lex_integer_binary.exp |   1 +
 5 files changed, 45 insertions(+), 3 deletions(-)

diffs (95 lines):

diff -r 433598ad6156 -r 2ab574aebd52 distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi       Tue Jul 13 19:11:35 2021 +0000
+++ b/distrib/sets/lists/tests/mi       Tue Jul 13 19:38:10 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1085 2021/07/11 19:24:41 rillig Exp $
+# $NetBSD: mi,v 1.1086 2021/07/13 19:38:10 rillig Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -6260,6 +6260,8 @@
 ./usr/tests/usr.bin/xlint/lint1/lex_floating.exp               tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/lex_integer.c                  tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/lex_integer.exp                        tests-usr.bin-tests     compattestfile,atf
+./usr/tests/usr.bin/xlint/lint1/lex_integer_binary.c           tests-usr.bin-tests     compattestfile,atf
+./usr/tests/usr.bin/xlint/lint1/lex_integer_binary.exp         tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/lex_integer_ilp32.c            tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/lex_integer_ilp32.exp          tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/lex_string.c                   tests-usr.bin-tests     compattestfile,atf
diff -r 433598ad6156 -r 2ab574aebd52 tests/usr.bin/xlint/lint1/Makefile
--- a/tests/usr.bin/xlint/lint1/Makefile        Tue Jul 13 19:11:35 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/Makefile        Tue Jul 13 19:38:10 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.87 2021/07/13 18:50:16 rillig Exp $
+# $NetBSD: Makefile,v 1.88 2021/07/13 19:38:10 rillig Exp $
 
 NOMAN=         # defined
 MAX_MESSAGE=   345             # see lint1/err.c
@@ -161,6 +161,8 @@
 FILES+=                lex_floating.exp
 FILES+=                lex_integer.c
 FILES+=                lex_integer.exp
+FILES+=                lex_integer_binary.c
+FILES+=                lex_integer_binary.exp
 FILES+=                lex_integer_ilp32.c
 FILES+=                lex_integer_ilp32.exp
 FILES+=                lex_string.c
diff -r 433598ad6156 -r 2ab574aebd52 tests/usr.bin/xlint/lint1/lex_integer.c
--- a/tests/usr.bin/xlint/lint1/lex_integer.c   Tue Jul 13 19:11:35 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/lex_integer.c   Tue Jul 13 19:38:10 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lex_integer.c,v 1.5 2021/07/10 18:42:28 rillig Exp $   */
+/*     $NetBSD: lex_integer.c,v 1.6 2021/07/13 19:38:10 rillig Exp $   */
 # 3 "lex_integer.c"
 
 /*
@@ -59,3 +59,10 @@
        /* The 'Ll' must not used mixed case. Checked by the compiler. */
        sinkull(3ULl);
 }
+
+/* https://gcc.gnu.org/onlinedocs/gcc/Binary-constants.html */
+void
+binary_literal(void)
+{
+       sinku(0b1111000001011010);
+}
diff -r 433598ad6156 -r 2ab574aebd52 tests/usr.bin/xlint/lint1/lex_integer_binary.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/usr.bin/xlint/lint1/lex_integer_binary.c    Tue Jul 13 19:38:10 2021 +0000
@@ -0,0 +1,30 @@
+/*     $NetBSD: lex_integer_binary.c,v 1.1 2021/07/13 19:38:10 rillig Exp $    */
+# 3 "lex_integer_binary.c"
+
+/*
+ * Test for parsing binary integer literals in non-GCC mode.
+ * As of C11, binary integer literals are not supported.
+ * Neither are underscores in integer literals.
+ */
+
+/* Remove the default -g flag. */
+/* lint1-flags: -Ac11 -w */
+
+void sink(unsigned int);
+
+void
+binary_literal(void)
+{
+       /*
+        * Binary integer literals are a GCC extension, but lint allows them
+        * even in non-GCC mode.
+        */
+       sink(0b1111000001011010);
+
+       /*
+        * Even though it would be useful for binary literals, GCC does not
+        * support underscores to separate the digit groups.
+        */
+       /* expect+1: syntax error '_0000_0101_1010' [249] */
+       sink(0b1111_0000_0101_1010);
+}
diff -r 433598ad6156 -r 2ab574aebd52 tests/usr.bin/xlint/lint1/lex_integer_binary.exp
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/usr.bin/xlint/lint1/lex_integer_binary.exp  Tue Jul 13 19:38:10 2021 +0000
@@ -0,0 +1,1 @@
+lex_integer_binary.c(29): error: syntax error '_0000_0101_1010' [249]



Home | Main Index | Thread Index | Old Index