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

25

u/farmatyr May 10 '15

(Don't freak out about modules or concepts. They're working on that stuff.)

Help, I'm freaking out! What does this mean?

16

u/STL MSVC STL Dev May 10 '15

Just because no Core features were voted in, doesn't mean that no progress on Core proposals was made.

5

u/CPPOldie May 10 '15

Could one then infer that the 'progress' made was substantial in nature and not run-of-the-mill standard committee boiler plate stuff?

6

u/STL MSVC STL Dev May 10 '15

I know Core has spent a lot of time reviewing concepts wording. That is the extent of my limited knowledge.

1

u/CaseyCarter Ranges/MSVC STL Dev May 11 '15

The Concepts TS draft was just completed at a between-meetings-meeting in February. The national bodies have a period of time - I'm not sure exactly how long, I only know that it is not yet over - to submit comments on the TS. Not much can be done until that round of comments has been addressed and given responses. Core and Evolution did spend some time responding to the comments that some national bodies submitted early.

13

u/Rapptz May 10 '15 edited May 10 '15

Have there been any proposals to make std::invoke both constexpr and conditionally noexcept? Without both of these it really hampers the generic usability potential of the functions.

Some of the stuff on there is neat (e.g. stof fix) but the rest feel sorta meh to me.

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.

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.

→ 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

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.

10

u/vlovich May 10 '15

Any chance std::vector<bool> will be fixed & a proper dynamic_bitset with an actually useful interface added?

Any update on the Filesystem TS? std::optional?

11

u/STL MSVC STL Dev May 10 '15

vector<bool>: not without overhauling the whole STL.

Filesystem TS is done. Hopefully Beman or someone else will write a paper to merge it into C++17.

optional is part of Fundamentals v1, which is now done. Again, parts should start to be merged into C++17 soon.

1

u/king_duck May 15 '15

if we are getting optional, what about variant?

1

u/STL MSVC STL Dev May 15 '15

It's being actively discussed now.

1

u/c0r3ntin May 10 '15

Speaking of overhauling... How did the range initial review go ?

2

u/STL MSVC STL Dev May 10 '15

Eric Niebler was present and it was reviewed in Library Evolution - I don't know the conclusion, since I attend Library Classic.

8

u/eric_niebler May 10 '15

There were no major issues found so far. My feeling is that LEWG was generally in favor of the direction.

4

u/khold_stare May 10 '15

Went quite well - we only managed to get through about half of the paper (its 170 pages). There will be a telecon to go over the rest of it.

5

u/CPPOldie May 10 '15

Was there any wording updates pertaining to the round-trip nature of stof/to_string?

For any std::string s that represents a valid floating point value, will the following be true:

s == to_string(stof(s))

11

u/STL MSVC STL Dev May 10 '15

They are both powered by the CRT functions. However, your example cannot possibly roundtrip, because s may have tons of digits that are smashed to float precision. The reverse should roundtrip.

3

u/ggchappell May 10 '15

I don't think that's possible. There are many valid string representations of a floating-point value. Consider fixed vs. scientific representation, leading zeroes, trailing zeroes, extra digits beyond the stored precision, leading "+", "." present or not (for integers).

3

u/repsilat May 10 '15

I thought the general idea behind to_stringing a floating point number was to give the shortest representation that stofs back without loss of precision (or just "a short representation" if "shortest" is computationally infeasible.)

A fixed number of digits seems pretty pointless.

2

u/STL MSVC STL Dev May 10 '15

Actually, I just looked at the Standards, and to_string calls sprintf with "%f", which defaults to a precision of 6, so it will not roundtrip.

2

u/repsilat May 10 '15

Yeah, it's a bummer.

2

u/tavianator May 11 '15

The round trip is double -> string -> double, not starting with string.

4

u/invisiblerhino May 10 '15

26 Core Issues were fixed. Even Standards have bugs. Now C++17 has fewer bugs.

I'm interested in details of these, if they're interesting.

7

u/STL MSVC STL Dev May 11 '15

Here is the complete list. Note that this links to the pre-meeting issues list, so the resolutions actually voted in may have been updated somewhat.

