C++ Logo


Advanced search

Allow virtual base classes in constexpr

From: Lyberta <lyberta_at_[hidden]>
Date: Fri, 31 May 2019 23:24:00 +0000
I have a serialization library that is designed very similar to standard
streams. So I have a very base class and virtually inherit input and
output streams from it. Naturally, most of the functions are virtual.

When I heard that virtual functions are allowed in constexpr in c++20, I
was excited because I thought I would be able to make most of the code
constexpr. Especially span streams that don't use any dynamic allocation.

When GCC 9 was released a month ago with support for virtual constexpr,
the first thing I tried is to aggressively add constexpr to my library.
I was immediately stopped by compiler because virtual base classes are
not allowed.

There is a proposal for text streams that use std::span - p0448. I think
if we allow constexpr virtual bases, we can have constexpr span streams
in p0448.

Received on 2019-05-31 18:26:31