Skip to content

Template parameter objects of enclosing templates in member template signatures [GH #423] - #464

Merged
daveedvdv-nvidia merged 1 commit into
mainfrom
fix/423
Nov 3, 2026
Merged

daveedvdv-nvidia merged 1 commit into
mainfrom
fix/423

Conversation

@daveedvdv-nvidia

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

Copy link
Copy Markdown
Contributor

Fixes #423.

When an enclosing template is instantiated, a reference to one of its class-type nontype template parameters in the signature of a member template (or of a generic lambda) is replaced by the template parameter object. When the member template's own arguments were then substituted, make_operand_for_rescanned_identifier rebuilt that reference with make_constant_operand, i.e., as a prvalue rather than a const lvalue. Taking its address therefore made deduction fail (the examples in the issue), and other uses produced a function type inconsistent with that of the template:

struct NoConst { int operator()() { return 0; } };
template <auto F> struct S {
  template <typename T> static auto g(T t) -> decltype(t, F);
};
using R = decltype(S<NoConst{}>::g(0));
// Previously: "template instantiation resulted in unexpected function type
// of "auto (int)->const NoConst &"".

The part of make_template_param_object_operand that builds the const lvalue operand for a template parameter object is now a separate function, make_template_param_object_variable_operand, which the rescan uses instead.

Summary by CodeRabbit

  • Bug Fixes
    • Corrected handling of class-type non-type template parameters in member-template and generic-lambda signatures. Address-taking, member access, and template argument deduction now work as expected in these cases.
    • Added regression coverage across C++20 compiler configurations to verify consistent behavior.

@daveedvdv-nvidia
daveedvdv-nvidia requested a review from a team November 3, 2026 00:33
@coderabbitai

coderabbitai Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between cc40804 and 7b8ac81.

Files selected for processing: 9
  • src/expr.c
  • src/exprutil.c
  • src/exprutil.h
  • src/pending_changes/gh-423-template-param-object-member-template.txt
  • tests/tests/regressions/.gh-423.rto/default.1.1.txt
  • tests/tests/regressions/.gh-423.rto/default.2.1.txt
  • tests/tests/regressions/.gh-423.rto/default.3.1.txt
  • tests/tests/regressions/.gh-423.rto/default.4.1.txt
  • tests/tests/regressions/gh-423.sft.cpp

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

Walkthrough

The rescan fallback now creates an operand from a template parameter object variable instead of creating a constant operand. A regression test covers member-template and generic-lambda signatures that use class-type non-type template parameters.

Changes: Template parameter object rescanning

Layer / File(s) Summary
Build operands from template parameter object variables
src/expr.c, src/exprutil.c, src/exprutil.h
The rescan fallback calls the new variable-based operand helper. The existing operand function delegates operand construction to that helper.
Cover member-template and lambda signatures
tests/tests/regressions/gh-423.sft.cpp, tests/tests/regressions/.gh-423.rto/*, src/pending_changes/gh-423-template-param-object-member-template.txt
The C++20 regression test checks member-template, generic-lambda, partial-specialization, and deduced-parameter cases. Runner fixtures specify C++20 compiler modes, and the pending-change entry describes the reported failures.

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

Change: Bug fix · Severity of issue fixed: Medium

Possibly related PRs

  • edgcpp/compiler#422: Both changes handle class-type non-type template parameters in signatures; this PR extends operand handling to rescanned enclosing-template references.
  • edgcpp/compiler#435: Both changes address rescans of template and lambda signatures that refer to enclosing template parameters.
  • edgcpp/compiler#339: Both changes cover lambda rescans involving enclosing template parameters.

Suggested labels: bug

Suggested reviewers: wchilders-nvidia, darkarc

Merge Risk: Minimal · up to 7b8ac

No actionable current-head defect remains from the reviewed changes.

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 names the main change: class-type non-type template parameter objects from enclosing templates, as referenced in member template signatures, and it cites the GH #423 issue. The raw summary a…
Linked Issues check Passed Issue #423 requires class-type NTTP references in enclosing-template member-template and generic-lambda signatures to remain const lvalues during substitution. src/expr.c now calls `make_template_pa…
Out of Scope Changes check Passed The changes stay within issue #423. The source changes extract and reuse template-parameter-object operand construction. The added pending-change note, regression source, and regression runner entries…
Full details: Title check

Explanation

The title names the main change: class-type non-type template parameter objects from enclosing templates, as referenced in member template signatures, and it cites the GH #423 issue. The raw summary and objectives confirm the change adds a variable-operand helper and corrects rescanning so these references are no longer rebuilt as prvalues. The title is specific and on-topic, so it passes.

Full details: Linked Issues check

Explanation

Issue #423 requires class-type NTTP references in enclosing-template member-template and generic-lambda signatures to remain const lvalues during substitution. src/expr.c now calls make_template_param_object_variable_operand during rescanning. src/exprutil.c constructs the const lvalue operand. The regression test tests/tests/regressions/gh-423.sft.cpp covers address-taking deduction, a generic lambda, a partial specialization, member access, and the reported auto NTTP case. The test includes compile-time type and value assertions for C++20 compiler modes.

Full details: Out of Scope Changes check

Explanation

The changes stay within issue #423. The source changes extract and reuse template-parameter-object operand construction. The added pending-change note, regression source, and regression runner entries document and test the same behavior. No unrelated product behavior or unrelated files appear in the reviewed diff.

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

codecov Bot commented Nov 3, 2026

Copy link
Copy Markdown

Codecov Report

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

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

📢 Thoughts on this report? Let us know!

@nv-cmeerw nv-cmeerw left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

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

Address of class-type NTTP in a member template signature fails deduction after enclosing template is instantiated

2 participants