Repository navigation
decltype of template parameters in requires-expression parameter types [GH #462] - #463
daveedvdv-nvidia wants to merge 1 commit into
Conversation
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Template deduction context src/declarator.c |
When requires-expression parameters occur in a template-dependent context, the prototype scope is marked as being in template deduction context. |
Operand rescanning and regression coverage src/exprutil.c, tests/tests/regressions/gh-462.sft.cpp, tests/tests/regressions/.gh-462.rto/*, src/pending_changes/gh-462-requires-expr-param-decltype.txt |
Rescanning preserves lvalue category and identifier details for the affected template-parameter expressions. Regression tests cover parameter types and contexts; the release note describes the reported cases. |
Estimated code review effort: 3 (Moderate) | ~20 minutes
Change: Bug fix
Possibly related issues
- Address of class-type NTTP in a member template signature fails deduction after enclosing template is instantiated #423: The issue concerns lvalue reconstruction for a class-type non-type template parameter during rescanning, which is related to the rescan changes here.
Possibly related PRs
- edgcpp/compiler#422: It changes rescanning for class-type non-type template parameters, sharing the rescan path modified in this PR.
Suggested labels: bug
Suggested reviewers: wchilders-nvidia, darkarc
Merge Risk: 
Minimal · up to 946de
-
The change targets requires-expression decltype handling. No concrete merge-blocking risk was identified.
Pre-merge checks: 
4
-
Full details: Linked Issues check
-
Explanation
Issue
#462requires unparenthesizeddecltype(F)for a class-type non-type template parameter to produce the declared non-const type in a requires-expression parameter, sof()is valid.src/declarator.crecords template deduction context for requires-expression parameter scopes.src/exprutil.cpreserves the lvalue and id-expression information during rescanning.tests/tests/regressions/gh-462.sft.cppverifies callable behavior, exact type, parenthesized behavior, references, pointers, function templates, class members, out-of-class members, and concepts. The regression commands cover C++20 and the listed compiler modes.
Full details: Out of Scope Changes check
-
Explanation
The changes stay within issue
#462. The source changes implement requires-expression substitution and template-parameter rescanning. The release note documents the fix. The added regression fixture and four test configurations verify the reported behavior and related cases. No unrelated product behavior or unrelated public entity changes are present.
-
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
CodeRabbit Verify
- Run CodeRabbit Verify to test the changes in this pull request.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Fixes #462.
The parameter declarations of a requires-expression are parsed before the requirements, and unlike the requirements, they were not treated as being in a template deduction context. So the information needed to substitute
decltypeapplied to a template parameter in a parameter type wasn't recorded, and the substituted parameter got an error type. Any requirement that used the parameter in an operation was then considered unsatisfied:This only worked in a concept definition, whose parameter scope inherits the flag from the enclosing template declaration.
function_declaratornow sets that flag on the prototype scope of a requires-expression's parameters in a template-dependent context.A second problem showed up in member templates of a class template (e.g.,
template <auto F> struct S { template <int I> static constexpr bool m() { return requires(decltype(F) f) { f(); }; } };). WhenS<NoConst{}>is instantiated,Fis still a template parameter of class type. Rescanning the reference stripped the implicit lvalue node that marks it as an id-expression, so whenm<1>was instantiated,decltype(F)gaveconst NoConst &(the type of the template parameter object) instead ofNoConst.make_rescan_operand_fullnow rebuilds that lvalue node and restores the id-expression details, as is already done for template parameter objects (#422).Summary by CodeRabbit
decltyperesults for parameters in requires-expressions, including class-type non-type template parameters. Requirements using these types now evaluate correctly across template contexts.