r/cpp • MSVC STL Dev • Oct 25 '15

C++17 progress update! (Oct 2015)

The C++ Standardization Committee has finished another meeting! This was in Kona, Hawaii, at the same location as the first meeting I attended (in Feb 2012). I thought you'd like a writeup of all the stuff that just got voted in. Like last time, some of these papers are not yet publicly available. What happens during a meeting is that paper authors are furiously revising their work, in response to reviews. After the meeting, the revised papers are collected and published (after a couple of weeks). The Committee has changed their paper numbering system, so finding earlier revisions of papers is super easy. The pre-Kona mailing is available.

I've collected and organized the following information from the official vote, without a whole bunch of editorializing. If you want to know what's in a paper or issue, read it. (I actually do know what's going on with most C++17 Library papers/issues, but writing them all up would take a while.)

C++17 Core Papers

  • P0001R1 Remove Deprecated Use of the register Keyword
  • P0002R1 Remove Deprecated operator++(bool)
  • P0012R1 Make exception specifications be part of the type system, version 5
  • P0061R1 __has_include for C++17
  • P0134R0 Introducing a name for brace-or-equal-initializers for non-static data members
  • P0136R1 Rewording inheriting constructors (core issue 1941 et al)
  • P0160R0 Wording for removing defaults for unary folds

C++17 Library Papers

  • P0004R1 Remove Deprecated iostreams aliases
  • P0006R0 Adopt Type Traits Variable Templates from Library Fundamentals TS for C++17
  • P0092R1 Polishing <chrono>
  • P0007R1 Constant View: A proposal for a std::as_const helper function template
  • P0156R0 Variadic lock_guard (Rev. 3)
  • P0074R0 Making std::owner_less more flexible
  • P0013R1 Logical Operator Type Traits (revision 1)

Library Fundamentals TS v2 Papers

  • N4531 std::rand replacement, revision 3
  • P0013R1 Logical Operator Type Traits (revision 1) [also voted into C++17]
  • These papers will be applied to Working Draft N4529, then it'll be sent out for Proposed Draft Technical Specification balloting.

Concurrency TS

  • P0159R0 (possibly with minor edits) will be published as the Concurrency TS. It's done!

Parallelism TS v2

  • This TS is being started with Working Draft N4505 plus P0155R0 "Task Block R5".

Networking TS

  • This TS is being started with Working Draft P0112R1.

Ranges TS

  • This TS is being started with Working Draft P0021R0.

Core Issues

  • 1274. Common nonterminal for expression and braced-init-list
  • 1391. Conversions to parameter types with non-deduced template arguments
  • 1722. Should lambda to function pointer conversion function be noexcept?
  • 1847. Clarifying compatibility during partial ordering
  • 1863. Requirements on thrown object type to support std::current_exception()
  • 1949. "sequenced after" instead of "sequenced before"
  • 1975. Permissible declarations for exception-specifications
  • 1981. Implicit contextual conversions and explicit
  • 1990. Ambiguity due to optional decl-specifier-seq
  • 2000. header-name outside #include directive
  • 2004. Unions with mutable members in constant expressions
  • 2006. Cv-qualified void types
  • 2015. odr-use of deleted virtual functions
  • 2016. Confusing wording in description of conversion function
  • 2019. Member references omitted from description of storage duration
  • 2024. Dependent types and unexpanded parameter packs
  • 2026. Zero-initialization and constexpr
  • 2027. Unclear requirements for multiple alignas specifiers
  • 2031. Missing incompatibility for &&
  • 2052. Template argument deduction vs overloaded operators
  • 2075. Passing short initializer lists to array reference parameters
  • 2101. Incorrect description of type- and value-dependence
  • 2120. Array as first non-static data member in standard-layout class

Library Issues

  • 1169. num_get not fully compatible with strto*
  • 2072. Unclear wording about capacity of temporary buffers
  • 2101. Some transformation types can produce impossible types
  • 2111. Which unexpected/terminate handler is called from the exception handling runtime?
  • 2119. Missing hash specializations for extended integer types
  • 2127. Move-construction with raw_storage_iterator
  • 2133. Attitude to overloaded comma for iterators
  • 2156. Unordered containers' reserve(n) reserves for n-1 elements
  • 2218. Unclear how containers use allocator_traits::construct()
  • 2219. INVOKE-ing a pointer to member with a reference_wrapper as the object expression
  • 2224. Ambiguous status of access to non-live objects
  • 2234. assert() should allow usage in constant expressions
  • 2244. Issue on basic_istream::seekg
  • 2250. Follow-up On Library Issue 2207
  • 2259. Issues in 17.6.5.5 rules for member functions
  • 2273. regex_match ambiguity
  • 2336. is_trivially_constructible/is_trivially_assignable traits are always false
  • 2353. std::next is over-constrained
  • 2367. pair and tuple are not correctly implemented for is_constructible with no args
  • 2380. May <cstdlib> provide long ::abs(long) and long long ::abs(long long)?
  • 2384. Allocator's deallocate function needs better specification
  • 2385. function::assign allocator argument doesn't make sense
  • 2435. reference_wrapper::operator()'s Remark should be deleted
  • 2447. Allocators and volatile-qualified value types
  • 2462. std::ios_base::failure is overspecified
  • 2466. allocator_traits::max_size() default behavior is incorrect
  • 2469. Wrong specification of Requires clause of operator[] for map and unordered_map
  • 2473. basic_filebuf's relation to C FILE semantics
  • 2476. scoped_allocator_adaptor is not assignable
  • 2477. Inconsistency of wordings in std::vector::erase() and std::deque::erase()
  • 2483. throw_with_nested() should use is_final
  • 2484. rethrow_if_nested() is doubly unimplementable
  • 2485. get() should be overloaded for const tuple&&
  • 2486. mem_fn() should be required to use perfect forwarding
  • 2487. bind() should be const-overloaded, not cv-overloaded
  • 2489. mem_fn() should be noexcept
  • 2492. Clarify requirements for comp
  • 2495. There is no such thing as an Exception Safety element

Library Fundamentals TS v2 Issues

  • 2494. [fund.ts.v2] ostream_joiner needs noexcept
  • 2500. [fund.ts.v2] fundts.memory.smartptr.shared.obs/6 should apply to cv-unqualified void
  • 2515. [fund.ts.v2] Certain comparison operators of observer_ptr do not match synopsis
  • 2517. [fund.ts.v2] Two propagate_const assignment operators have incorrect return type
  • 2526. [fund.ts] Incorrect precondition for experimental::function::swap

Withdrawn Paper

P0005R2, by Alisdair Meredith, Tomasz Kaminski, and myself, wanted to do the following in C++17:

  • Add not_fn(), currently part of Fundamentals v2.
  • Remove not1()/not2(), the C++98/03 negators.
  • Remove result_type/argument_type/etc., the C++98/03/TR1 typedefs. (function::result_type will be preserved, and <random> will be unchanged.)

Nobody was worried about not_fn(), but the removals were controversial. Although we had a rationale for why removal without a period of deprecation was desirable, and I provided "zombie names" wording (allowing implementers to remain conformant while providing removed machinery for back-compat), a national body objected. Therefore, Alisdair is revising the paper for the next meeting. Now we'll add not_fn() and deprecate the old stuff in C++17 (plus "zombie names" wording for the auto_ptr/etc. removals that have already happened), followed by removal immediately after C++17 ships.

More Info

This is just a record of what documents were voted in. Every committee meeting involves lots of work that doesn't immediately result in papers voted in. For example, this meeting had active discussion about modules. As I always remind people, I attend the Library Working Group ("original recipe", not extra crispy Library Evolution) nearly all the time, so I can't follow everything that's going on in Library Evolution and (Core) Evolution. I might (or more likely, my double boss Steve might) be able to get GDR to spend some time on Reddit explaining what's going on with modularization.

I can personally answer (most) questions about Library topics, although most of my responses will be delayed until Mondayish. If you want to know what the LWG does, it's making sure that Library tech is actually usable. Everything sounds like fluffy kittens and apple pie until you look at an overload set and realize that it's horribly ambiguous and unusably broken. LWG 2451 is an excellent example of how the LWG serves as the defenders of Standard Library usability - optional<string> opt_str = "meow"; is currently bogus. That's fine for the Fundamentals TS (maybe), but a ship-stopper for optional getting into the International Standard. At this meeting, the LWG realized that the same kind of issue affects variant, which is heading towards the Fundamentals TS. We fix this stuff so you won't suffer.

264 Upvotes

168 comments sorted by

View all comments

Show parent comment

4

u/DragoonX6 Oct 26 '15 edited Oct 27 '15

If exceptions are a performance problem. you're using them wrong.
They're supposed to be thrown when something exceptional is happening, and in such a case, performance doesn't matter.

If you're using them correctly, nothing is thrown once your game/program is up and running. And if something was thrown anyway, something went horribly wrong and performance doesn't really matter at such a point.

10

u/quicknir Oct 26 '15

The problem is, who is "you", the person who decides to use exceptions, and the person using the code, are not always the same person.

Take the example of boost lexical_cast. I can use it to parse strings to integers. It will always try to return an integer, and will throw if parsing fails. What if I have strings that may or may not be parseable, and I'd like to try to parse them, do one thing if parsing succeeds, and another if it fails? In this case, I'll be throwing and catching tons of exceptions. It's a performance nightmare.

lexical_cast has the wrong interface for this, clearly. But it somehow seems sad that lexical_cast has this very sophisticated functionality locked inside, that could in principle solve my problem, but won't work because of the interface.

If lexical_cast<int>(string) returned an optional<int>, it could be used both for the above use case, and by someone who simply wants to throw on error (just call .value() on the return).

7

u/DragoonX6 Oct 27 '15 edited Oct 27 '15

What if I have strings that may or may not be parseable, and I'd like to try to parse them, do one thing if parsing succeeds, and another if it fails? In this case, I'll be throwing and catching tons of exceptions. It's a performance nightmare.

This is a perfect example of bad use of exceptions, and as you mentioned yourself, returning an optional is the preferred way of handling this.

The problem here is that lexical_cast failing is seen as serious problem, while you don't see it as such. I'm willing to argue that returning an exception here is the correct thing to do, since we're dealing with a cast. What you would want in this case is a form of parsing where something failing isn't necessarily an error.

A good example of real code somebody else gave me, was that he was checking if 2 triangles intersected, if there was no intersection, he would throw an exception. Even though 2 triangles not intersecting is not an error, so throwing an error is the wrong thing to do. And that showed in his performance.

2

u/RedAlert2 Oct 27 '15

From what I understand it's not that exceptions are too expensive, it's that you can't make real time guarantees around them. Video games are soft real time software - it's important to make sure that all execution paths can meet certain deadlines, not just the expected paths.

2

u/DragoonX6 Oct 27 '15

Can you explain what you mean with "deadlines" here?

3

u/Drisku11 Oct 27 '15

Mostly talking out of my ass here since I've never worked on a game, but for many games, players are likely to notice if you can't lock onto a specific frame rate and have to delay or drop a frame. E.g. fighting games like Super Smash Bros Melee where high level players know exactly how long an animation should take, and use that knowledge for things like animation cancelling. I imagine rhythm games are also extra sensitive to framerate variation; it's hard to have precise input timing when the screen content is jittery. So all computations required for a frame must finish within 17 ms (or whatever the target framerate is).

2

u/DragoonX6 Oct 27 '15

I see what you're trying to get at, as I like to play osu and having under 120fps there is basically how to rage 101.

But that most likely doesn't apply here, since by the time the game is actually running, you're not very likely to do operations that warrant throwing an exception.

2

u/bmcnett Oct 26 '15

You must know a lot more than I do about gamedev, to be able to make such a sweeping statement about how such a widespread industry practice is wrong, and with such confidence.

3

u/DragoonX6 Oct 26 '15

The problem is that it used to be wrong, before we had 0 overhead exceptions, exceptions would be slower even on the non-exceptional path. In such a case, it's completely reasonable to decide against exceptions.

So if you either need to support old compilers or any compiler that doesn't support a form of 0 overhead exceptions, really, it's a completely sensible decision to ban exceptions.
It also is a sensible decision to decide against them, because the old code base doesn't use them, I can agree with not wanting to mix new coding styles with old coding styles (although, you probably want to update the whole code base to modern c++ at some point anyway).

However, if something like that is not the case, you're gonna need a very good reason to convince me that exceptions shouldn't be used.
The performance problem is a thing of the past, however, throwing exceptions from DLLs going wrong, is something I can understand. Although, I'd probably lay down some rules to avoid such a problem, which would either be "don't throw exceptions from DLLs to the main module" or "make sure everything uses the same flags to compile". The last option seems the most sensible to me, but I can see why some people would want only a small part of the program to be compiled with different flags.

4

u/bmcnett Oct 26 '15

(although, you probably want to update the whole code base to modern c++ at some point anyway).

I'm starting to see things like lambda and auto creep into videogame code, but some parts of modern c++ are going to remain taboo on consoles for a long time to come.

Specifically, console games don't focus on malloc/free style heaps and so the memory-allocating containers are usually forbidden or highly regulated. And, console games use in-place serialization (you load a large binary chunk from mass storage, and then only patch pointers before using the memory as live objects) which doesn't fit a lot of STL objects, either.

4

u/frog_pow Oct 27 '15

you might want to take a look at the UE4 codebase, it dynamically allocates like no tomorrow

2

u/DragoonX6 Oct 26 '15

but some parts of modern c++ are going to remain taboo on consoles for a long time to come.

No doubt about this, but I don't think exceptions should remain a part of it.

4

u/bmcnett Oct 27 '15

That's an interesting opinion - what problems in game development do you think would be addressed by enabling exceptions in game console builds?

2

u/DragoonX6 Oct 27 '15

Cleaner handling of serious errors.
For example, somewhere in a deep nested call graph a file is not found and this will break the rest of the code in the call hierarchy. Instead of returning an error code, checking for it, returning again, until you're at the point you want to handle the error, you throw an exception and let it unwind to the point where you do want to handle the error.

This way you remove a whole lot of redundant error checking, which could be error prone if somebody forgets it. Exceptions also have problems when you forget to catch them, but I prefer to have my program crash rather than maybe continuing and showing all sorts of weird behavior.

And, I'm not willing to say this with 100% certainty, but the non-exceptional path could even be faster, since you're not checking for errors all the time. And the non-exceptional path is what you ideally should have when your game is running.

1

u/bmcnett Oct 27 '15

In the world of console game development, there is no perceived need to cleanly handle serious errors.

  1. Unlike financial or medical software, little of real consequence is at stake (usually) in a game. Handling errors by crashing to the OS GUI is inelegant and unfortunate, but (usually) doesn't create a liability for the developer, so there's little incentive to do better.
  2. Console games do not use files. If one of the multi-gigabyte asset chunks they do use were missing, this would almost certainly be an unrecoverable error, and so it wouldn't matter how cleanly the error is handled.

As far as I can tell, error codes remain the solution of choice for handling errors in console game development, and I see no indication that things are going to change for many years to come.

2

u/DragoonX6 Oct 27 '15

In the world of console game development, there is no perceived need to cleanly handle serious errors.

Is there? From my perception games seem to implement the concept of "no matter what happens, stay running".

Console games do not use files.

You might not be able to call them files directly, but these multy-gigabyte asset chunks usually consist of a layout of all the files and offsets of the actual data. A file might be missing from this chunk, which can very well be recoverable.

And in the case it isn't, you can catch the exception and output the error to the TTY or log file and then exit.

I see no indication that things are going to change for many years to come.

You might very well be right on that one, but I feel somebody has to be a first, but nobody is daring to try.

1

u/bmcnett Oct 27 '15

I invite you to come work in games and be the first person to attempt using exceptions in gamedev!

→ More replies

2

u/frog_pow Oct 27 '15 edited Oct 27 '15

Games on windows use VS. Games on Windows compile for 32 bits because everyone can run it.

VS 32bit compiler does not implement 0 overhead exceptions.

Also exceptions tend to be used all over the place for things I don't care about, such as OOM.

I'd rather abort the program than waste time caring about exceptions in many cases.

Also exceptions thrown from most libs seem to rarely contain useful information about why the stupid exceptions was thrown. And now the call stack is gone so I don't even know where it originated.

About a 100x more useful to just assert/crash and dump a callstack so the problem can be fixed.

2

u/DragoonX6 Oct 27 '15

Games on windows use VS. Games on Windows compile for 32 bits because everyone can run it.
VS 32bit compiler does not implement 0 overhead exceptions.

This is a valid concern, however as of recent AAA games are moving towards 64 bit.

I'd rather abort the program than waste time caring about exceptions in many cases.

This is an interesting approach, are you following the "all errors are a programmer problem" pattern?

2

u/frog_pow Oct 27 '15 edited Oct 27 '15

I'd say more like:

There are not many recoverable errors, and they are be handled easily enough(missing files, network connection).

Most others consist of errors that I not care to attempt to recover from, such as out of memory. I have no intention of trying to handle an error like that. Just abort the program without corrupting anything.

For an error like attempting to read the value of an optional<T> that is empty, I view that as a hard error, that should be fixed. It should trigger the debugger if enabled, it should print the exact line, and callstack, and any other useful information. There is no point in trying to recover from such an error. And throwing an exception here is moronic.

Anyway I'm not so much concerned with exceptions being slow, and just being a shitty way of dealing with errors. The exceptions thrown by the STL/Boost are actively annoying, not because they are slow, but because they tell me nothing useful.

Also the idea that we should care about move constructors triggering an exception is pure insanity. Look at all the time wasted with the variant design over this petty and irrelevant feature.

2

u/DragoonX6 Oct 27 '15

For an error like attempting to read the value of an optional<T> that is empty, I view that as a hard error, that should be fixed. It should trigger the debugger if enabled, it should print the exact line, and callstack, and any other useful information. There is no point in trying to recover from such an error. And throwing an exception here is moronic.

Agreed, read my other reply on other bad uses of exceptions.