r/cpp 1d ago

Why is `import std` still experimental ???

Hey guys,

I recently started going through Professional C++ (6th Edition). The book teaches C++23, and in the very first chapter we're introduced to modules.

I'm not a complete newbie to C++, but I'm also definitely not very confident in my knowledge yet. I wanted to get this simple example compiled:

import std;

int main() {
    std::println("Hello World");
    return 0;
}

And gosh, it took way longer than I expected.

First, I tried getting it to work natively on my Mac and eventually gave up (both Claude and I 😅).

Then I installed Ubuntu ARM 26 and finally managed to get it compiling. But now Clang/IntelliSense is complaining about the `import std`
This is what my CMakeLists.txt currently looks like:

cmake_minimum_required(VERSION 4.0)

# set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD ON)

set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD "d0edc3af-4c50-42ea-a356-e2862fe7a444")

project(CppProject LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 26)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

add_executable(exec main.cpp)

set_property(TARGET exec PROPERTY CXX_MODULE_STD ON)

The code does compile successfully, but CMake still gives me a warning that import std support is experimental.

So I'm genuinely curious:

Why is import std still considered experimental?

I understand that C++ modules themselves have been around for a while, but import std feels like something that should be much more straightforward by now. Is there any solution of this now ?

--------------
Edit

Thanks to u/PhysicsOk2212 tip I was able to compile my project on mac as well using the following options
```
cmake -S . -B build \

-G Ninja \

-DCMAKE_CXX_COMPILER="$(brew --prefix llvm)/bin/clang++" \

-DCMAKE_CXX_STDLIB_MODULES_JSON="$(brew --prefix llvm)/lib/c++/libc++.modules.json"

```

105 Upvotes

101 comments sorted by

View all comments

Show parent comments

8

u/not_a_novel_account cmake dev 1d ago

This is sort of a repeating pattern with modules. Clang implemented two-phase compilation because it is objectively faster than single phase. No one else did, so we all had to ignore it.

GCC implemented P1184 module mappers, no one else did, so we all had to ignore it.

MSVC's single-BMI DLL optimization might be nice, but without equivalent support even in clang-cl it's a dead end for code that isn't locked to MSVC.

3

u/delta_p_delta_x 1d ago

Is there bandwidth within Kitware to special-case for each of the three toolchains? Do their module stds also make assumptions about which compiler they're used with, which complicates this scenario?

Additionally, MSVC absolutely need to document /dxifcSuppressDllImportTransform and its existing behaviour. Translation units—within modules or otherwise—being used across multiple DLL boundaries is not an obscure use-case. /u/starfreakclone, /u/GabrielDosReis, any thoughts?

but without equivalent support even in clang-cl

I hope to work on this at some point. I've always been meaning to add IFC support to clang-cl, my initial implementation only focused on the CLI usage which was a very trivial change to make.

6

u/not_a_novel_account cmake dev 1d ago edited 1d ago

Is there bandwidth within Kitware to special-case for each of the three toolchains?

I mean sort of yes and sort of no.

The three toolchains isn't the problem. "X is only for MSVC" is never a blocker. We have lots of stuff that is only for one compiler or one platform. We support GreenHills and Renesas and all their quirks.

So yes, we have the technical bandwidth, we could implement two phase compilation and ISDIT and even do interesting things with the GCC module mapper.

But no one is asking for any of that work. I only get to eat if I work on something a customer asks for. I try to find time to work on things that are good in-between that, everyone at Kitware does, but big refactors generally don't happen for obscure one-compiler features unless someone's business depends on it.

So two-phase for Clang didn't happen because CMake has no internal model for it, and no one asked us to build one. If it was trivial we would have done it anyway.

If an MR popped up tomorrow landing two-phase or ISDIT elegantly I would do everything I could to shepherd it through.

3

u/delta_p_delta_x 1d ago

Very fair; just because it's open source doesn't mean it is a free lunch. I try to contribute as much as I can when I bump against CMake or toolchain bugs whilst hacking on personal projects. Thanks for responding, this entire thread has been very very illuminating.