[libcxx-commits] [libcxx] [libcxx][c++26] 2937R0: Freestanding: Remove strtok (PR #146290)

Nikolas Klauser via libcxx-commits libcxx-commits at lists.llvm.org
Mon Jun 30 02:07:54 PDT 2025


philnik777 wrote:

> > I don't think this is the right approach here. `_LIBCPP_USING_IF_EXISTS` is there to make `std::strtok` available exactly when `::strtok` is available, which seems like a _much_ more useful way of handling this than arbitrarily disabling it because `-ffreestanding` was set. Generally, I don't think we should check for `-ffreestanding` directly in the headers at any point.
> 
> `__STDC_HOSTED__ == 1 || _LIBCPP_STD_VER < 26` is the thing what [P2937R0](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2023/p2937r0.html) requires. Since `<cstring>` is a freestanding header (not completely),

This is incorrect. We're simply not required to provide `strtok`. We are allowed to do that though.

> ```c++
> using ::strtok _LIBCPP_USING_IF_EXIST;
> ```
> 
> must be removed from `<cstring>` in C++26, using macro condition:
> 
> ```c++
> #if __STDC_HOSTED__ == 1 || _LIBCPP_STD_VER < 26
> using ::strtok _LIBCPP_USING_IF_EXISTS;
> #endif
> ```
> 
> Different C libraries might have different interpretations of what should be freestanding.

Which is exactly why we have `_LIBCPP_USING_IF_EXISTS`. If it's available in the global namespace, we import it into `std`. Otherwise we don't. That's what the attribute does.

https://github.com/llvm/llvm-project/pull/146290


More information about the libcxx-commits mailing list