[BUG] Cannot emit static constexpr
function local variables
#1093
Labels
bug
Something isn't working
Describe the bug
I can't find a Cpp2 syntax to emit a
static constexpr
local variable.static constexpr
variables are useful (particularly in debug/non-optimised builds) for look-up tables in a function where you want the data initialised once and also prefer to keep the variable close to its use in the function, rather than declaring it globally.See:
constexpr
(And Use This [static constexpr] Instead!)To Reproduce
Run cppfront on this code:
It lowers to:
which produces a C++ compiler error:
Repro on Godbolt
Why
static constexpr
Here's a C++ example demonstrating why
static constexpr
is useful:Side-by-side repro on Godbolt
With
static constexpr
MSVC Release `/O2`
MSVC Debug `/Od`
Without
static constexpr
MSVC Release `/O2`
MSVC Debug `/Od`
The text was updated successfully, but these errors were encountered: