[clang] Add more tests for _Countof (PR #133333)

A. Jiang via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 27 19:10:57 PDT 2025


================
@@ -81,6 +89,22 @@ void test_with_function_param(int array[12], int (*array_ptr)[12], int static_ar
   (void)_Countof(static_array); // expected-error {{'_Countof' requires an argument of array type; 'int *' invalid}}
 }
 
+void test_func_fix_fix(int i, char (*a)[3][5], int (*x)[_Countof(*a)]);
+void test_func_fix_var(int i, char (*a)[3][i], int (*x)[_Countof(*a)]);
+void test_func_fix_uns(int i, char (*a)[3][*], int (*x)[_Countof(*a)]);
----------------
frederick-vs-ja wrote:

Oh, I forgot that trailing return type is not yet supported in C.

Perhaps we can do this:
```c
void test_func_fix_fix(int i, char (*a)[3][5], int (*x)[_Countof(*a)], char(*)[_Generic(x, int(*)[3] : 1)]);
```

Which effectively asserts that `typeof(x)` is `int(*)[3]`.

https://github.com/llvm/llvm-project/pull/133333


More information about the cfe-commits mailing list