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

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.

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.