Skip to content

Default-initialized local static constexpr in constant evaluation [GH #399] - #417

Open
daveedvdv-nvidia wants to merge 1 commit into
mainfrom
fix/399
Open

daveedvdv-nvidia wants to merge 1 commit into
mainfrom
fix/399

Conversation

@daveedvdv-nvidia

@daveedvdv-nvidia daveedvdv-nvidia commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #399.

In C++23 mode, a local static constexpr variable is permitted in a constexpr function (P2647R1), and the stmk_decl case of the statement interpreter accepts it because it is usable in constant expressions. However, a default-initialized variable of class type also gets an stmk_init statement (for its constructor call), and the interpreter treated that like the initialization of an automatic variable: it tried to allocate interpreter storage for the static variable and to run its initializer, which failed.

The stmk_init case now skips variables with static or thread storage duration: their value is obtained (from their constant initializer) when they are referenced, as for any other variable usable in constant expressions.

Tests: new changes/gh-399.sft.cpp.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed a C++23 constant-evaluation failure involving default-initialized local static constexpr variables of class type. These variables are now evaluated correctly in functions with default member initializers, user-defined constexpr constructors, and templates, allowing valid constant expressions in these scenarios to compile successfully.

@daveedvdv-nvidia
daveedvdv-nvidia requested a review from a team October 28, 2026 14:41
@daveedvdv-nvidia daveedvdv-nvidia self-assigned this Oct 28, 2026
@coderabbitai

coderabbitai Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c0176e66-ad71-43ab-8db6-509ce87ba13a
Commits

Reviewing files that changed from the base of the PR and between a98c367 and b38ccbe.

Files selected for processing: 4
  • src/interpret.c
  • src/pending_changes/gh-399-default-initialized-local-static-constexpr.txt
  • tests/tests/changes/.gh-399.rto/default.1.1.txt
  • tests/tests/changes/gh-399.sft.cpp
Files skipped from review as they are similar to previous changes: 1

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

Walkthrough

The interpreter now skips allocation and initialization at stmk_init for variables with static or thread storage duration. A C++23 regression test covers default-initialized local static constexpr objects, and a pending-changes note describes GH #399.

Changes: C++23 static constexpr evaluation

Layer / File(s) Summary
Interpreter handling
src/interpret.c
stmk_init skips allocation and initialization for variables with static or thread storage duration.
GH #399 regression coverage
tests/tests/changes/gh-399.sft.cpp, tests/tests/changes/.gh-399.rto/default.1.1.txt, src/pending_changes/gh-399-default-initialized-local-static-constexpr.txt
The C++23 test checks default-initialized local static constexpr objects with a member initializer, a user-defined constructor, and a template. The fixture selects C++23 mode. The pending-changes note describes the reported issue and states it is fixed.

Priority: Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: nv-cmeerw

Merge Risk: Minimal · up to b38cc

No concrete merge-blocking defect was established in the changed interpreter logic or regression coverage.

Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the actual change: default-initialized local static constexpr variables during constant evaluation, with the linked issue GH #399. It matches the interpret.c change that skips stmk_ini…
Linked Issues check Passed Issue #399 requires C++23 constant evaluation for a default-initialized local static constexpr class object. The change skips stmk_init processing for variables with static or thread storage duration.…
Out of Scope Changes check Passed The source change directly addresses issue #399. The regression test and pending change note support that fix. The whole-pull-request diff contains no demonstrated unrelated changes.
Docstring Coverage Passed No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Full details: Title check

Explanation

The title names the actual change: default-initialized local static constexpr variables during constant evaluation, with the linked issue GH #399. It matches the interpret.c change that skips stmk_init handling for static or thread storage duration variables. It is specific enough for a teammate scanning history. Minor note: the title does not say that the fix skips allocation for static and thread storage variables, but it does not need to cover every detail.

Full details: Linked Issues check

Explanation

Issue #399 requires C++23 constant evaluation for a default-initialized local static constexpr class object. The change skips stmk_init processing for variables with static or thread storage duration. The existing reference evaluation can then obtain the constant-initialized value. tests/tests/changes/gh-399.sft.cpp directly covers the reported Q example and adds user-constructor and template cases.

Full details: Docstring Coverage

Explanation

No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 0 functions across 1 files. (3 skipped: 2 unsupported, 1 too large.)

Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@edgcpp-bot

Copy link
Copy Markdown
Collaborator

AcknowlEDG review results updated for ee2c0769afd0:

@edgcpp-bot

Copy link
Copy Markdown
Collaborator

AcknowlEDG review results updated for ee2c0769afd0:

CI success.

@codecov

codecov Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 50.00000% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/interpret.c 50.00% 0 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@edgcpp-bot

Copy link
Copy Markdown
Collaborator

AcknowlEDG review results updated for a98c3676ca8b:

@edgcpp-bot

Copy link
Copy Markdown
Collaborator

AcknowlEDG review results updated for a98c3676ca8b:

CI success.

This branch has not been deployed

No deployments
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.

C++23: default-initialized local static constexpr variable of class type prevents constant evaluation

2 participants