[libcxx-commits] [libcxx] [libc++] Hoist <compare> outside the threads guard in <thread> (PR #202535)

Nikolas Klauser via libcxx-commits libcxx-commits at lists.llvm.org
Tue Jun 9 02:26:29 PDT 2026


philnik777 wrote:

> So, just to make sure we're on the same page, what you're advocating for is that we unconditionally include implementation-detail headers outside carve-outs and standard modes, and that we do that consistently. And then we'd only guard the actual parts of implementation-detail headers that don't work when a carve-out is active.
> 
> Just to clarify, let's take `<thread>` as an example. Before (let's assume this patch lands, which makes it consistent with what we do for all other headers):
> 
> ```c++
> // [thread.syn]
> #  include <compare>
> 
> #  if _LIBCPP_HAS_THREADS
> 
> #    include <__thread/this_thread.h>
> #    include <__thread/thread.h>
> 
> #    if _LIBCPP_STD_VER >= 20
> #      include <__thread/jthread.h>
> #    endif
> 
> #    if _LIBCPP_STD_VER >= 23
> #      include <__thread/formatter.h>
> #    endif
> 
> #    include <version>
> #  endif // _LIBCPP_HAS_THREADS
> ```
> 
> What is your target? One possibility:
> 
> ```c++
> // note: no more _LIBCPP_HAS_THREADS check here
> 
> #    include <__thread/this_thread.h>
> #    include <__thread/thread.h>
> 
> #    if _LIBCPP_STD_VER >= 20 // do you want this here or inside `jthread.h`?
> #      include <__thread/jthread.h>
> #    endif
> 
> #    if _LIBCPP_STD_VER >= 23
> #      include <__thread/formatter.h>
> #    endif
> 
> #    include <version>
> ```

I'd like to avoid any sort of conditional include inside the detail headers, since I think that can get very convoluted very quickly. Taking your example, I'd like to have a guard inside `<__thread/jthread.h>`. I'm OK with having the `#if _LIBCPP_STD_VER >= 20` guard inside `<thread>` _as a compile-time optimization inside the umbrella headers_.

I would like to avoid having multiple dimensions of compile time optimizations though, i.e. I don't want both `_LIBCPP_HAS_THREADS` and `_LIBCPP_STD_VER` guards inside `<thread>`, since, again, it gets complicated very fast - see this very bug. A compounding factor here is that the carve-outs are tested way less thoroughly, so any issues with header includes there are much less likely to be found.

TL:DR I'd like to remove carve-out guards around headers everywhere and guard only the code, but keep the version guards _inside the umbrella headers_.

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


More information about the libcxx-commits mailing list