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: demonstrate wrong warn...



details:   https://anonhg.NetBSD.org/src/rev/8b4c22114c98
branches:  trunk
changeset: 985361:8b4c22114c98
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Aug 21 07:52:07 2021 +0000

description:
tests/lint: demonstrate wrong warnings for 'null effect' expressions

diffstat:

 tests/usr.bin/xlint/lint1/msg_129.c   |  52 ++++++++++++++++++++++++++++++++--
 tests/usr.bin/xlint/lint1/msg_129.exp |   4 ++
 2 files changed, 53 insertions(+), 3 deletions(-)

diffs (80 lines):

diff -r 85d7207b64f9 -r 8b4c22114c98 tests/usr.bin/xlint/lint1/msg_129.c
--- a/tests/usr.bin/xlint/lint1/msg_129.c       Sat Aug 21 07:49:48 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_129.c       Sat Aug 21 07:52:07 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: msg_129.c,v 1.3 2021/01/30 23:05:08 rillig Exp $       */
+/*     $NetBSD: msg_129.c,v 1.4 2021/08/21 07:52:07 rillig Exp $       */
 # 3 "msg_129.c"
 
 // Test for message: expression has null effect [129]
@@ -15,8 +15,8 @@
  * wrongly reported as having no side effect.
  *
  * The bug was that has_side_effect did not properly examine the sub-nodes.
- * The ',' operator has m_has_side_effect == false since it depends on its
- * operands whether the ',' actually has side effects.  For nested ','
+ * The ',' operator itself has m_has_side_effect == false since it depends
+ * on its operands whether the ',' actually has side effects.  For nested ','
  * operators, the function did not evaluate the operands deeply but only did
  * a quick shallow test on the m_has_side_effect property.  Since that is
  * false, lint thought that the whole expression would have no side effect.
@@ -41,3 +41,49 @@
        if (0, side_effect())           /* expect: 129 */
                return;
 }
+
+void
+legitimate_use_cases(int arg)
+{
+       int local = 3;
+
+       /*
+        * This expression is commonly used to mark the argument as
+        * deliberately unused.
+        */
+       /* TODO: remove this bogus warning. */
+       /* expect+1: warning: expression has null effect [129] */
+       (void)arg;
+
+       /*
+        * This expression is commonly used to mark the local variable as
+        * deliberately unused.  This situation occurs when the local
+        * variable is only used in some but not all compile-time selectable
+        * variants of the code, such as in debugging mode, and writing down
+        * the exact conditions would complicate the code unnecessarily.
+        */
+       /* TODO: remove this bogus warning. */
+       /* expect+1: warning: expression has null effect [129] */
+       (void)local;
+
+       /* This is a short-hand notation for a do-nothing command. */
+       /* TODO: remove this bogus warning. */
+       /* expect+1: warning: expression has null effect [129] */
+       (void)0;
+
+       /*
+        * This variant of the do-nothing command is commonly used in
+        * preprocessor macros since it works nicely with if-else and if-then
+        * statements.  It is longer than the above variant though.
+        */
+       do {
+       } while (0);
+
+       /*
+        * Only the expression '(void)0' is common, other expressions are
+        * unusual enough that they warrant a warning.
+        */
+       /* TODO: remove this bogus warning. */
+       /* expect+1: warning: expression has null effect [129] */
+       (void)13;
+}
diff -r 85d7207b64f9 -r 8b4c22114c98 tests/usr.bin/xlint/lint1/msg_129.exp
--- a/tests/usr.bin/xlint/lint1/msg_129.exp     Sat Aug 21 07:49:48 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_129.exp     Sat Aug 21 07:52:07 2021 +0000
@@ -1,2 +1,6 @@
 msg_129.c(37): warning: expression has null effect [129]
 msg_129.c(41): warning: expression has null effect [129]
+msg_129.c(56): warning: expression has null effect [129]
+msg_129.c(67): warning: expression has null effect [129]
+msg_129.c(72): warning: expression has null effect [129]
+msg_129.c(88): warning: expression has null effect [129]



Home | Main Index | Thread Index | Old Index