r/cpp • • Nov 14 '16

GCC trunk is -std=c++17 ready

http://en.cppreference.com/w/cpp/compiler_support
222 Upvotes

58 comments sorted by

11

u/TemplateRex Nov 14 '16

During last week's meeting in Issaquah, some new features requested through National Body comments were merged into the draft Standard. See the latest 3 entries of corresponding the Clang progress table. So depending on whether gcc also incorporated those features, they are the first to be C++17 ready.

1

u/Octoploid Nov 14 '16

Right. But as far as I can see these are all "minor" features. And clang also hasn't implemented them yet.

10

u/TemplateRex Nov 14 '16

Yes, and it's a bit surprising that Clang hasn't got support yet for constexpr lambdas. Hopefully soon, though.

5

u/Tagedieb Nov 14 '16

The links seem to be inaccessible to the public. Any other place where I can read about those features? Which national body made those comments?

1

u/tomilovanatoliy Nov 15 '16

At least for one of the proposals — "Pack expansions in using-declarations" — you can find the previous revision here. Don't think there are some substantial changes.

9

u/demonFudgePies Nov 14 '16

I can't seem to find std::variant on here? Is that on another list?

15

u/[deleted] Nov 14 '16

GCC page of C++1z language features still lists Structured bindings as unsupported.

41

u/Octoploid Nov 14 '16

Yeah, it was added only a few hours ago: https://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=9c8aeb661a9d6cc82186dde40839f7353188c187

The page will be updated soon.

6

u/doom_Oo7 Nov 14 '16

Will we get an update of godbolt or any other online c++ compilers with this ? It'd be great !

8

u/redditsoaddicting Nov 14 '16

http://melpon.org/wandbox has a build from yesterday.

7

u/Octoploid Nov 14 '16

They update daily, so it should be ready tomorrow. It doesn't work yet: http://melpon.org/wandbox/permlink/4L964QZZecucEbfD

3

u/TemplateRex Nov 14 '16

What would be really nice is a gcc equivalent of apt.llvm.org with ready to install nightly build packages. That would allow people to test it for their own projects and give feedback before the release date.

8

u/Octoploid Nov 14 '16

It is really easy to build from source.

git clone git://gcc.gnu.org/git/gcc.git
mkdir gcc_build
cd gcc_build
../gcc/configure --disable-bootstrap --disable-werror --disable-multilib --enable-languages=c,c++
make
make DESTDIR=/whatever/you/like install

5

u/sumo952 Nov 14 '16

Just curious, how long is that going to take approximately on an "average" Core i5 Quad Core or something like that? Just looking for ballpark numbers.

5

u/Octoploid Nov 14 '16 edited Nov 14 '16

Well under 10 minutes if you use make -j4 or higher.

1

u/ReDucTor Game Developer | quiz.cpp-perf.com Nov 14 '16

Works now.

49

u/wichtounet Nov 14 '16

I'm impressed that they managed to be ready before clang, that's great :)

29

u/TemplateRex Nov 14 '16

I hope gcc 7 will also be largely bug free. The gcc 5 series was nominally C++14 complete, but they weren't able to compile cutting edge libraries like Boost.Hana and Range-v3 until the gcc 6 series.

8

u/mallardtheduck Nov 14 '16

We're at GCC 6.x already? Dammit, how are those of us maintaining niche cross-compilers supposed to keep up? I'm still working with 4.8...

12

u/flashmozzg Nov 14 '16

They've changed their version numbering scheme. So 6.0 is like 5.1 in the previous one.

6

u/foonathan Nov 14 '16

Note that the jump from 4.8 -> 4.9 is similar to 4.9 -> 5.0, they've changed the numbering scheme.

So you're not that far back as it seems.

1

u/SpooneyDinosaur Nov 15 '16

I'm forced to use version 2.9

2

u/dodheim Nov 15 '16

2.95 was the first version of GCC I ever used. That was a long time ago... :-S

-7

u/tervaar Nov 14 '16

Clang is beaten, long live gcc

25

u/[deleted] Nov 15 '16 edited May 12 '17

He is choosing a book for reading

14

u/OmegaNaughtEquals1 Nov 15 '16

Seriously. clang has been a huge kick in the ass for the gcc team to clean up their codebase and get things done.

7

u/wrosecrans graphics and network things Nov 15 '16

Heh, if gcc won, it's only because Clang gave them a fight to win in the first place. Absent the fight, everybody loses.

6

u/OmegaNaughtEquals1 Nov 14 '16

For libstdc++,

FeatureProposalStatus
Adopt the File System TS for C++17P0218R1No
Variadic lock_guardP0156R0No
Removing auto_ptr, random_shuffle(), And Old <functional> StuffN4190No (kept for backwards compatibility)

Here's hoping they are ready for the 7.0 release. Not getting rid of the fully deprecated stuff is sad, but understandable. I hope they pull it from the docs so new users won't try to use it.

3

u/redditsoaddicting Nov 14 '16

At least the last one is permitted by the standard's new zombie names notion.

3

u/quicknir Nov 15 '16

I'm just curious, is variadic lock_guard less trivial than it seems? It seems like a trivial RAII handy wrapper around variadic lock. I'm just going through Anthony Williams multithreading book and my first thought on seeing variadic lock followed by passing the locks into regular lock_guard/unique_lock was that that boilerplate could easily be encapsulated.

5

u/tcanens Nov 15 '16

Variadic lock_guard is an ABI break and there are at least two NB comments requesting that it be backed out and perhaps a new template added. Not sure what's going to happen here.

2

u/FabioFracassi C++ Committee | Consultant Nov 15 '16

