Module Name: src Committed By: rillig Date: Fri Jun 24 21:02:10 UTC 2022
Modified Files: src/tests/usr.bin/xlint/lint1: msg_247.c Log Message: tests/lint: demonstrate another warning about pointer casts To generate a diff of this commit: cvs rdiff -u -r1.24 -r1.25 src/tests/usr.bin/xlint/lint1/msg_247.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_247.c diff -u src/tests/usr.bin/xlint/lint1/msg_247.c:1.24 src/tests/usr.bin/xlint/lint1/msg_247.c:1.25 --- src/tests/usr.bin/xlint/lint1/msg_247.c:1.24 Fri Jun 24 20:44:53 2022 +++ src/tests/usr.bin/xlint/lint1/msg_247.c Fri Jun 24 21:02:10 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: msg_247.c,v 1.24 2022/06/24 20:44:53 rillig Exp $ */ +/* $NetBSD: msg_247.c,v 1.25 2022/06/24 21:02:10 rillig Exp $ */ # 3 "msg_247.c" // Test for message: pointer cast from '%s' to '%s' may be troublesome [247] @@ -305,3 +305,23 @@ cast_between_first_member_struct(void *p return t2; } + +double * +unnecessary_cast_from_array_to_pointer(int dim) +{ + static double storage_1d[10]; + static double storage_2d[10][5]; + + if (dim == 1) + return (double *)storage_1d; + + if (dim == -1) + return storage_1d; + + if (dim == 2) + /* expect+1: warning: illegal combination of 'pointer to double' and 'pointer to array[5] of double' [184] */ + return storage_2d; + + /* expect+1: warning: pointer cast from 'pointer to array[5] of double' to 'pointer to double' may be troublesome [247] */ + return (double *)storage_2d; +}