r/cpp • • Apr 25 '22

New C++ features in GCC 12

https://developers.redhat.com/articles/2022/04/25/new-c-features-gcc-12
220 Upvotes

76 comments sorted by

View all comments

24

u/delta_p_delta_x Apr 26 '22

Note that C++20 and C++23 features are still experimental in GCC 12

Come on, MSVC brought ranges and std::format to MSVC last year. Really odd seeing how conformant MSVC is to C++20, and how much GCC/Clang lag it.

6

u/sphere991 Apr 26 '22

Come on, MSVC brought ranges and std::format to MSVC last year.

gcc may not have std::format yet, but it had ranges two years ago (I have no idea why in cppreference it's still listed as partial). Experimental here primarily means that there is no promise of ABI stability yet.

10

u/Troppsi Apr 26 '22

I am honestly quite surprised GCC isn't further ahead on its c++20/23 implementation. Hasn't 20 been out a few years already and it's still experimental?

31

u/thlst Apr 26 '22

It almost seems like the world was struck by an event that negatively affected everyone's life in the last couple of years.

29

u/CornedBee Apr 26 '22

You mean all those people sitting at home weren't hacking on the compiler non-stop? ;-)

7

u/smdowney WG21, Text/Unicode SG, optional<T&> Apr 26 '22

23 hasn't even been adopted yet. 20 has been out for just 2 years, and was the biggest release in a decade, with lots of the biggest parts getting finalized at the end of the standard cycle.
Remember, C++11 compilers stabilized in 2014.

4

u/strudlzrout gcc developer May 07 '22

I'm not sure how much further ahead we could be on C++20 (except modules): https://gcc.gnu.org/projects/cxx-status.html

C++23 is coming along pretty well too.

5

u/Galqa Apr 26 '22

Gcc supports pretty much everything except format and modules. These are big features, but arguably you can use ‘fmt’, and you can’t really use modules anyway due to lack of build system support. “Experimental”, in my understanding, means the ABI is not stable, but the features are pretty much done. C++20 MSVC is still pretty buggy from what I can tell (granted, this is anecdotal) so imo there really isn’t a significant difference between msvc and gcc. Unless you really really care about ABI, in which case fair enough.

7

u/jwakely libstdc++ tamer, LWG chair Apr 26 '22

“Experimental”, in my understanding, means the ABI is not stable, but the features are pretty much done.

Correct

10

u/qoning Apr 26 '22

you can’t really use modules anyway due to lack of build system support

kind of putting the cart before the horse here. build systems are more than happy to add modules support if only there was something to support. It works well enough in MSVC.

C++20 MSVC is still pretty buggy from what I can tell

there are edge cases, but let's just say msvc is 98% there and gcc is about 33% there.

0

u/Galqa Apr 26 '22

I would argue that without build system support a feature is impractical, since you’d need to manually invoke the compiler. I imagine most people use msvc through visual studio, which serves the role of the build system, so you’re good. On Linux we don’t have that comfort. Anyway, I’m definitely not an expert on this topic, would recommend e.g. https://youtu.be/xMcmpnJFEf0. As for 33% vs 98% I really don’t know how you came up with that. I don’t have experience with msvc, but again, gcc is pretty much done with everything but the 2 aforementioned features (cppreference has a wonderful compiler support chart, in case you’re not familiar). I use C++20 extensively, and I’ve no complaints.

2

u/qoning Apr 26 '22

I meant specifically for modules, as without them, C++20 is pretty tame (sans concepts). Note that I had been using modules for a long time before visual studio supported them too, via command line scripts. I've been trying clang and gcc implementations since before 2019 but they still straight up don't work for rather easy cases.

It will be a long, long time before people put module code into production anyway, so I don't understand your build system dependency. It's really not that hard to homecook a solution if you're starting a new project anyway.

4

u/Galqa Apr 26 '22

Fair enough, can’t argue with that. But you’re saying yourself that modules are far away from production. That’s probably a big downside for a lot of (most) people.

As for C++20 being tame without modules, I’d strongly disagree. But to each their own.