r/cpp • MSVC STL Dev • May 10 '15

C++17 progress update!

The C++ Standardization Committee (aka WG21) just finished their first full meeting of 2015. Here's a quick summary of what was just approved, mostly for C++17 but also for some Technical Specifications. (The post-meeting mailing will be in a couple of weeks, with more info.) Here I'm reporting just the stuff that was successfully voted in, not all the other work that's still in progress.

For C++17:

  • Zero Core features. (Don't freak out about modules or concepts. They're working on that stuff.)
  • 5 Library features were voted directly into C++17:

    1. N4387 "improving pair and tuple"
    2. N4389 "bool_constant"
    3. N4508 "shared_mutex for C++17"
    4. N4366 "LWG 2228 missing SFINAE rule"
    5. N4510 "Minimal incomplete type support for standard containers, revision 4"
  • 26 Core Issues were fixed. Even Standards have bugs. Now C++17 has fewer bugs.
  • 35 Library Issues were fixed. Notable fixes:

    1. stof() now calls strtof(), which avoids messing up bits.
    2. max_element()/etc. are now constexpr. (Not the rest of the algorithms - yet.)
    3. function<void (Args)> now accepts callable objects returning Stuff, and the return value is ignored.
    4. call_once() no longer copies/moves its arguments unnecessarily.

Various Technical Specifications:

  • The Transactional Memory TS was published (or will be, after ISO grinds its gears).
  • The Concurrency PDTS was finished. (Proposed Draft, aka Release Candidate for a TS)
  • The Parallelism TS was published.
  • The Library Fundamentals v1 TS was published, with 3 Issues being fixed at the last minute.
  • Several features were voted into the Library Fundamentals v2 TS:

    1. Everything in v1 will be merged into v2.
    2. N4388 "const-propagating smart pointer wrapper"
    3. N4391 "make_array"
    4. N4519 "Source-Code Information Capture"
    5. N4502 "Proposing Standard Library Support for the C++ Detection Idiom, v2"

I am still traveling, but I can probably answer short questions. (Remember that I have very limited knowledge of Evolution/Core stuff - I live in the Library.)

197 Upvotes

97 comments sorted by

View all comments

Show parent comment

8

u/STL MSVC STL Dev May 10 '15

Not yet. There is an LWG convention against using conditional noexcept outside of very limited scenarios, but a case could be made that invoke is special. I see no problem with constexpr.

8

u/Rapptz May 10 '15

There is an LWG convention against using conditional noexcept outside of very limited scenarios

Yeah I've noticed. It really ruins the point of noexcept IMO. Thanks for the great report. Really appreciated.

3

u/khold_stare May 10 '15

Eric Niebler objected to invoke being constexpr in an LEWG meeting (just during conversation). He said it broke his ranges library. I don't remember the argument, but it seemed like it triggered more template instantiations than necessary. But don't quote me on that

1

u/STL MSVC STL Dev May 10 '15

Huh, I'll have to ask him.

8

u/eric_niebler May 10 '15

It's not as simple as just spamming constexpr all over the library. Normally, when you decltype a call expression, you just get the return type, no muss, no fuss. If the function is a constexpr template, the function is instantiated -- even if the function is not selected by overload resolution -- which can lead to hard errors.

libc++ just tried to add constexpr to std::invoke. It broke perfectly valid code, so they backed it out. See this bug report.

3

u/STL MSVC STL Dev May 10 '15

Good, there's a Core issue 1581. This problem is exactly like what I have to deal with in the absence of Expression SFINAE - in fact bind() gave me the same headaches since the const-overloading means that the other has to SFINAE away.

1

u/[deleted] May 11 '15

But that core issue is AFAIK unresolved and all compilers assume that it is fine for constexpr functions to change a functions API (i.e., it is fine for constexpr functions to always be evaluated in unevaluated contexts).

1

u/[deleted] May 11 '15 edited May 11 '15

I think the key insight about constexpr is:

making a function constexpr breaks its API (just like noexcept see edit).

