This paper proposes allowing usage of virtual inheritance. This will allow in futureconstexpr-ification ofstd::ios_base, and streams, removing final limitation for making most of stream formattingconstexpr.
This will also remove definition ofconstexpr-suitable as it will be meaningless and clean all references across draft of the standard (if this paper land afterP3367: constexpr coroutines).
Last language syntax thing which is disallowed in[dcl.constexpr] which blocks us from makingstd::stringstream constant evaluatable, which blocks us from making exception types for<chrono> (chrono::nonexistent_local_time andchrono::ambiguous_local_time). Stream formatting<chrono>. Usingbasic_istream_view in range code for compile-time parsing.
When we remove this limitations, language will only have limit on evaluation properties of code in[expr.const], and not syntactical (with exception ofreinterpret_cast, but this is also defined as not constant evaluatable.)
Then keywordconstexpr can be seen only as an opt-in into constant evaluatable and can belater removed and replaced with an opt-out attribute (this is not propesed here.)
struct Superbase {string id{"name"};};struct Common: Superbase {unsigned counter{0};};struct Left: virtual Common {unsigned value{0};constexpr const unsigned & get_counter() const {return Common::counter;}};struct Right: virtual Common {unsigned value{0};constexpr const unsigned & get_counter() const {return Common::counter;}};struct Child: Left, Right {unsigned x{0};unsigned y{0};// ...};constexpr auto ch = Child{};// before: not allowed to even construct// after: works as expectedstatic_assert(&ch.Left::get_counter() == &ch.Right::get_counter());In progress in clang's fork. Currently structures are represented asAPValue object with type fieldstruct and pointer to an array ofAPValue-s containingnAPValue-s representing base types andkAPValue representing each member subobject.
Lookup for outermost object is already implemented in clang in order to implementvirtual function calls. So only changes needed are:
APValue to contain number of virtual bases (inAPValue.h)I spoke with other implementors and they don't seem to have any major concern about implementability.
Removing last limitation onconstexpr-suitable as defined in[dcl.constexpr] will make it a tautology asevery function will now beconstexpr-suitable hence this paper contains changes to removal of it across wording.
But this term was used somehow badly to make specify what must be constant evaluatable. It's a subject ofLWG issue 2833. Library needs to invent wording specifying something like"implementation must make sure this functionality is constant evaluatable by avoiding constructs disallowed in[expr.const]". Asconstexpr keyword doesn't mean something must be constant-evaluatable, it's just an opt-in into evaluation for some (or none) code-paths.
I still kept removal of all references toconstexpr-suitable in this paper for the project editor's convenience but I guess LWG will do some changes there as they will resolve the issue 2833.
Paper contains two sets of wordings. One is based on current draft and one is based on changes inP3367 constexpr coroutines.
__cpp_constexpr_virtual_inheritance 2025??L