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 'dubious ...



details:   https://anonhg.NetBSD.org/src/rev/1a578ec22639
branches:  trunk
changeset: 959859:1a578ec22639
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Feb 27 14:54:55 2021 +0000

description:
tests/lint: add test for 'dubious operation on enum' [241]

diffstat:

 tests/usr.bin/xlint/lint1/msg_241.c   |  72 +++++++++++++++++++++++++++++++++-
 tests/usr.bin/xlint/lint1/msg_241.exp |  46 +++++++++++++++++++++-
 2 files changed, 114 insertions(+), 4 deletions(-)

diffs (130 lines):

diff -r 5d7c47c03f34 -r 1a578ec22639 tests/usr.bin/xlint/lint1/msg_241.c
--- a/tests/usr.bin/xlint/lint1/msg_241.c       Sat Feb 27 14:22:07 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_241.c       Sat Feb 27 14:54:55 2021 +0000
@@ -1,7 +1,73 @@
-/*     $NetBSD: msg_241.c,v 1.2 2021/02/21 09:07:58 rillig Exp $       */
+/*     $NetBSD: msg_241.c,v 1.3 2021/02/27 14:54:55 rillig Exp $       */
 # 3 "msg_241.c"
 
 // Test for message: dubious operation on enum, op %s [241]
+//
+// As of February 2021, the option -e is not enabled by default in
+// share/mk/sys.mk, therefore this message is neither well-known nor
+// well-tested.
 
