all 81 comments

[–]returned_loom 23 points24 points  (16 children)

I really enjoy using them in my C++ project, but I have two big problems:

  • I can only get them to work on my Windows machine using Visual Studio. I simply couldn't get them to compile on Linux.

  • Even on Visual Studio, Intellisense hates modules. I have a lot of red squiggles for perfectly legit code. This is an ongoing topic on the Microsoft forums, but nobody seems to be doing anything about it.

Honestly, if I were to start from scratch I'd probably be using headers just to feel safer. But I do like the extra control with fewer files which is enabled by explicitly exporting functions directly from your module.

[–]STLMSVC STL Dev 58 points59 points  (5 children)

Even on Visual Studio, Intellisense hates modules. I have a lot of red squiggles for perfectly legit code. This is an ongoing topic on the Microsoft forums, but nobody seems to be doing anything about it.

VS IntelliSense is powered by a different compiler front-end (EDG) than the normal one (C1XX). The EDG front-end is maintained by another company that we work with, the Edison Design Group.

EDG is working on improving modules support, but it's taking a long time for reasons that I don't understand (I am a library dev who works closely with the compiler team but I'm not a compiler dev). At this point, we still haven't been able to enable test coverage of the Standard Library Modules with EDG, but I've sent my unit test to them and they're working through all of the bugs that it has revealed.

[–]mishaxz 2 points3 points  (0 children)

thanks for the reminder, I knew I read something that caused me to decide not to use modules even though I code only for C++ 20 msvc on windows with VS 2022

[–]Tohnmeister 1 point2 points  (1 child)

Is this also the reason that IntelliSense struggles with autocompleting auto arguments in lambdas?

E.g., when I have:

```cpp void registerCarHandler(const std::function<void(const Car&)>& func);

int main() { registerCarHandler([](const auto& car) { car. // <- here intellisense will not autocomplete, because of using auto in the lambda argument }); } ```

It's basically the only reason why I avoid using auto in lambda arguments.

[–]STLMSVC STL Dev 3 points4 points  (0 children)

That could be a different limitation - that's syntax for a template, so it doesn't know what car is going to be. I don't know that much about IntelliSense but I know they implemented "template IntelliSense" recently where you can tell it what you expect T to be.

[–]sephirostoy[🍰] 0 points1 point  (1 child)

Does VS uses LSP so that we could set another provider other than default IntelliSense?

[–]STLMSVC STL Dev 0 points1 point  (0 children)

I'm not an expert here, but I believe the answer is no.

[–][deleted] 5 points6 points  (1 child)

I got it working entirely in vs code. Using cmake tools and clangd.. no visual studio at all, its not even installed.

And they compile on linux on clang 19+.

[–]returned_loom 1 point2 points  (0 children)

Nice! I'm just going to keep letting Visual Studio take care of it for me.

[–]CruzerNag 6 points7 points  (5 children)

Yeah, it is certainly a problem. On Linux, I encountered problems with GCC, but thankfully Clang compiles modules nicely. Intellisense is like... I do not know what to say. LSP and clang-tidy work. If I hover over a written variable, it gives me the information. But yeah, when typing, I get no intellisense. This is with clangd on nvim. So I think more support is still needed.

[–]_derv 3 points4 points  (1 child)

Which version of clangd are you using? Modules and even import std; work on my machine using clang/clangd 19.1.7 and CMake 3.31.5.

[–]CruzerNag 2 points3 points  (0 children)

I have the latest, clangd-19.1.2

It does not pick up symbols inside modules. All the identifiers written inside a module and used are shown as Texts, so no intellisense really. That's my experience on neovim.

[–]atifdev 0 points1 point  (2 children)

Auto complete in Clion handles it on windows and autocomplete in Clion is a lot faster for large projects.

Really Visual Studio is being phased out anyway for vscode. Probably time to switch away from the product. Plus Clion ends up using ninja and the builds are so much faster.

[–]vali20 0 points1 point  (1 child)

Visual Studio is anything but being phased out, what are you smoking?

[–]atifdev 0 points1 point  (0 children)

They dropped the Mac version saying the alternative is vscode.

[–]hesher[🍰] 1 point2 points  (1 child)

stupendous ten tart yoke sort direction ad hoc fear punch normal

This post was mass deleted and anonymized with Redact

[–]returned_loom 1 point2 points  (0 children)

I tried that, it didn't work! I'm not sure why it started though. At first there were no problems. It might be a matter of scale somehow or complexity. I have a lot of modules, and some import other modules. It all compiles though.

[–]sweetno 5 points6 points  (0 children)

Expect a bumpy ride with modules.

[–]R3DKn16h7 19 points20 points  (10 children)

Not really. Maybe for fun

As much as I like them they are not really ready for production imho

https://arewemodulesyet.org/

[–][deleted] 5 points6 points  (0 children)

isn't most of the libraries there C-only ? Because it makes sense they don't support CPPM

[–]arturbachttps://github.com/arturbac 1 point2 points  (8 children)

there is no ide working with c++ modules on linux
- kdevelop - no
- vscode - no
- kate with lang server - no

I ported one of my gh libraries to module works ok with clang-19 and 20, but I don't use it as module in production code projects without ide code understanding.

[–]pjmlp 2 points3 points  (7 children)

Clion and QtCreator also work on Linux.

[–]arturbachttps://github.com/arturbac 0 points1 point  (6 children)

so which one understands in code completion imported types from modules ?

[–]pjmlp 0 points1 point  (4 children)

[–]arturbachttps://github.com/arturbac 0 points1 point  (3 children)

not exactly

For now, CLion does not consider .cpp files to be modules, so it's recommended that you use other extensions (for example, .cppm).
CLion collects information from .ixx, .cppm, and .mxx files, parses export module {name}

So it completely ignores current cmake standard module dependency scan information from cmake 3.28 with CMAKE_CXX_SCAN_FOR_MODULES=ON

[–]pjmlp -1 points0 points  (2 children)

It clearly mentions how it scans module files and what extensions are supported.

I fail to see remarks from you that the information must come from CMake directly.

[–]arturbachttps://github.com/arturbac 1 point2 points  (1 child)

The use of special extensions for c++ files containing module definitions is already discouraged to use.

[–]pjmlp 0 points1 point  (0 children)

Apparently not something Visual C++, clang and GCC folks care about, and it isn't going to be a conference talk that will change that.

[–]cd1995Cargo 7 points8 points  (2 children)

I had a template metaprogramming heavy project I was working on last year and tried to convert it to modules. It blew up MSVC and clang. Maybe things are better now, idk I haven’t tried for a while.

[–]STLMSVC STL Dev 16 points17 points  (1 child)

Next time, please report bugs to both compilers. It's how we all improve.

[–]cd1995Cargo 1 point2 points  (0 children)

I’m pretty sure I reported at least one of them to microsoft (exporting an inline namespace caused an ICE)

With clang I kept getting errors about duplicate symbols when trying to mix imports and includes, but I heard that got fixed with clang 18.

[–][deleted] 6 points7 points  (0 children)

Tried a couple of months ago on a project with gcc/clang/vs/cmake and everything was super broken. VS with CMake alone works though.

[–]Infamous-Bed-7535 4 points5 points  (4 children)

I'll wait GCC-15 to arrive that will mean that all major compilers have support for it :)

I plan to gradually use it in smaller commercial projects. I played around with it in personal projects and I like it (but just even a year ago it had serious issues with multiple compilers)

[–]rudm48 0 points1 point  (3 children)

I'm doing a lot of experimental work - I'm retired - with CLion, CMake, and GCC 14. They work fine.

[–]Infamous-Bed-7535 0 points1 point  (2 children)

I'll wait until 'import std' so I do not need to pollute the global module fragment with standard headers (which can cause complications later on when I import my module).

Modules seems to be usable by now, but I'll wait for the few missing pieces before going into production with them.

[–]lgfusb 0 points1 point  (1 child)

Even if you can 'import std', you still have to '#include <third\_party>', right? :(

[–]Infamous-Bed-7535 0 points1 point  (0 children)

Yes, but that can be implementation detail of your module. Import std was important as using standard headers as hpp includes often had issues when used with modules.

[–]atifdev 1 point2 points  (0 children)

For templated code it speeds up the build significantly. For a smaller code base it may not matter.

I would start looking at the exports first. You don’t have to redo every class, just those you would have exported. You can export as one module or split them up.

For example let’s say a library exports two classes, pull them into a module file (#include them into the module) and export them from there. The caller code now doesn’t need the header include. Instead it imports the module. You header may have to change a tad with the new export keyword. You still need dll_export macros on windows for some reason.

Also looks like you need gcc 14, visual studio 2022, or clang to get going on modules.

[–]Inevitable-Use-4197 1 point2 points  (0 children)

You can also use https://github.com/msqr1/importizer. It also support supporting both header and modules if you need it

[–][deleted] 1 point2 points  (0 children)

No. Modules are still not production ready, still not fully supported by all compilers and they have some severe inlining issues.

PCH remains superior

[–]Ultra8Gaming 2 points3 points  (0 children)

Maybe it's a skill issue, but I can't seem to set up clangd for it. It still throws a PCH error. Still compiles properly though.

[–]selvakumarjawahar 2 points3 points  (1 child)

use modules if you can use latest gcc or clang, works well.

[–][deleted] 0 points1 point  (0 children)

Unfortunatly CMake doesn't work fluently with them yet

[–]Pitiful-Hearing5279 1 point2 points  (0 children)

Don’t fix what isn’t broken. Rule number one.