Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,9 @@ C2y Feature Support
a conforming extension in earlier C language modes, but not in C++ language
modes (``std::extent`` and ``std::size`` already provide the same
functionality but with more granularity). The feature can be tested via
``__has_feature(c_countof)`` or ``__has_extension(c_countof)``.
``__has_feature(c_countof)`` or ``__has_extension(c_countof)``. This also
adds the ``<stdcountof.h>`` header file which exposes the ``countof`` macro
which expands to ``_Countof``.

C23 Feature Support
^^^^^^^^^^^^^^^^^^^
Expand Down
15 changes: 15 additions & 0 deletions clang/lib/Headers/stdcountof.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*===---- stdcountof.h - Standard header for countof -----------------------===
*
* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
* See https://llvm.org/LICENSE.txt for license information.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*
*===-----------------------------------------------------------------------===
*/

#ifndef __STDCOUNTOF_H
#define __STDCOUNTOF_H

#define countof _Countof

#endif /* __STDCOUNTOF_H */
13 changes: 11 additions & 2 deletions clang/test/C/C2y/n3469.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// RUN: %clang_cc1 -fsyntax-only -std=c2y -verify %s
// RUN: %clang_cc1 -fsyntax-only -std=c2y -verify -ffreestanding %s

/* WG14 N3469: Clang 21
* The Big Array Size Survey
*
* This renames _Lengthof to _Countof.
* This renames _Lengthof to _Countof and introduces the stdcountof.h header.
*/

void test() {
Expand All @@ -12,3 +12,12 @@ void test() {
expected-error {{expected expression}}
}

#ifdef countof
#error "why is countof defined as a macro?"
#endif

#include <stdcountof.h>

#ifndef countof
#error "why is countof not defined as a macro?"
#endif
Loading