P3141: std::terminates()

A new WG21 paper is available.

Document number: P3141

Date: 2016-04-01

std::terminates()

by Hal T. Ng, Professor, C.S., LLVM.edu

Excerpt:

In 2014, the C++ committee tackled the problem of C++98's subtly hard-to-use std::uncaught_exception(), which was intended to return whether there were unhandled exceptions but did not work as intended in all destructor cases. The committee successfully addressed the problem by providing the improved std::uncaught_exceptions() (note plural "s"), which returns the number of unhandled exceptions in the current thread, and this function can now be used to reliably implement scope_guard and similar patterns in portable code.

Continuing in the same vein, this paper proposes to address C++98's related and sometimes-problematic std::terminate(). As its name suggests, the function causes abrupt program halts, which can cause data corruption if operations in flight are not completed gracefully. The set_terminate_handler() facility only partly addresses this problem by allowing a last-ditch handler to be invoked after unstoppable termination has already begun.

Along the same lines as conditional noexcept (noexcept(cond)), we propose a way for a sensitive operation, or a whole program, to determine in advance whether termination is possible. A program can test this by calling:

namespace std {
    bool terminates();
}

which returns true if and only if the program can subsequently terminate.

Because this function cannot fail to determine a valid result, it should be noexcept. Further, anticipating its usefulness in constant expressions and following LWG’s guidance for using constexpr wherever possible throughout the standard library, we propose in full:

namespace std {
    constexpr bool terminates() noexcept;
} 

Implementation notes: This function is so simple to specify that we foresee no implementation difficulty in any of the major C++ compilers.

Note that this is not the same as the halting problem, which would be to return true if and only if the program will halt, and which is known to take several hours to compute for programs longer than a few tens of millions of lines. Rather, this function is carefully constructed to return true if and only if the program could terminate, which is fundamentally different and well understood problem.

Acknowledgments: This paper expands on the core idea that was first proposed in committee hallway discussion by P.J. Plauger.

C++ Core Guidelines Checkers: Preview of the Lifetime Safety checker--Andrew Pardoe

The Visual C++ Team announces a preview of the Lifetime Safety checker for CppCoreCheck:

C++ Core Guidelines Checkers: Preview of the Lifetime Safety checker

From the article:

Lifetime safety is ensuring that the lifetime of any object matches its use. That is, don’t leak objects by forgetting to delete them in the case that they were allocated on the heap, and don’t access objects...

C++ sessions at JAX Finance

The JAX Finance conference is to be held in London in April.

The Conference for Technology in Finance

About the conference:

JAX Finance is a three-day conference for software experts focusing on the specific technological needs of the financial industry.

This year the conference includes a number of sessions on C++ (in addition to the existing focus on Java.)

Dates: 27 - 29 Apr

Venue: Park Plaza Victoria, London

 

GoingNative 48: ISO C++ @Jacksonville Debriefing -- Gabriel Ha

goingnative48.PNGJust posted on C9:

GoingNative 48: ISO C++ @Jacksonville Debriefing

by Gabriel Ha

From the post:

We're back with another round of updates from the most recent ISO C++ standards meeting at Jacksonville, where some..."interesting" turns of events took place.

Timeline
[0:30] Interview portion begins
[1:35] The Jacksonville Controversy
    [3:07] Why should I care about TS's?
[5:55] New TS's
    [6:00] Modules (Try it out [VS] | Learn more | Send feedback)
    [6:27] Coroutines (Try it out [VS] | Learn more | Send feedback)       
    [7:59] Concepts (Try it out [GCC] [6.0 changes] | Send feedback)
    [10:11] Ranges (Try it out [GCC] [6.0 changes] | Send feedback)
[11:33] Direct-into-Standard items
    [11:40] constexpr v3
    [12:16] New attributes (fallthrough, nodiscard, maybe_unused)
    [14:24] Extended aggregating initializers
    [15:34] Sentinel iterators
    [16:14] Hex floats
[16:27] TS-into-Standard items
    [16:38] Parallelism TS (Learn more)
    [17:30] Library fundamentals v1 TS (Try it out [Boost] [GCC] [6.0 changes])
    [19:19] File system TS
    [20:01] "Special" math IS [International Standard] (Try it out [Boost] [GCC] [6.0 changes])
[22:21] What's next for the committee?
    [22:27] And how exactly does one pronounce "Oulu?"

[23:01] Call to action: Get involved with the committee, try out the TS's!
    Download the latest versions of GCC [6.0]Boost [1.60], and/or Visual Studio [2015 Update 2 RC]

C++Now 2016 program is online

The C++Now 2016 program is online.

Sean Parent

C++Now 2016 program

From the program:

The this years C++Now keynote will be held by the conference's first ever keynote speaker, Sean Parent. He is returning for the tenth annual conference to deliver this year's keynote, "Better Code."

STL Algorithms in Action -- Haitham Gad

Use of STL Algorithm as building block to implement various high level algorithms.

STL Algorithms in Action

by Haitham Gad

From the article:

We saw variations of three common sorting algorithms implemented generically and compactly using STL algorithms. In general, STL algorithms are more applicable than they look. The key to utilizing them is to always ask whether the raw loop I’m about to write (or the one I’m reading) can be replaced by a packaged STL algorithm. You’d be surprised how many times this question can be answered affirmatively.

CppCast Episode 50: Stream Processing with Jonathan Beard

Episode 50 of CppCast the only podcast for C++ developers by C++ developers. In this episode Rob and Jason are joined by Jonathan Beard to discuss Stream Processing with his Raft Library.

CppCast Episode 50: Stream Processing with Jonathan Beard

by Rob Irving and Jason Turner

About the interviewee:

Jonathan Beard received a BS (Biology) and BA (International Studies) in 2005 from the Louisiana State University, MS (Bioinformatics) in 2010 from The Johns Hopkins University, and a PhD in Computer Science from Washington University in St. Louis in 2015. Jonathan served as a U.S. Army Officer through 2010 where he served in roles ranging from medical administrator to acting director of the medical informatics department for the U.S. Army in Europe. Jonathan's research interests include online modeling, stream parallel systems, streaming architectures, compute near data, and massively parallel processing. He is currently a Senior Research Engineer with ARM Research in Austin, Texas.