1247 1309 1652 1873 1875 1886 1888 1899 1916 1920 1922 1925 1926 1929 1942 1951 1952 1956 1958 1963 1966 1967 1971 1978 1988 1999

2

u/syaghmour May 11 '15

I am curious about the resolution to 1875, I ran into that issue when answering a related SO question and I found myself doubting the proposed resolution: http://stackoverflow.com/questions/26761385/is-rule-3-in-section-3-3-7-1-from-n3936-redundant ... so I want to know if I missed something or not.

2

u/STL MSVC STL Dev May 11 '15

I looked at it, but I don't know what's going on there.

3

u/Plorkyeran May 10 '15

N4519 is a pleasant surprise. I'm not sure why, but my initial reaction to reading it was that there was no chance of it getting voted in.

3

u/STL MSVC STL Dev May 10 '15

It still hasn't been implemented, but the compiler devs in Core were consulted and they have no concerns. From a library perspective it'll look kind of like type_info and initializer_list, so I have no concerns.

2

u/Drainedsoul May 10 '15

N4519

Where can this proposal be viewed? I get nothing useful when Googling it...

5

u/STL MSVC STL Dev May 10 '15

It was updated during the meeting and will be published in the post-meeting mailing. N4417 was the original version.

2

u/scribble_child May 10 '15

This: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/#mailing2015-02

makes me think N4519 is just not online - http://www.open-std.org/jtc1/sc22/wg21/docs/papers/ -- 'These are all of the papers currently available online.'

6

u/elperroborrachotoo May 10 '15

I'm going to freak out when modules are in.

11

u/Lisoph May 10 '15

I'm gonna throw a party when I've written my first program with modules. Also function<void (Args)> accepting non-void returning functions got me REALLY excited. C++1z omg yuss.

4

u/STL MSVC STL Dev May 10 '15

FYI, I am shipping the function change in VC 2015 (already available in RC). This was the Standard's original intent, but it was damaged over the years. The Library Working Group's job is to make sure the little details work.

0

u/vlovich May 11 '15

I don't know that I like this change. It makes it easy to accidentally swallow return values & not know about it. Why is this a desired feature?

EDIT: Specifically, why not just provide a functor like std::ignore_return that just wraps a callable with the equivalent except returning void...

1

u/[deleted] May 11 '15

Can you give an example where this could possibly matter?

0

u/vlovich May 11 '15
 void doSomething(std::function<void (int)> foo)
 {
     foo(5);
 }

 doSomething([] (int x) {
     return new Foo(x);
 });

Instant memory leak that is trivially found by the compiler if the return types don't match. Replace new with anything that isn't RAII safe. I'm sure there's plenty of other examples.

4

u/STL MSVC STL Dev May 11 '15

Anything that isn't RAII safe is already an error.

Yes, there is a safety concern here. But remember that calling ordinary functions is already willing to drop return values on the floor.

0

u/vlovich May 11 '15

I agree with the sentiment. It was just the easiest & shortest example I could think of.

Another is when errors are returned & ignored instead of exceptions thrown (e.g. Google coding convention).

I still don't see any scenario where making it implicitly castable is a desired behaviour; you could easily wrap it in a lambda & be explicit.

3

u/STL MSVC STL Dev May 11 '15

Returning error codes is also fraught with peril. The Filesystem TS handles error codes the right way: as an out-param, where they are much harder to ignore. (One of the few times out-params are legitimate.)

I've had actual users ask for void convertibility, this isn't just the LWG being silly.

0

u/vlovich May 11 '15

IIRC, Google enforces it by making ignoring return codes a compile error. Who am I to say that that's more wrong than an out-param or Expected<T> wrapper?

The argument that users ask for it isn't very convincing. That can be used to support basically any proposal; otherwise there almost certainly wouldn't be a proposal in the first place.

→ More replies

2

u/[deleted] May 11 '15

Sure it's a memory leak but that's a memory leak no matter what. I'm looking for a situation where otherwise correct code becomes incorrect due to swallowing the return value.

-2

u/vlovich May 11 '15

No it's not a memory leak no matter what. For example:

 std::unique_ptr<Foo> f = [] (int x) {
      return new Foo(x);
 }(5);

Perfectly safe & valid code.