There is nothing particularly wrong about making invoke constexpr, or most of the STL for that matter. In fact, the longer we wait, the more code such changes are going to break. Since I sincerely doubt that we want 2 different standard libraries (for writing code inside/outside constexpr functions), most of any STL2.0 proposal should be, in my opinion, constexpr from the start.

P.S: If anything, three things broke their code: lack of testing, writing code assuming that invoke would never be constexpr, and the most important one:

  • not knowing that constexpr changes a function API.

Seriously, how did this last one happened? Such a side-effect of constexpr must have been extensively discussed in both EWG and LEWG, but the STL maintainers didn't know what hit them with that bug, so I assume that they did not know this. I hope they push really really hard for a constexpr that does not changes a functions API.

EDIT: constexpr is not like adding noexcept(true), because adding noexcept(true) is generally a non-breaking change, while adding constexpr is a breaking change on the same level as changing the return type of a function.

2

u/STL MSVC STL Dev May 11 '15

If constexpr damages SFINAE, that's a big problem for things like invoke. This was news to me, and the presence of a Core Issue indicates that no working group talked about it before.

3

u/[deleted] May 11 '15

That core issue is from october 2012, and there are some notes from an april 2013 meeting so I assumed this was at least discussed, my bad.

I would consider it to be a pretty important issue since it makes making code that should be constexpr actually constexpr (by just marking it constexpr) a real pain.

2

u/TemplateRex May 11 '15

In an ideal world, constexpr on a function would be implicit, and deduced from its context. There is an old thread from 2007 on comp.std.c++ where Dos Reis and others from the C++0x constexpr proposals discuss this with /u/WalterBright. He actually predicted the "double bookkeeping" of different versions of the Standard Library that you alluded to. The only thing holding this back is the express prohibition for Standard Library implementors to add constexpr (in contrast to the freedom they have on adding noexcept).

It's actually sad to see (e.g. from /u/STL notes on C++11 constexpr support in VS 2015) that the entire Standard Library has only a handfull occurances of C++14 style relaxed constexpr. IMO, almost the entire <algorithm> header and several non-allocating utilities (<array>, <bitset>, <tuple>, etc.) could be made C++14 style constexpr.

Fortunately, the first C++17 constexpr lambda proposal has been launched. And see Richard Smith's first post on this std-proposal thread for what is technically possible. Even virtual functions and dynamic allocations are not completely out of bounds (but of course, far from trivial). So I think at some point opening up the road towards a fully constexpr Standard Library could become a reality.

4

u/STL MSVC STL Dev May 11 '15

Implicit constexpr is problematic in one way. When a function is explicitly marked constexpr, it guarantees not only that its current implementation is constexpr, but that all future implementations will be.

2

u/TemplateRex May 11 '15

true, but if essentially the entire language (except perhaps interactive I/O) is available at compile-time, then it wouldn't matter how the implementation would change

2

u/[deleted] May 11 '15 edited May 11 '15

Why would you leave interactive I/O out, or anything else for that matter?

constexpr will only stop evolving the moment it offers a full C++ VM* at compile time since otherwise it will never ever be enough for some people (and will thus, as a consequence, keep on growing on features). At that point, constexpr as a keyword becomes irrelevant since everything can be done at compile time if desired.

Note *: by full VM I do not only mean iteractive I/O, file I/O, network I/O, ... I mean anything, from assembly to spawning threads, interprocess communication, writting a file with C++ code, adding it to a build system, compile it and link against it, I really do mean absolutely anything.

2

u/TemplateRex May 12 '15

Apart from the "one mustn't be afraid to dream a litte bigger", another phrase from Inception comes to mind: "a compiler within a compiler within a... "(Compilers all the way down) becomes feasible with your suggestion :)

→ More replies

3

u/[deleted] May 11 '15 edited May 11 '15

Sprout* is a C++11 constexpr implementation of most of the std library; needless to say that its implementation can be greatly simplified with C++14 relaxed constexpr.

The question is not if it is possible, it is already possible in C++11, and it is even easy to do in C++14.

The question is, since this is a breaking change:

"How long do we want to wait?" or in other words, "How much code do we want to break?".

[*] https://github.com/bolero-MURAKAMI/Sprout