Skip to content

Keep C++11 constexpr templates usable after non-return statement warning [GH #356] - #407

Merged
daveedvdv-nvidia merged 1 commit into
mainfrom
fix/356
Oct 27, 2026
Merged

daveedvdv-nvidia merged 1 commit into
mainfrom
fix/356

Conversation

@daveedvdv-nvidia

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

Copy link
Copy Markdown
Contributor

Fixes #356.

When a statement that is not permitted in a C++11 constexpr function or constructor is accepted with a warning (for example, in a function or constructor template in some GNU or Clang C++11 modes), statement() in src/statements.c previously still set constexpr_ruled_out = TRUE unconditionally. As a result, the routine was marked as unusable in constant expressions.

Only set constexpr_ruled_out = TRUE for an explicitly constexpr/consteval routine when is_effective_error(err_code, in_constexpr_body_sev, &start_pos) is TRUE (matching check_void_return_okay), so routines accepted with a warning remain eligible for constant evaluation.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed constant evaluation in GNU and Clang C++11 modes when a constexpr template or constructor contains a statement that triggers a warning. Such expressions can now be used in constant evaluation, including in static assertions and template arguments.
    • Diagnostics reported as errors still prevent the affected constexpr function or constructor from being used in constant evaluation.

@coderabbitai

coderabbitai Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Caution

Review failed

The pull request is closed.

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: 20a59e80-246c-4752-bdb9-aa37a8f2a48d
Commits

Reviewing files that changed from the base of the PR and between 35b7c47 and b8bbe31.

Files selected for processing: 5
  • src/pending_changes/gh-356-cpp14-constexpr-func-in-cpp11.chng.txt
  • src/statements.c
  • tests/tests/regressions/.gh-356.rto/default.1.1.txt
  • tests/tests/regressions/.gh-356.rto/default.2.1.txt
  • tests/tests/regressions/gh-356.sft.cpp

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 constexpr-body diagnostic now sets constexpr_ruled_out only when it is an effective error for declared constexpr or consteval functions. A C++11 regression test and expected outputs cover constexpr templates that receive warnings.

Changes: C++11 constexpr warning handling

Layer / File(s) Summary
Condition constexpr exclusion on diagnostic severity
src/statements.c
The selected constexpr-body diagnostic code is reported, and declared constexpr or consteval functions are ruled out only when the diagnostic is an effective error.
Test warning cases and record behavior
tests/tests/regressions/gh-356.sft.cpp, tests/tests/regressions/.gh-356.rto/*, src/pending_changes/gh-356-cpp14-constexpr-func-in-cpp11.chng.txt
The C++11 regression test checks constexpr construction, template argument evaluation, and function evaluation. Expected outputs record the warnings, and the changelog describes the behavior.

Priority: Normal

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

Change: Bug fix · Severity of issue fixed: Medium

Possibly related PRs

  • edgcpp/compiler#386: Both PRs address GH #356 in statement() and constexpr evaluation of C++11 templates.

Suggested labels: bug

Suggested reviewers: nv-cmeerw

Merge Risk: Minimal · previous review b8bbe

The change is ready to merge; normal execution of the added regression test remains appropriate validation.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within survi… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the primary change: C++11 constexpr templates stay usable after a non-return statement warning, which matches the statements.c change and the GH #356 changelog, test, and regression fi…
Linked Issues check Passed Issue #356 requires that a C++11 constexpr constructor or function template, accepted with a warning for a C++14-style statement in GNU 120000+ or Clang 30300+ mode, remain usable in constant expressi…
Out of Scope Changes check Passed All changes support issue #356. The src/statements.c hunk implements the required conditional constexpr_ruled_out logic. It also moves the err_code selection into a local variable so that the same cod…
Full details: Title check

Explanation

The title names the primary change: C++11 constexpr templates stay usable after a non-return statement warning, which matches the statements.c change and the GH #356 changelog, test, and regression files. It also names the issue, so a reviewer scanning history can identify the fix.

Full details: Linked Issues check

Explanation

Issue #356 requires that a C++11 constexpr constructor or function template, accepted with a warning for a C++14-style statement in GNU 120000+ or Clang 30300+ mode, remain usable in constant expressions. The diff in src/statements.c (statement()) changes the constexpr-body path. It now sets constexpr_ruled_out = TRUE for a declared constexpr or consteval routine only when is_effective_error(err_code, in_constexpr_body_sev, &start_pos) is TRUE. When the diagnostic is downgraded to es_warning, the routine stays eligible for constant evaluation. The constructor case is covered because err_code is selected with special_kind_is(current_rp, sfk_constructor). The added regression test tests/tests/regressions/gh-356.sft.cpp uses the issue's constructor-template pattern (A<int> a(5); static_assert(a.x == 5, "");) with the GNU 150000 and Clang 190000 options. It also covers a constexpr function template (f(41) == 42) and a template-argument use. Non-declared constexpr routines keep the previous unconditional ruled-out behavior through the else branch. The issue's objective is implemented by the code change. Test results were not executed in this review. The is_effective_error declaration was not inspected; its use mirrors check_void_return_okay as stated in the PR description.

Full details: Out of Scope Changes check

Explanation

All changes support issue #356. The src/statements.c hunk implements the required conditional constexpr_ruled_out logic. It also moves the err_code selection into a local variable so that the same code is reused for both pos_diagnostic and is_effective_error. The new regression test and its .rto expected-output files exercise the reported scenario. The changelog entry src/pending_changes/gh-356-cpp14-constexpr-func-in-cpp11.chng.txt documents the fix. No unrelated source or behavior change was found in the reviewed diff. The one behavioral side effect is that uninstantiated prototype or template routines whose diagnostic is downgraded to a warning are no longer ruled out. This follows directly from the issue's warning-to-eligibility requirement.

Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 3 functions across 2 files. (3 skipped: 3 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

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 b8bbe31f5c9d:

@edgcpp-bot

Copy link
Copy Markdown
Collaborator

AcknowlEDG review results updated for b8bbe31f5c9d:

CI success.

@codecov

codecov Bot commented Oct 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@daveedvdv-nvidia
daveedvdv-nvidia merged commit e5cb7da into main Oct 27, 2026
12 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.

C++11 constexpr function/constructor using C++14 statement extensions is excluded from constant evaluation

3 participants