Source-Changes-HG archive

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

[src/trunk]: src/tests/usr.bin/xlint/lint1 tests/lint: add test for message 1...



details:   https://anonhg.NetBSD.org/src/rev/723a43c63add
branches:  trunk
changeset: 953686:723a43c63add
user:      rillig <rillig%NetBSD.org@localhost>
date:      Tue Mar 16 23:18:49 2021 +0000

description:
tests/lint: add test for message 139 about division by zero

diffstat:

 tests/usr.bin/xlint/lint1/msg_139.c   |  23 ++++++++++++++++++++---
 tests/usr.bin/xlint/lint1/msg_139.exp |   5 ++++-
 2 files changed, 24 insertions(+), 4 deletions(-)

diffs (40 lines):

diff -r 15897f81d1fb -r 723a43c63add tests/usr.bin/xlint/lint1/msg_139.c
--- a/tests/usr.bin/xlint/lint1/msg_139.c       Tue Mar 16 23:12:30 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_139.c       Tue Mar 16 23:18:49 2021 +0000
@@ -1,7 +1,24 @@
-/*     $NetBSD: msg_139.c,v 1.2 2021/02/21 09:07:58 rillig Exp $       */
+/*     $NetBSD: msg_139.c,v 1.3 2021/03/16 23:18:49 rillig Exp $       */
 # 3 "msg_139.c"
 
 // Test for message: division by 0 [139]
 
-TODO: "Add example code that triggers the above message." /* expect: 249 */
-TODO: "Add example code that almost triggers the above message."
+void sink_int(int);
+void sink_double(double);
+
+void
+example(int i)
+{
+       enum {
+               zero = 0
+       };
+
+       sink_int(i / 0);        /* only triggers in constant expressions */
+       sink_int(i / zero);     /* only triggers in constant expressions */
+       sink_double(i / 0.0);
+
+       sink_int(13 / 0);       /* expect: 139 */
+       sink_int(13 / zero);    /* expect: 139 */
+       sink_double(13 / 0.0);  /* expect: 139 *//* XXX: Clang doesn't warn */
+       sink_double(13 / -0.0); /* expect: 139 *//* XXX: Clang doesn't warn */
+}
diff -r 15897f81d1fb -r 723a43c63add tests/usr.bin/xlint/lint1/msg_139.exp
--- a/tests/usr.bin/xlint/lint1/msg_139.exp     Tue Mar 16 23:12:30 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_139.exp     Tue Mar 16 23:18:49 2021 +0000
@@ -1,1 +1,4 @@
-msg_139.c(6): syntax error ':' [249]
+msg_139.c(20): division by 0 [139]
+msg_139.c(21): division by 0 [139]
+msg_139.c(22): division by 0 [139]
+msg_139.c(23): division by 0 [139]



Home | Main Index | Thread Index | Old Index