https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122591

            Bug ID: 122591
           Summary: _Countof has wrong return type (not size_t)
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: sjames at gcc dot gnu.org
                CC: [email protected]
  Target Milestone: ---

See the thread starting at
https://lists.gnu.org/archive/html/bug-gnulib/2025-11/msg00048.html.

```
int global_array[12];

void test_return_type() {
  static_assert(_Generic(typeof(_Countof global_array), typeof(sizeof(0)) : 1,
default : 0));
}
```

```
$ clang a.c -std=gnu2y -c # 21.1.5
$ gcc a.c -std=gnu2y -c # trunk from today
a.c: In function ‘test_return_type’:
a.c:6:3: error: static assertion failed
    6 |   static_assert(_Generic(typeof(_Countof global_array),
typeof(sizeof(0)) : 1, default : 0));
      |   ^~~~~~~~~~~~~
```

Clang has a test for exactly this functionality at clang/test/C/C2y/n3369.c
(added in
https://github.com/llvm/llvm-project/pull/133125/files#diff-5b20365a8a9f9b93411a2b5e156b5b74a6bad71a6cba0ae18dcb3a96defd7dde),
as does gnulib (which is how I spotted this).

Alex, you seem to have looked at the PR but also touched those gnulib tests
just last month -- did you test with trunk with your patches?

Reply via email to