EN VI

Why is jthread not presented in libc++ (using clang 18, c++26)?

2024-03-16 16:30:06
Why is jthread not presented in libc++ (using clang 18, c++26)

the following code just compile with "jthread not in std". with clang 18

clang++ -std=c++26 -stdlib=libc++

and the implementation of jthread is in __thread/jthread.h, but for some reason macro out. why?

#include <thread>
using namespace std::chrono_literals;

int main() {
  std::jthread t([] { std::this_thread::sleep_for(1s); });
}

Solution:

The libc++ documentation has a webpage about C++20 status of libc++. Quoting the relevant footnote 8:

P0660: The paper is implemented but the features are experimental and can be enabled via -fexperimental-library.

Thus, just pass that flag mentioned above when compiling with Clang 18 or newer, like this:

clang++ -std=c++26 -stdlib=libc++ -fexperimental-library
Answer

Login


Forgot Your Password?

Create Account


Lost your password? Please enter your email address. You will receive a link to create a new password.

Reset Password

Back to login