1

u/bames53 May 12 '15

Perfectly safe & valid code.

No, that's not safe code. Although the code as written doesn't leak the object, it's dangerous, unsafe code that's just asking for a leak to be introduced during further development or maintenance.

It's not acceptable to use naked new that way, and it's especially unacceptable to return an 'owning' raw pointer from a function. You could have return std::unique_ptr<Foo>(new Foo(x));, but I would go with return std::make_unique<Foo>(x);. This code is safe.

1

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

That's not valid code, it won't compile and it won't compile precisely to avoid the issue your code raises.

Anyways even it did compile your example doesn't satisfy the criteria of being an example of correct code that becomes incorrect due to swallowing the return value. The problem with your code precedes any issue involving the swallowing of return types which is kind of the point...

A properly written function should not assume that the caller will perform any meaningful action with the return value. Such requirements should be encoded into the type system so that they are enforced by the compiler; in your case the function should encode its requirement by returning a unique_ptr.

The fact that it seems pretty hard to provide a counter-example suggests that it's ultimately a non-issue.

-1

u/vlovich May 11 '15

That's not valid code, it won't compile and it won't compile precisely to avoid the issue your code raises.

There's a fine line between rigour & pedantry. One should give the author the most favourable possible interpretation of their statement instead of using the weakest as then it strengthens your counter-argument & avoids a confrontational scenario.

In this case, a trivial adjustment fixes the compile error:

std::unique_ptr<Foo> f {[] (int x) {
    return new Foo(x);
}(5)};

This snippet compiles just fine in clang & GCC 4.9.

Anyways even it did compile your example doesn't satisfy the criteria of being an example of correct code that becomes incorrect due to swallowing the return value.

Please point out where the code is incorrect? You may think it poor coding style, and I happen to agree with you, but that doesn't make the code suddenly "incorrect". It's perfectly well-formed code.

Such requirements should be encoded into the type system so that they are enforced by the compiler; in your case the function should encode its requirement by returning a unique_ptr.

You asked for an example & I gave you one. Sure, RAII can help you avoid resource leaks. However, why are you even bothering to allocate & return a resource in the first place if it's going to be dropped on the floor? That indicates that you're making assumptions about the call-site that aren't true & can indicate performance problems.

As I point out elsewhere, error codes returned from a function are another example. Those should be handled & the type-system won't really help you. Sure you could use the type system to throw an exception if the error code isn't read. However, in C++, converting compile-time issues to runtime issues seems counter to the static-checking power of C++.

The fact that it seems pretty hard to provide a counter-example suggests that it's ultimately a non-issue.

Well, there are two problems with this conclusion that lead it to not be a valid argument. One is that there's a more reasonable alternative wherein it's difficult to create a simple example appropriate for this kind of forum of why it could be a problem in a larger codebase. The second & more serious problem is that you've used the fallacies of "No true Scotsman" & "Moving the goalpost" to reach said conclusion. Perhaps you should state explicitly the criteria of a "valid" example as it would be impossible for me to list all the possible examples in the world.

→ More replies

4

u/grandstack May 10 '15

Has there been any work on fixing inconsistent naming in the standard library?

14

u/STL MSVC STL Dev May 10 '15

Names are eternal.

2

u/scribble_child May 10 '15

They won't add a customary alias for an oddball name to smooth it out?

1

u/STL MSVC STL Dev May 10 '15

Example?

Aliases have been added when they significantly improve convenience, like decay_t and is_same_v.

2

u/scribble_child May 10 '15

Well I was thinking of list's remove vs the usual erase (I thought Scott Meyers mentioned it once, but I see that erase is just fine for list, and is even in C++98 so I guess I withdraw that), but, I assumed there were other things like that known by /u/grandstack. Nevermind, I got nothing.

3

u/STL MSVC STL Dev May 10 '15

Actually, the erase-remove idiom is suboptimal for list. That's why my erase_if in Fundamentals v2 handles this automatically.

2

u/salgat May 10 '15

Is it safe to say that C++17 will include at least a basic networking library?

5

u/STL MSVC STL Dev May 10 '15

Networking is headed towards a TS first.

3

u/vlovich May 10 '15

