Source-Changes-HG archive

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

[src/trunk]: src tests/lint: test precedence of operators



details:   https://anonhg.NetBSD.org/src/rev/79781a43772b
branches:  trunk
changeset: 1022387:79781a43772b
user:      rillig <rillig%NetBSD.org@localhost>
date:      Thu Jul 15 17:09:08 2021 +0000

description:
tests/lint: test precedence of operators

diffstat:

 distrib/sets/lists/tests/mi                   |   4 ++-
 tests/usr.bin/xlint/lint1/Makefile            |   4 ++-
 tests/usr.bin/xlint/lint1/expr_precedence.c   |  31 +++++++++++++++++++++++++++
 tests/usr.bin/xlint/lint1/expr_precedence.exp |   4 +++
 4 files changed, 41 insertions(+), 2 deletions(-)

diffs (79 lines):

diff -r e86af9927463 -r 79781a43772b distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi       Thu Jul 15 17:03:50 2021 +0000
+++ b/distrib/sets/lists/tests/mi       Thu Jul 15 17:09:08 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1088 2021/07/14 20:39:13 rillig Exp $
+# $NetBSD: mi,v 1.1089 2021/07/15 17:09:08 rillig Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -6224,6 +6224,8 @@
 ./usr/tests/usr.bin/xlint/lint1/emit.exp                       tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/emit.exp-ln                    tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/emit.ln                                tests-obsolete          obsolete
+./usr/tests/usr.bin/xlint/lint1/expr_precedence.c              tests-usr.bin-tests     compattestfile,atf
+./usr/tests/usr.bin/xlint/lint1/expr_precedence.exp            tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/expr_range.c                   tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/expr_range.exp                 tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/feat_stacktrace.c              tests-usr.bin-tests     compattestfile,atf
diff -r e86af9927463 -r 79781a43772b tests/usr.bin/xlint/lint1/Makefile
--- a/tests/usr.bin/xlint/lint1/Makefile        Thu Jul 15 17:03:50 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/Makefile        Thu Jul 15 17:09:08 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.89 2021/07/14 20:39:13 rillig Exp $
+# $NetBSD: Makefile,v 1.90 2021/07/15 17:09:08 rillig Exp $
 
 NOMAN=         # defined
 MAX_MESSAGE=   345             # see lint1/err.c
@@ -123,6 +123,8 @@
 FILES+=                emit.c
 FILES+=                emit.exp
 FILES+=                emit.exp-ln
+FILES+=                expr_precedence.c
+FILES+=                expr_precedence.exp
 FILES+=                expr_range.c
 FILES+=                expr_range.exp
 FILES+=                feat_stacktrace.c
diff -r e86af9927463 -r 79781a43772b tests/usr.bin/xlint/lint1/expr_precedence.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/usr.bin/xlint/lint1/expr_precedence.c       Thu Jul 15 17:09:08 2021 +0000
@@ -0,0 +1,31 @@
+/*     $NetBSD: expr_precedence.c,v 1.1 2021/07/15 17:09:08 rillig Exp $       */
+# 3 "expr_precedence.c"
+
+/*
+ * Tests for the precedence among operators.
+ */
+
+int var;
+
+/*
+ * An initializer needs an assignment-expression; the comma must be
+ * interpreted as a separator, not an operator.
+ */
+/* expect+1: error: syntax error '4' [249] */
+int init_error = 3, 4;
+
+/* expect+1: error: non-constant initializer [177] */
+int init_syntactically_ok = var = 1 ? 2 : 3;
+
+/*
+ * The arguments of __attribute__ must be constant-expression, as assignments
+ * don't make sense at that point.
+ */
+void __attribute__((format(printf,
+    /* expect+2: error: 'var' undefined [99] */ /* XXX: why? */
+    /* XXX: allow only constant-expression, not assignment-expression */
+    var = 1,
+    /* Syntactically ok, must be a constant expression though. */
+    /* expect+1: error: 'var' undefined [99] */
+    var > 0 ? 2 : 1)))
+my_printf(const char *, ...);
diff -r e86af9927463 -r 79781a43772b tests/usr.bin/xlint/lint1/expr_precedence.exp
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/usr.bin/xlint/lint1/expr_precedence.exp     Thu Jul 15 17:09:08 2021 +0000
@@ -0,0 +1,4 @@
+expr_precedence.c(15): error: syntax error '4' [249]
+expr_precedence.c(18): error: non-constant initializer [177]
+expr_precedence.c(27): error: 'var' undefined [99]
+expr_precedence.c(30): error: 'var' undefined [99]



Home | Main Index | Thread Index | Old Index