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

via libcxx-commits libcxx-commits at lists.llvm.org
Mon Jun 30 01:59:25 PDT 2025


dywoq 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, 

```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. 

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


More information about the libcxx-commits mailing list