-TODO: "Add example code that triggers the above message." /* expect: 249 */
-TODO: "Add example code that almost triggers the above message."
+/* lint1-extra-flags: -e */
+
+/*
+ * Enums are a possible implementation of bit-sets.
+ */
+enum color {
+       RED     = 1 << 0,
+       GREEN   = 1 << 1,
+       BLUE    = 1 << 2
+};
+
+extern void sink(int);
+
+void
+example(void)
+{
+       enum color c = RED;
+
+       sink(!c);                       /* expect: 241 */
+       sink(~c);                       /* expect: 241, 278 */
+       ++c;                            /* expect: 241 */
+       --c;                            /* expect: 241 */
+       c++;                            /* expect: 241 */
+       c--;                            /* expect: 241 */
+       sink(+c);                       /* expect: 241, 278 */
+       sink(-c);                       /* expect: 241, 278 */
+       sink(c * c);                    /* expect: 241, 278 */
+       sink(c / c);                    /* expect: 241, 278 */
+       sink(c % c);                    /* expect: 241, 278 */
+       sink(c + c);                    /* expect: 241, 278 */
+       sink(c - c);                    /* expect: 241, 278 */
+       sink(c << c);                   /* expect: 241, 278 */
+       sink(c >> c);                   /* expect: 241, 278 */
+
+       sink(c < c);
+       sink(c <= c);
+       sink(c > c);
+       sink(c >= c);
+       sink(c == c);
+       sink(c != c);
+
+       sink(c & c);                    /* expect: 241, 278 */
+       sink(c ^ c);                    /* expect: 241, 278 */
+       sink(c | c);                    /* expect: 241, 278 */
+
+       sink(c && c);                   /* expect: 241 */
+       sink(c || c);                   /* expect: 241 */
+       sink(c ? c : BLUE);             /* expect: 278 */
+
+       c = GREEN;
+       c *= c;                         /* expect: 241 */
+       c /= c;                         /* expect: 241 */
+       c %= c;                         /* expect: 241 */
+       c += c;                         /* expect: 241 */
+       c -= c;                         /* expect: 241 */
+       c <<= c;                        /* expect: 241 */
+       c >>= c;                        /* expect: 241 */
+       c &= c;                         /* expect: 241 */
+       c ^= c;                         /* expect: 241 */
+       c |= c;                         /* expect: 241 */
+
+       /* The cast to unsigned is required by GCC at WARNS=6. */
+       c &= ~(unsigned)GREEN;          /* expect: 241 */
+}
diff -r 5d7c47c03f34 -r 1a578ec22639 tests/usr.bin/xlint/lint1/msg_241.exp
--- a/tests/usr.bin/xlint/lint1/msg_241.exp     Sat Feb 27 14:22:07 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_241.exp     Sat Feb 27 14:54:55 2021 +0000
@@ -1,1 +1,45 @@
-msg_241.c(6): syntax error ':' [249]
+msg_241.c(28): warning: dubious operation on enum, op ! [241]
+msg_241.c(29): warning: dubious operation on enum, op ~ [241]
+msg_241.c(29): warning: combination of 'int' and 'enum color', arg #1 [278]
+msg_241.c(30): warning: dubious operation on enum, op ++x [241]
+msg_241.c(31): warning: dubious operation on enum, op --x [241]
+msg_241.c(32): warning: dubious operation on enum, op x++ [241]
+msg_241.c(33): warning: dubious operation on enum, op x-- [241]
+msg_241.c(34): warning: dubious operation on enum, op + [241]
+msg_241.c(34): warning: combination of 'int' and 'enum color', arg #1 [278]
+msg_241.c(35): warning: dubious operation on enum, op - [241]
+msg_241.c(35): warning: combination of 'int' and 'enum color', arg #1 [278]
+msg_241.c(36): warning: dubious operation on enum, op * [241]
+msg_241.c(36): warning: combination of 'int' and 'enum color', arg #1 [278]
+msg_241.c(37): warning: dubious operation on enum, op / [241]
+msg_241.c(37): warning: combination of 'int' and 'enum color', arg #1 [278]
+msg_241.c(38): warning: dubious operation on enum, op % [241]
+msg_241.c(38): warning: combination of 'int' and 'enum color', arg #1 [278]
+msg_241.c(39): warning: dubious operation on enum, op + [241]
+msg_241.c(39): warning: combination of 'int' and 'enum color', arg #1 [278]
+msg_241.c(40): warning: dubious operation on enum, op - [241]
+msg_241.c(40): warning: combination of 'int' and 'enum color', arg #1 [278]
+msg_241.c(41): warning: dubious operation on enum, op << [241]
+msg_241.c(41): warning: combination of 'int' and 'enum color', arg #1 [278]
+msg_241.c(42): warning: dubious operation on enum, op >> [241]
+msg_241.c(42): warning: combination of 'int' and 'enum color', arg #1 [278]
+msg_241.c(51): warning: dubious operation on enum, op & [241]
+msg_241.c(51): warning: combination of 'int' and 'enum color', arg #1 [278]
+msg_241.c(52): warning: dubious operation on enum, op ^ [241]
+msg_241.c(52): warning: combination of 'int' and 'enum color', arg #1 [278]
+msg_241.c(53): warning: dubious operation on enum, op | [241]
+msg_241.c(53): warning: combination of 'int' and 'enum color', arg #1 [278]
+msg_241.c(55): warning: dubious operation on enum, op && [241]
+msg_241.c(56): warning: dubious operation on enum, op || [241]
+msg_241.c(57): warning: combination of 'int' and 'enum color', arg #1 [278]
+msg_241.c(60): warning: dubious operation on enum, op *= [241]
+msg_241.c(61): warning: dubious operation on enum, op /= [241]
+msg_241.c(62): warning: dubious operation on enum, op %= [241]
+msg_241.c(63): warning: dubious operation on enum, op += [241]
+msg_241.c(64): warning: dubious operation on enum, op -= [241]
+msg_241.c(65): warning: dubious operation on enum, op <<= [241]
+msg_241.c(66): warning: dubious operation on enum, op >>= [241]
+msg_241.c(67): warning: dubious operation on enum, op &= [241]
+msg_241.c(68): warning: dubious operation on enum, op ^= [241]
+msg_241.c(69): warning: dubious operation on enum, op |= [241]
+msg_241.c(72): warning: dubious operation on enum, op &= [241]



Home | Main Index | Thread Index | Old Index