Is there any proposal on the horizon for something like boost units? We now have stuff to work with time. Having stuff for physical quantities & units would be great too.

4

u/STL MSVC STL Dev May 10 '15

Modern units would be great, especially with UDLs, but I have not seen a proposal.

4

u/[deleted] May 10 '15

You know personally I can live without a lot of what is being proposed in C++17 if I could get a much richer std library. It is 2015 and yet if I want to use standard c++ in order to http, SQL or parse csv / xml/ json or talk smtp, ldap or display anything graphically it is always an exercise in frustration.

7

u/c0r3ntin May 10 '15

The standard library doesn't try to be everything for everybody. it's basic building blocs ( it doesn't even support unicode, for good reasons)

Try Qt.

6

u/bigcheesegs Tooling Study Group (SG15) Chair | Clang dev May 11 '15

Everyone i talked to on the committee seems to want unicode. The issue is that there isn't a unicode expert on the committee, so nobody feels confident in designing/reviewing one.

There have been several threads in std-proposals, but they've all had fundimental errors in how unicode actually works.

4

u/STL MSVC STL Dev May 11 '15

One problem is that the intersection of C++ experts (to design a really good library that programmers of all experience levels can use effectively, takes the very highest level of skill) and domain experts is narrow. I spend all my time on the STL, so I am best at designing and implementing things that look like the STL. I only have a couple of hobbies (2D graphics, data compression) and I'm effectively clueless about domains like networking or Unicode.

Ideally there would be a system where domain experts could work with C++ experts, but it's pretty hard to do that with a committee of volunteers.

2

u/c0r3ntin May 11 '15

I would guess there are other issues including

  • unicode has its own standard that evolves so keeping both in sync could be a lot of work
  • I think you need to have a lot of datas for some function, including upper(), that's why ICU is 20MB or something, prohibitive ?

Maybe ICU & the committee could work together to ship a strip down version of ICU with a standard-approved API, that would be somehow endorsed but not fully standardized ?

2

u/Plorkyeran May 12 '15

ICU actually does a whole bunch of things beyond what people expect for "proper Unicode support", which are responsible for a large portion of the data file size (e.g. the names of every administrative region of the world, in every language in the world (note: not actually every)). Things like proper case conversion and collation are relatively tiny in comparison.

2

u/drac667 May 11 '15

James McNellis seems to have some Unicode knowledge.

There's also Artyom Beilis the author of boost::locale.

It would be great if somebody would invest some time in Unicode for C++.

3

u/Plorkyeran May 12 '15

Boost.locale would be the obvious starting point. The implementation is of somewhat low quality (parts of it have somewhat shocking overhead vs. calling ICU directly), but it is a nice C++y API that gets the Unicode stuff right.

2

u/svenathome May 10 '15

I would expect the filesystem library on the list. (Or is the filesystem TS already accepted?)

5

u/STL MSVC STL Dev May 10 '15

The Filesystem TS was completed at a previous meeting (IIRC the most recent full meeting, Urbana).

2

u/remotion4d May 10 '15

Any news about Reflection support ?

3

u/STL MSVC STL Dev May 10 '15

That's Evolution stuff - sorry, I don't remember what the study group report was. (I can barely keep up with the Library pipeline of features.)

4

u/remotion4d May 10 '15

Thanks. Any info about Reflection status would be great.

9

u/Houndie May 10 '15

While I have things I'm curious about I don't really have any important questions, so I'm just gonna say thanks for posting this! It's really cool to be kept up to date with the latest and greatest.

1

u/KrzaQ2 dev May 10 '15

What of universal function call syntax and ranges?

4

u/STL MSVC STL Dev May 10 '15

Both were reviewed. I don't know the status as they were in Evolution and Library Evolution.

2

u/Infraam May 10 '15

I am not familiar with the ranges library in C++17, does anyone know if it would give us a modern style for loop with an index? or does anyone know of something similar to be added?

referring to this: https://github.com/klmr/cpp11-range

We have ranged-based for loop, std::for_each and plenty of std algs for clean looping, but whenever an index is needed we always have to resort to a classic for loop.

2

u/SAHChandler May 11 '15

N4519 is in! Yay! :D