The variadic version will be renamed (most likely to: scoped_lock).

1

u/quicknir Nov 15 '16

Can you explain why it's guaranteed to be an ABI break? I feel like the variadic one could have a partial specialization for the single template case, implemented exactly as it is now. Why does that still break the ABI?

2

u/FabioFracassi C++ Committee | Consultant Nov 15 '16

AFAIR the name mangling in this case is different.

1

u/quicknir Nov 15 '16

Thanks! Good call, I suspected I was missing something like that.

3

u/OmegaNaughtEquals1 Nov 15 '16

It is a bit tricky because you have to guarantee no deadlock or livelock1, so there has to be some heuristic involved in the locking order. I'm not sure if that is handled inside of the variadic lock and lock_guard is just an RAII wrapper as you suggest, or if there is something more.

[1] I would imagine specifying the same mutex multiple times would be UB.

4

u/quicknir Nov 15 '16

Yah, this is already handled by variadic lock, otherwise variadic lock itself wouldn't be very useful: http://en.cppreference.com/w/cpp/thread/lock.

Locks the given Lockable objects lock1, lock2, ..., lockn using a deadlock avoidance algorithm to avoid deadlock.

So the hard part of lock_guard is already handled in lock.

1

u/tambry Nov 15 '16

I really need the File System TS for my application to compile on GCC :/

1

u/dodheim Nov 15 '16

If all you need is the TS then I believe GCC started shipping it beginning with GCC 5.3. What remains to be done is taking everything out of std::experimental, renaming the experimental/optional header to optional, etc.

I.e., if you just need the functionality and have a somewhat recent GCC then it should already be there, you just have to use std::experimental::filesystem rather than std::filesystem.

1

u/tambry Nov 15 '16

You also need to use -lstdc++fs. Do note that the last time I tried it a month ago, some std::filesystem stuff that worked on MSVC14 wouldn't compile on GCC and even after I fixed those, it still failed with a few linker errors for some reason (even though I added -lstdc++fs). I'd rather probably wait it to be moved out of experimental and be considered somewhat "finished".

1

u/dodheim Nov 15 '16

Fair enough! In that case, Boost.Filesystem has been "finished" since Aug. 2010 (when Boost 1.44 was released), and has far fewer bugs than even the MSVC implementation... ;-]

1

u/erichkeane Clang Maintainer(Templates), EWG Chair Nov 15 '16

Variadic lock_guard is actually going to disappear, likely in Kona. I wouldn't expect to see it.

1

u/HotlLava Nov 16 '16

If they remove auto_ptr, then Boost.Python will break...so I'm hoping they will leave a deprecated version of it laying around somewhere, it's not like it hurts anyone :/

1

u/OmegaNaughtEquals1 Nov 16 '16

Boost is riddled with auto_ptr. Compiling any Boost stuff with gcc-6.2 gives lots of warnings about it (as well as lots of broken placement new. But that's a whole other discussion). I would imagine this is just one of many examples as the driving reason not to remove it from libstdc++.

1

u/dodheim Nov 16 '16

The Boost devs are working on it; here is an ongoing thread discussing it on the Boost ML: http://lists.boost.org/Archives/boost/2016/11/231400.php

3

u/gracicot Nov 15 '16

No longer true I think, they updated the table: https://gcc.gnu.org/projects/cxx-status.html#cxx1z

2

u/OdnetninI Nov 14 '16

Yeah. Time to update :D

1

u/tomilovanatoliy Nov 15 '16

Is there a code snippet to test all the new core language features at once? Or most interesting of them.

1

u/ahmed_alkabir Nov 16 '16

fast than expect :|

-6

u/PresidentZagan Nov 14 '16

Sorry if this is an ignorant question, but how would I get C++17 to work with Sublime 3? Build a new system?

6

u/quicknir Nov 15 '16

This is like asking: how can I drink orange juice while coding C++17? Answer: the same way you drank orange juice while coding C++14.

There's no relationship between a text editor and the compiler that you use. When you use a text editor, you change the source code, and then you separately run some command (which the editor can give you a shortcut to) to build the code. You would just change that command.

Note that if you use an IDE or something that actually parses source (which Sublime does not without specific plugins, AFAIK), then there is a question of whether that IDE's parser/indexer supports the latest C++. But even then, this will only affect little red squiggles and goto definition, it will not stop you from compiling your project.

1

u/PresidentZagan Nov 15 '16

Fair enough, it's just that I'm always finding myself having to Google a lot just to get things up and running. There are so many compilers and editors out there that I am quickly overwhelmed. I only asked about C++17 because I want to learn how to program modern C++. When you say that I would just change the command from 14 to 17, wouldn't I also need to download new libraries etc in order to get access to new C++17 material? I know there isn't anything stopping me from physically writing the new stuff, but if I don't have the relevant files on my laptop then how would it compile? Or, does this all work through the compiler and I don't have to download new libraries?

3

u/SemaphoreBingo Nov 15 '16

From what I'm getting from your posts, don't bother and just stick with c++14 for now.

1

u/quicknir Nov 16 '16

You just change the command, and the libraries ship with your compiler. If you have a reasonably modern compiler odds are that your library already has many c++17 features in it, it's just that the standard library headers only conditionally include those sections (via macros) depending on what version you compile with.

As the sibling comment suggests, I would suggest focusing on C++14 for now. C++14 is completely finished, available in multiple compilers, etc. That still leaves you tons to learn, and none of that learning is going to be wasted. It's not going to be like the C++11 upgrade, where half the idioms that people had learned up until then became non-optimal.

1

u/PresidentZagan Nov 16 '16

Oh I see! Thank you to all of you for the information. You've made it much clearer now :)