AnthonyCalandra / modern-cpp-features

A cheatsheet of modern C++ language and library features.
MIT License
19.77k stars 2.09k forks source link

CPP20 constinit: `g` is not constexpr typo #134

Closed jonathanbcarlson closed 3 months ago

jonathanbcarlson commented 4 months ago

In the constinit example in CPP20.md:

const char* g() { return "dynamic initialization"; }
constexpr const char* f(bool p) { return p ? "constant initializer" : g(); }

constinit const char* c = f(true); // OK
constinit const char* d = f(false); // ERROR: `g` is not constexpr, so `d` cannot be evaluated at compile-time.

it has d = f(false) when it should be d = g(false).

Thanks for all the work on this wonderful cheatsheet!

AnthonyCalandra commented 3 months ago

Thanks for the bug report! Done