You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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.
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.
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.
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: 4
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
The title clearly describes the main change: accepting template-dependent variable template-ids in C++03 constant expressions.
Linked Issues check
[ #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
[ #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.
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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-489covers the accepted cases (including a member variable template) in GNU C++03, Clang C++03, and GNU C++11.regressions/gh-489-negcovers the non-constant case.Fixes #489
Summary by CodeRabbit
Bug Fixes
Tests