Red Hat at the ISO C++ Standards Meeting (April 2017, Kona): Core Language

The March/April C++ meeting was back in Kona, Hawaii again, only a year and a half after the last Kona meeting. As usual, Red Hat sent three of us to the meeting: Jonathan Wakely, Torvald Riegel, and me.

The headline from the meeting was voting to submit C++17 for approval by the national bodies. There wasn’t really any significant resistance.

There was one new feature added in the final draft, namely std::byte, which was expected to go in at the meeting in Issaquah, WA, last November but got derailed by naming concerns. std::byte is intended to be used instead of a variant of char for typeless memory access; hopefully, in the future, we can remove the broad aliasing semantics from char and thereby improve optimization of types with char members.

As usual, I spent the week in the Core language working group.

Core spent much of the week discussing C++ Modules and argument-dependent lookup. In C++ without Modules, there’s only one instance of each namespace, so it’s clear what is found by argument-dependent lookup. But this gets more complicated with modules, where a template defined in module A might depend on non-exported declarations, and argument-dependent lookup might need to find declarations in another module or the importing translation unit. For more information on these discussions, see this paper.

The expectation was that after these adjustments, the Modules working paper would advance to the initial ballot as a Technical Specification. But at the full committee plenary at the end of the week it was pointed out that some design choices made at the Jacksonville meeting the previous year were still not reflected in the document; as a result, we decided not to proceed to TS at this point.

Some people are eager to have published a TS in order to increase the number of implementations, but I’m skeptical that it would actually make a difference; the Concepts TS has not led to any more implementations, and it did not help Concepts make C++17. It may even have hindered the progression of Concepts, as we spent a lot less time looking at Concepts issues after the publication of the TS, and even explicitly delayed considering significant design concerns to wait for feedback from users and implementors, which feedback was later deemed to have been inadequate. In particular, our experience with the Concepts TS being published with known design issues should discourage us from doing the same with Modules.

For Modules, I don’t think that a delayed TS will be a problem at all.  Users are clamoring for the feature, and work is proceeding swiftly toward a GCC implementation in addition to the existing (and rather different) VC++ and Clang implementations. If Modules stays as a working paper until it is incorporated into C++20 that seems fine to me.

Core also spent a fair amount of time resolving issues with C++17 class template argument deduction and deduction guides, which were a source of concern for many people going into the meeting. I led this off by drafting and implementing proposed resolutions to issues that had come up on the reflector and worked through the week with Michael Spertus on the Library side to make sure that the feature as specified had semantics that would work well for Library templates.

We also discussed a concern raised by Library with the restrictions on using a pointer to an old object that has been replaced. After the C++98 standard, core issue 89 pointed out that there was no restriction on replacing a static or automatic object containing a reference member like there was for const objects. In response, the committee added a restriction on pointers to objects containing const or reference members: if such an object is replaced, a pointer to the old object cannot be used to refer to the new object.

Optimizers have never taken advantage of this restriction, but late in the C++14 process people noticed that this rule causes problems with several library classes; it was discovered when thinking about std::optional, but clearly affects std::vector as well. Given a vector of class C which contains a reference member, if we pop an element and then push a new object in its place, can we use vector’s internal data pointer to refer to the new object? This is core issue 1776.

The solution adopted for issue 1776 was to provide a library function std::launder which could be used to tell the compiler to forget what it thinks it knows about what a pointer refers to. So std::vector can launder its internal pointer and then use it to refer to the new object.

There continue to be concerns that this isn’t good enough, but Core is not yet convinced. There will be an evening session for discussing this issue at the next meeting.  One compromise might be to weaken the restriction (and therefore the potential optimization) specifically for pointers while retaining it for references and named variables; issue 89 was originally about named variables and the restriction in paragraph 10. Independently, it might make sense for launder/placement new to implicitly launder all pointers based (in the sense of C restrict semantics) on a common ancestor; it doesn’t make much sense to need to use the return value.

The next meeting will be in Toronto, ON, Canada in July 2017.

Whether you are new to Containers or have experience, downloading this cheat sheet can assist you when encountering tasks you haven’t done lately.

Join the Red Hat Developer Program (it’s free) and get access to related cheat sheets, books, and product downloads.