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