Skip to content

Accept template-dependent variable template-ids in C++03 constant expressions [GH #489] - #493

Merged
daveedvdv-nvidia merged 1 commit into
mainfrom
fix/489
Nov 6, 2026
Merged

daveedvdv-nvidia merged 1 commit into
mainfrom
fix/489

Conversation

@daveedvdv-nvidia

@daveedvdv-nvidia daveedvdv-nvidia commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

In C++03 GNU and Clang modes, variable templates are accepted as an extension. A variable template-id with template-dependent arguments was rejected as nonconstant wherever a constant expression is required (a template argument, an array bound, an enumerator value, and so on). The value is not known until instantiation, so the reference should be accepted in the template definition and checked when the template is instantiated, as a dependent static data member already is.

In var_constant_value_full, a reference to a constant variable template with dependent template arguments is now treated as a template-dependent constant in pre-C++11 mode. A variable template that is not itself constant is still diagnosed when the enclosing template is instantiated.

regressions/gh-489 covers the accepted cases (including a member variable template) in GNU C++03, Clang C++03, and GNU C++11. regressions/gh-489-neg covers the non-constant case.

Fixes #489

Summary by CodeRabbit

  • Bug Fixes

    • Fixed handling of template-dependent variable-template values in constant-expression contexts, including template arguments, array bounds, and enum initializers.
    • Non-constant variable-template values are correctly rejected when used where a constant expression is required.
  • Tests

    • Added regression coverage for GNU and Clang in legacy C++ modes, including checks for both valid constant expressions and invalid non-constant values.

@daveedvdv-nvidia
daveedvdv-nvidia requested a review from a team November 6, 2026 15:58
@daveedvdv-nvidia daveedvdv-nvidia self-assigned this Nov 6, 2026
@coderabbitai

coderabbitai Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The compiler now treats qualifying dependent variable-template instances as template-parameter constants when constexpr is disabled. New regression cases cover constant-expression uses and verify that non-constant values produce errors during template instantiation.

Changes: Dependent variable-template constants

Layer / File(s) Summary
Regression cases
src/pending_changes/gh-489-var-tmpl-const.txt, tests/tests/regressions/gh-489*.sft.cpp, tests/tests/regressions/.gh-489*.rto/*
Regression tests cover dependent variable-template values in constant-expression contexts, including template arguments, array bounds, enum initializers, and a static member variable template. Negative cases check that a non-constant value is rejected during instantiation. Expected outputs record compiler diagnostics across configured modes.
Constant classification
src/exprutil.c
For a nonreal variable-template instance with template arguments and no initializer, the compiler creates a template-parameter constant from its rvalue expression when constexpr is disabled. The g++ nonreal-class check also compares init_kind directly with initk_none.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Low

Suggested labels: bug

Suggested reviewers: nv-cmeerw, darkarc

Merge Risk: Minimal · up to 0860c

The change accepts dependent constant variable templates in C++03 constant expressions and still diagnoses non-constant ones at instantiation. No actionable merge-blocking risk remains.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly describes the main change: accepting template-dependent variable template-ids in C++03 constant expressions.
Linked Issues check Passed [ #489 ] var_constant_value_full treats dependent variable template instances as template-dependent constants in pre-C++11 mode. Regression tests cover GNU and Clang C++03, GNU C++11, template argum…
Out of Scope Changes check Passed [ #489 ] The implementation, regression tests, expected diagnostics, and pending-change note support the linked issue. No unrelated change is evident in the whole-PR summary.
Full details: Linked Issues check

Explanation

[ #489 ] var_constant_value_full treats dependent variable template instances as template-dependent constants in pre-C++11 mode. Regression tests cover GNU and Clang C++03, GNU C++11, template arguments, array bounds, enum values, and member variable templates. A negative test checks that a non-constant variable template is rejected at instantiation.

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

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between ab072d3 and 0860ccb.

Files selected for processing: 10

  • src/exprutil.c
  • src/pending_changes/gh-489-var-tmpl-const.txt
  • tests/tests/regressions/.gh-489-neg.rto/default.1.1.txt
  • tests/tests/regressions/.gh-489-neg.rto/default.2.1.txt
  • tests/tests/regressions/.gh-489-neg.rto/default.3.1.txt
  • tests/tests/regressions/.gh-489.rto/default.1.1.txt
  • tests/tests/regressions/.gh-489.rto/default.2.1.txt
  • tests/tests/regressions/.gh-489.rto/default.3.1.txt
  • tests/tests/regressions/gh-489-neg.sft.cpp
  • tests/tests/regressions/gh-489.sft.cpp

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

@edgcpp-bot

Copy link
Copy Markdown
Collaborator

AcknowlEDG review results updated for 0860ccbd0c13:

@edgcpp-bot

Copy link
Copy Markdown
Collaborator

AcknowlEDG review results updated for 0860ccbd0c13:

CI success.

@daveedvdv-nvidia
daveedvdv-nvidia added this pull request to the merge queue Nov 6, 2026
Merged via the queue into main with commit 3c88dad Nov 6, 2026
23 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.

Template-dependent variable template-id rejected as nonconstant in C++03 mode

3 participants