r/cpp • • Jun 18 '26

GCC 17 Lands Initial Infrastructure For C++29

https://www.phoronix.com/news/GCC-17-std-CPP29-Experimental
130 Upvotes

38 comments sorted by

View all comments

Show parent comment

16

u/not_a_novel_account cmake dev Jun 18 '26

There's no work left to do as far as stability goes. If your blocker was GCC or CMake, it shouldn't be.

24

u/llort_lemmort Jun 18 '26

As long as import std is experimental in CMake that's definitely a blocker for me.

22

u/not_a_novel_account cmake dev Jun 18 '26 edited Jun 18 '26

That might be awhile. It's going to remain experimental until someone decides how static libraries on MSVC are supposed to work, which is above my paygrade.

Right now they just don't, if you use import std in a static library on MSVC and then try to use that library in some other project (which doesn't import std, maybe isn't even written in C++) the link fails.

I tried to move it out of experimental in 4.3. Turns out people like static libraries. Back to experimental it went.

0

u/[deleted] Jun 18 '26

[deleted] — view deleted comment

7

u/not_a_novel_account cmake dev Jun 18 '26

Seperate codebase is the key here, although I'm not sure what VS does with the std.obj, maybe they vendor it inside the archive and that would work.

3

u/pjmlp Jun 18 '26

Static libraries definitely work with modules in VC++ with MSBuild, and import std, unless you mean something else.

https://github.com/pjmlp/RaytracingWeekend-CPP/tree/main/OneWeekend/RaytracingLib

8

u/not_a_novel_account cmake dev Jun 18 '26 edited Jun 18 '26

You're doing an import std in the main project, so std.obj is being provided there.

The problem is when you try to use a static library which wants import std in a project which does not itself do import std. CMake does not bundle std.obj into the archive, unless someone else provides it the link fails.

It's entirely possible VS is bundling std.obj and this "just works" for them even when consumed by projects which don't do import std themselves, like a plain C project. That's certainly a solution. I need to boot up a Windows box and check at some point.

3

u/pjmlp Jun 19 '26

I am on Windows and can have a look later today, with VC++ / MS Build though.

2

u/mapronV Jun 19 '26

Can you please share a result? I interested in result of this conversation!

2

u/pjmlp Jun 19 '26 edited Jun 19 '26

It is on github already, https://github.com/pjmlp/staticlib-modules

There are two approaches there, as described on the readme.

EDIT: as per chat conversation, it may be that the way VC++ manages it, even with a .obj and .ifc referenced via the linker (not MSBuild project reference), is actually an ODR reference due to how std.obj ends up on the final binary.

Note, not a linker expert.

3

u/llort_lemmort Jun 18 '26

Is there an issue that I can follow for this? The merge request that restored the experimental gate for 4.3 only mentions 4 issues which have all been closed since.

7

u/not_a_novel_account cmake dev Jun 18 '26

These include both broken stdlib distributions and regressions in our implementation

The issues are for the latter. The former is discussed in the upstreams:

GCC/libstdc++ fixed in GCC 16, Clang/libc++ is not actually a blocker, MSVC/msvp*.dll is NOTABUG. The last one is a blocker until someone from on-high tells me how it's supposed to work. The DevCom focuses on ODR for DLLs but the static archive scenario is actually the more pressing problem.

4

u/Expert-Map-1126 vcpkg maintainer BillyONeal Jun 18 '26

"The downstream customer also needs to import std" is the usage model I remember being expected when this was discussed way back in Cologne

4

u/not_a_novel_account cmake dev Jun 18 '26

How does a Fortran consumer have import std in its usage model? It might not even have a C++ compiler available.

3

u/Expert-Map-1126 vcpkg maintainer BillyONeal Jun 18 '26

"That's the neat part you don't" 🤷 (You are saying more or less exactly what I was saying to the modules designers at the time. "How can I ship a std module that customers can use?" "You don't, customers have to build you themselves")

7

u/not_a_novel_account cmake dev Jun 18 '26

Well it works for literally every module on Earth except for import std under MSVC. The answer is very obvious IMHO, which is that std.obj should be a part of the runtime distribution. "std isn't special"

But if the official answer eventually becomes "this is how it works, you need a C++ compiler for MSVC import std", that's fine. It's more work; I just need that from on high because I don't want to implement that and have it change in 6 months.

4

u/Expert-Map-1126 vcpkg maintainer BillyONeal Jun 18 '26

I have not been a standard library maintainer for 6 years so don't take this as "on high". I was under the impression that std.obj may depend on user settings so it may not be bundleable the way the libraries are normally bundled. For instance, different _ITERATOR_DEBUG_LEVEL settings create disjoint linker universes but there is only one import .lib, so we can't put anything _IDL dependent in the normal import libs, that stuff must all be header only.

I expect that if you're shipping a static library, the std.obj you built is the same as any of your other .objs that include standard library symbols from headers world so it needs to be in your .lib. But I am not positive.

→ More replies

6

u/_bstaletic Jun 18 '26

During gcc 16 development, there were bugs when one turns on both -fmodules and -freflection. Last time I checked modules and reflections still aren't a stable combination. I might need a newer gcc 17, as I haven't been following the most recent development.

4

u/Pretend-Guide-8664 Jun 18 '26

I thought the implementation was partial, aren't there some missing bits? Private partitions, implementation definitions visible by importers, something else. Going off of memory here

4

u/not_a_novel_account cmake dev Jun 18 '26

Oh GCC stuff, yes, I overstated the case. GCC has some edge features which are partial.

Private frags are pointless IMHO, but I shouldn't have said they covered everything.

1

u/pjmlp Jun 18 '26

Header units beyond VC++?

Not that I care that much, I can only use modules outside work, and already rewrote the places where I used them.

6

u/not_a_novel_account cmake dev Jun 18 '26

"Modules" always means "module units". Header units are part of the same proposal but an entirely different bag.

We have all the pieces in place to turn on support for them but they'll remain niche. You need to explicitly enumerate the headers you want to use as units, at which point you're better off just wrapping them in a named module instead.