Module Name: src
Committed By: rillig
Date: Wed Mar 13 06:56:24 UTC 2024
Modified Files:
src/tests/usr.bin/xlint/lint1: expr_sizeof.c
Log Message:
tests/lint: ensure that lint correctly decays array parameter types
To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/tests/usr.bin/xlint/lint1/expr_sizeof.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/expr_sizeof.c
diff -u src/tests/usr.bin/xlint/lint1/expr_sizeof.c:1.14 src/tests/usr.bin/xlint/lint1/expr_sizeof.c:1.15
--- src/tests/usr.bin/xlint/lint1/expr_sizeof.c:1.14 Sat Aug 5 10:13:39 2023
+++ src/tests/usr.bin/xlint/lint1/expr_sizeof.c Wed Mar 13 06:56:24 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: expr_sizeof.c,v 1.14 2023/08/05 10:13:39 rillig Exp $ */
+/* $NetBSD: expr_sizeof.c,v 1.15 2024/03/13 06:56:24 rillig Exp $ */
# 3 "expr_sizeof.c"
/*
@@ -199,3 +199,17 @@ struct s24 {
};
/* expect+1: error: negative array dimension (-24) [20] */
typedef int sizeof_s24[-(int)sizeof(struct s24)];
+
+void
+sizeof_array_parameter(short arr[12345])
+{
+ // The size of an array parameter is the size of the decayed pointer.
+ // Subtracting 'sizeof(void *)' makes the test platform-independent.
+ typedef int sizeof_arr[-(int)(sizeof arr - sizeof(void *))];
+
+ // The 2 comes from 'sizeof(short)', as the type 'array[size] of elem'
+ // decays into the type 'pointer to elem', not 'pointer to array[size]
+ // of elem'.
+ /* expect+1: error: negative array dimension (-2) [20] */
+ typedef int sizeof_arr_elem[-(int)(sizeof *arr)];
+}