News for hackers. Stuff that matters.
Re:When noexcept? by pjc50 on Thursday December 15, 2016 @09:21AM (#13184684)
They still made it a runtime failure rather than a compile-time enforcement of no exceptions? What is the point of that?
Re:When noexcept? by maxlybbert on Thursday December 15, 2016 @09:49AM (#13184889)
One of the ground rules for the old exception specifications was that it had to be possible to link code compiled at different times. Which meant that there might never be a moment when the compiler had access to all the source code. And, given that most code did not have exception specifications, the only way to enforce them at compile time would have been to require them on all functions.

I didn't follow the development of noexcept, so I can only guess at the motives. By and large, there were three complaints about exception specifications that I am familiar with: (1) by requiring stack unwinding when a no-throw specification was violated, they often caused worse performance (or, at least, didn't allow an optimization opportunity); (2) generally, the important question is whether a function might throw, not which exceptions it might throw; and (3) the rules around when exception specifications affect a function's signature -- e.g., does a pointer to a function have to match the specification exactly? -- were convoluted. I think it was reasonable for the Committee to focus on those issues.

Re:When noexcept? by gpderetta on Thursday December 15, 2016 @05:06PM (#13188943)
A possible solution would have been optional static enforcement of exception specifications plus fallback on the existing dynamic enforcement.

Existing unmarked functions would be expeced to possibly throw everything, while functions with throw specifications would be statically checked.

You can call the later from the former, but to do the reverse you need an explicit try/catch. Some form of throw(auto) would enable automatic deduction of exception specifications for e.g. template code.

Dyanamic exception specifications will be removed fron the language in c++17, so the synax is open to be reused for such a feature in the future.

Re:When noexcept? by palunon on Thursday December 15, 2016 @06:17PM (#13189615)
The problem is C code. You know it won't throw, but there will never be any exception specification on it.
Re:When noexcept? by Rexxar on Thursday December 15, 2016 @09:37AM (#13184787)
The "nothrow" is not part of the function signature, probably in order not to break retro-compatibility. Without this, "nothrow" cannot be enforced reliably at compile time. And I think they don't want to add a new sort of undefined behaviour if a function from a linked module doesn't respect the nothrow promise at runtime.
Re:When noexcept? by maxlybbert on Thursday December 15, 2016 @05:42PM (#13189330)
You are right, even nothrow doesn't fix the weirdness with signatures. However, nothrow allows a program to change behavior based on whether a function it will call will throw exceptions. That wasn't available under the old exception specification mechanism.