Skip to content

fix uninitialized array in constexpr context (GCC 14)#669

Merged
kris-jusiak merged 1 commit into
boost-ext:masterfrom
PavelGuzenfeld:fix/constexpr-uninit-array
May 23, 2026
Merged

fix uninitialized array in constexpr context (GCC 14)#669
kris-jusiak merged 1 commit into
boost-ext:masterfrom
PavelGuzenfeld:fix/constexpr-uninit-array

Conversation

@PavelGuzenfeld
Copy link
Copy Markdown
Contributor

Problem

Two state_t old[regions] declarations in sm_impl::process_event and the deferred-event dispatch were uninitialized at the point of declaration. GCC 14 enforces that constexpr functions cannot contain uninitialized local variables, causing the constexpr_sm test to fail with:

error: uninitialized variable 'old' in 'constexpr' context
state_t old[regions];

Fix

Zero-initialize both occurrences with {}:

state_t old[regions]{};  // state_t is unsigned char or unsigned short

state_t is always an integer type (unsigned char or unsigned short), so {} gives correct zero-initialization with no overhead.

Also included

Adds issue_639_repro.cpp to the CMake test configuration with -ftemplate-depth=100, so the template depth regression test from issue #639 runs in CI (it was previously only present in the Makefile).

Closes the GCC 14 constexpr failure visible when running make test CXX=g++ CXXSTD=c++17 locally.

state_t old[regions] was declared without initialization, which is invalid
in a constexpr function under GCC 14's stricter enforcement. Zero-initialize
both occurrences with {} — state_t is an integer type so this is correct
and efficient.

Also add issue_639_repro to the CMake test list with -ftemplate-depth=100
so the template depth regression test runs in CI (previously only in Make).
@kris-jusiak kris-jusiak merged commit c1f533c into boost-ext:master May 23, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants