Module Name: src Committed By: rillig Date: Tue Oct 29 20:39:53 UTC 2024
Modified Files: src/tests/usr.bin/xlint/lint1: msg_129.c Log Message: tests/lint: demonstrate wrong warning about 'null effect' Seen in sys/timevar.h:250 and other places. To generate a diff of this commit: cvs rdiff -u -r1.8 -r1.9 src/tests/usr.bin/xlint/lint1/msg_129.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/tests/usr.bin/xlint/lint1/msg_129.c diff -u src/tests/usr.bin/xlint/lint1/msg_129.c:1.8 src/tests/usr.bin/xlint/lint1/msg_129.c:1.9 --- src/tests/usr.bin/xlint/lint1/msg_129.c:1.8 Wed Aug 2 18:51:25 2023 +++ src/tests/usr.bin/xlint/lint1/msg_129.c Tue Oct 29 20:39:52 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: msg_129.c,v 1.8 2023/08/02 18:51:25 rillig Exp $ */ +/* $NetBSD: msg_129.c,v 1.9 2024/10/29 20:39:52 rillig Exp $ */ # 3 "msg_129.c" // Test for message: expression has null effect [129] @@ -64,7 +64,7 @@ legitimate_use_cases(int arg) */ (void)local; - /* This is a short-hand notation for a do-nothing command. */ + /* This is a shorthand notation for a do-nothing command. */ (void)0; /* @@ -78,7 +78,8 @@ legitimate_use_cases(int arg) /* * 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. + * statements. It is longer than the above variant, and it is not + * embeddable into an expression. */ do { } while (0); @@ -94,3 +95,31 @@ legitimate_use_cases(int arg) /* expect+1: warning: expression has null effect [129] */ (void)(void)0; } + +int +return_statement_expression(int arg) +{ + ({ + int local = arg; + /* XXX: redundant warning, also occurs outside the braces. */ + /* expect+1: warning: expression has null effect [129] */ + local + 4; + /* expect+1: warning: expression has null effect [129] */ + }); + + if (arg == 1) + return ({ + int local = arg; + /* FIXME: The expression _does_ have an effect. */ + /* expect+1: warning: expression has null effect [129] */ + local; + }); + if (arg == 2) + return ({ + int local = arg; + /* FIXME: The expression _does_ have an effect. */ + /* expect+1: warning: expression has null effect [129] */ + local + 4; + }); + return 0; +}