[Bug 292960] Calling clang with -std=c11 (or any other standard <C23) exposes C23 _WIDTH macros
[email protected] Thu, 05 Feb 2026 12:19:13 +0000
| Newsgroups | gmane.os.freebsd.devel.standards |
|---|---|
| Message-ID | <[email protected]/bugzilla/> |
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=292960
Bug ID: 292960
Summary: Calling clang with -std=c11 (or any other standard
<C23) exposes C23 _WIDTH macros
Product: Base System
Version: 16.0-CURRENT
Hardware: Any
OS: Any
Status: New
Severity: Affects Many People
Priority: ---
Component: standards
Assignee: [email protected]
Reporter: [email protected]
Commit 7998a82d2f99a00086baf64b2a3343ba10f8806d added the C23 _WIDTH macros.
These macros are always exposed, regardless of the selected C standard, as long
as neither _POSIX_C_SOURCE nor one of the _SOURCE macros are defined.
Take this small example program:
----
#include <stdint.h>
#include <stdio.h>
int main() {
printf("* __STDC_VERSION__: %li\n", __STDC_VERSION__);
printf("* __ISO_C_VISIBLE: %i\n", __ISO_C_VISIBLE);
#ifdef SIZE_WIDTH
printf("* C23 macro SIZE_WIDTH is defined\n");
#else
printf("* C23 macro SIZE_WIDTH is not defined\n");
#endif
return 0;
}
----
C23 is correct:
% cc -o test -std=c23 test.c
% ./test
* __STDC_VERSION__: 202311
* __ISO_C_VISIBLE: 2023
* C23 macro SIZE_WIDTH is defined
C11 still sets __ISO_C_VISIBLE=2023 and thus exposes the SIZE_WIDTH macro:
% cc -o test -std=c11 test.c
* __STDC_VERSION__: 201112
* __ISO_C_VISIBLE: 2023
* C23 macro SIZE_WIDTH is defined
Defining _POSIX_C_SOURCE sets __ISO_C_VISIBLE=2011:
% cc -D_POSIX_C_SOURCE -o test -std=c11 test.c
% ./test
* __STDC_VERSION__: 201112
* __ISO_C_VISIBLE: 2011
* C23 macro SIZE_WIDTH is not defined
Defining _C11_SOURCE also sets __ISO_C_VISIBLE=2011:
% cc -D_C11_SOURCE -o test -std=c11 test.c
% ./test
* __STDC_VERSION__: 201112
* __ISO_C_VISIBLE: 2011
* C23 macro SIZE_WIDTH is not defined
This is caused by clang setting __STDC_VERSION__ to the requested C standard,
but _visible.h only evaluating __STDC_VERSION__ when _POSIX_C_SOURCE is also
set. When _POSIX_C_SOURCE is not set a _SOURCE macro must be defined, otherwise
the default case (which exposes everything) is selected.
I don't know if this this really bug. However it's not the the anticipated
behavior that requesting a C standard by -std= requires some other macros to be
set for the C23 (and maybe other?) macros don't get defined.
I have at least one real world example where a C11 code base breaks by the
exposed SIZE_WIDTH macro.
--
You are receiving this mail because:
You are the assignee for the bug.