Module Name: src Committed By: rillig Date: Sun Jan 15 13:30:04 UTC 2023
Modified Files: src/tests/usr.bin/xlint/lint1: expr_sizeof.c Log Message: tests/lint: add more tests for sizeof To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 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.1 src/tests/usr.bin/xlint/lint1/expr_sizeof.c:1.2 --- src/tests/usr.bin/xlint/lint1/expr_sizeof.c:1.1 Sun Jan 15 00:53:19 2023 +++ src/tests/usr.bin/xlint/lint1/expr_sizeof.c Sun Jan 15 13:30:04 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: expr_sizeof.c,v 1.1 2023/01/15 00:53:19 rillig Exp $ */ +/* $NetBSD: expr_sizeof.c,v 1.2 2023/01/15 13:30:04 rillig Exp $ */ # 3 "expr_sizeof.c" /* @@ -42,10 +42,27 @@ typedef int sizeof_paren_global_var[-(in /* * Even though 'sizeof(s)' may look like a function call expression, the * parentheses around 's' are ordinary parentheses and do not influence the - * associativity. Therefore, the '.' following the '(s)' takes precedence - * over the 'sizeof'. Same for the '->' following the '(ps)'. + * precedence. + * + * Therefore, the '.' following the '(s)' takes precedence over the 'sizeof'. + * Same for the '->' following the '(ps)'. Same for the '[0]' following the + * '(arr)'. */ /* expect+1: error: negative array dimension (-4) [20] */ typedef int sizeof_paren_global_struct_member[-(int)sizeof(s).member]; /* expect+1: error: negative array dimension (-4) [20] */ typedef int sizeof_paren_global_ptr_struct_member[-(int)sizeof(ps)->member]; +int arr[] = { 1, 2, 3 }; +/* expect+1: error: negative array dimension (-3) [20] */ +typedef int arr_count[-(int)sizeof(arr) / (int)sizeof(arr)[0]]; + +/* FIXME: 'n' is actually used, for the variable length array. */ +/* expect+2: warning: argument 'n' unused in function 'variable_length_array' [231] */ +void +variable_length_array(int n) +{ + int local_arr[n + 5]; + /* FIXME: sizeof(local_arr) must be 20, not 4. */ + /* expect+1: error: negative array dimension (-4) [20] */ + typedef int sizeof_local_arr[-(int)sizeof(local_arr)]; +}