Module Name: src Committed By: rillig Date: Mon Dec 9 22:43:33 UTC 2024
Modified Files: src/tests/usr.bin/xlint/lint1: msg_126.c Log Message: tests/lint: test more cases of type mismatch in '?:' To generate a diff of this commit: cvs rdiff -u -r1.8 -r1.9 src/tests/usr.bin/xlint/lint1/msg_126.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_126.c diff -u src/tests/usr.bin/xlint/lint1/msg_126.c:1.8 src/tests/usr.bin/xlint/lint1/msg_126.c:1.9 --- src/tests/usr.bin/xlint/lint1/msg_126.c:1.8 Sun Aug 6 19:44:50 2023 +++ src/tests/usr.bin/xlint/lint1/msg_126.c Mon Dec 9 22:43:33 2024 @@ -1,15 +1,27 @@ -/* $NetBSD: msg_126.c,v 1.8 2023/08/06 19:44:50 rillig Exp $ */ +/* $NetBSD: msg_126.c,v 1.9 2024/12/09 22:43:33 rillig Exp $ */ # 3 "msg_126.c" // Test for message: incompatible types '%s' and '%s' in conditional [126] -/* lint1-extra-flags: -X 351 */ +/* lint1-extra-flags: -X 351 -q 1 */ /* ARGSUSED */ -int -max(int cond, void *ptr, double dbl) +void +example(int i, void *ptr, double dbl, void (*return_void)(void)) { - /* expect+2: error: incompatible types 'pointer to void' and 'double' in conditional [126] */ - /* expect+1: error: function 'max' expects to return value [214] */ - return cond ? ptr : dbl; + /* expect+1: error: incompatible types 'pointer to void' and 'double' in conditional [126] */ + i = i > 0 ? ptr : dbl; + + ptr = i > 0 ? ptr : (void *)0; + + ptr = i > 0 ? ptr : 0; + + /* expect+1: implicit conversion from floating point 'double' to integer 'int' [Q1] */ + i = i > 0 ? dbl : i; + + // GCC accepts the 'int/void' mismatch even with -Wall -Wextra -std=c99. + /* expect+1: warning: incompatible types 'void' and 'int' in conditional [126] */ + i > 0 ? return_void() : 0; + + i > 0 ? return_void() : (void)0; }