From a725e6ac8ccac5b1d698e0bda4149e6b897d25fd Mon Sep 17 00:00:00 2001 From: Red Bear OS Date: Mon, 29 Jun 2026 19:35:07 +0300 Subject: [PATCH] relibc: guard size_t typedef against C++ name collision When a C++ translation unit transitively includes this header (e.g. via pulling in ), the unqualified 'size_t' references inside libstdc++'s internal templates resolved to this typedef instead of std::size_t, producing 'unterminated #ifndef' template parse errors during hosted-mode C++ compilation. Mirror the pattern already used in bits/wchar-t.h: wrap the typedef in '#ifndef __cplusplus / #endif' so C compilation sees the typedef and C++ falls back to the libstdc++/libc++-provided std::size_t via the standard type machinery. --- src/header/bits_size-t/cbindgen.toml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/header/bits_size-t/cbindgen.toml b/src/header/bits_size-t/cbindgen.toml index d2835f458a..09dbbe3260 100644 --- a/src/header/bits_size-t/cbindgen.toml +++ b/src/header/bits_size-t/cbindgen.toml @@ -1,7 +1,26 @@ # POSIX header spec: https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/stddef.h.html # # This type is split out to prevent importing all of stddef.h into other headers. +# +# C++ compatibility: in C++, `size_t` is defined by the standard library +# in namespace `std::`. A bare `typedef unsigned long size_t;` at file +# scope in a C++ translation unit collides with `std::size_t` whenever +# a host stdlib header (e.g. ``, ``) is +# transitively included — the libstdc++ internal code references +# unqualified `size_t` and resolves it to the first visible one, which +# would otherwise be this typedef. The `__cplusplus` guard makes the +# typedef a no-op under C++ compilation; the libc++/libstdc++ headers +# then provide their own `std::size_t` via `__SIZE_TYPE__` or the +# standard type machinery. include_guard = "_RELIBC_BITS_SIZE_T_H" +after_includes = """ +/** + * Unsigned integer type of the result of the sizeof operator. + */ +#ifndef __cplusplus +typedef unsigned long size_t; +#endif +""" language = "C" no_includes = true cpp_compat = true