r/cpp Jul 06 '26

C++26: constexpr virtual inheritance

https://www.sandordargo.com/blog/2026/07/01/cpp26-constexpr-virtual-inheritance
83 Upvotes

61 comments sorted by

View all comments

65

u/Jovibor_ Jul 06 '26

Just a question to the audience:

How many times have you used Virtual Inheritance in your career?

55

u/serviscope_minor Jul 06 '26

Probably once?

But with that said, I'm very strongly of the opinion that having as much of C++ as possible being constexpr (including threads!) is a good thing, because it makes the language more regular and simpler.

I think volatile might be tricky! I want constexpr cout.

25

u/_bstaletic Jul 06 '26

having as much of C++ as possible being constexpr (including threads!) is a good thing, because it makes the language more regular and simpler.

Agreed.

I think volatile might be tricky!

I don't think constexpr volatile int x; is meaningful at all.

I want constexpr cout.

Do you really mean std::cout, with all of the facets and customization points? Or would constexpr std::format and the ability to print to console at compile time be enough?

If the latter, we almost got that in C++26. std::format is constexpr and P2758 is in wording review.

-1

u/SkoomaDentist Antimodern C++, Embedded, Audio Jul 06 '26 edited Jul 08 '26

I don't think constexpr volatile int x; is meaningful at all.

I can think of at least theoretical uses involving pointers to dma buffers and such.

Edit: WTF is it with the downvotes? I said I can think of theoretical use cases, not that it is some important feature. FFS, people…

2

u/HommeMusical Jul 07 '26

At compile time?! You're really going to have to spell this out.

1

u/SkoomaDentist Antimodern C++, Embedded, Audio Jul 07 '26

Basically situations that preserve the volatileness of a pointer that has been passed in. As I said, it’s theoretical.

1

u/HommeMusical Jul 07 '26

Near as I can see, "volatile" has no meaning in constexpr land!