Skip to content

Pack expansions in nested generic-lambda template default arguments [GH #506] - #524

Merged
nv-cmeerw merged 1 commit into
mainfrom
fix/506
Nov 12, 2026
Merged

nv-cmeerw merged 1 commit into
mainfrom
fix/506

Conversation

@nv-cmeerw

@nv-cmeerw nv-cmeerw commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #506

A default template argument of a nested generic lambda could be rejected when a
pack expansion involving an enclosing pack was incorrectly treated as empty
before the lambda's template arguments were available. Such defaults now
remain dependent until instantiation. For example, with --c++20 -tused:

  template<int... Is> void f() {
    [](auto) {
      []<int... Js, typename U = int[((Js * Is) * ... * 1) - 2]>() {};
    };
  }
  template void f<2>();  // Previously a spurious array bound error, now okay.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed a C++20 compiler error affecting default template arguments in nested generic lambdas that reference parameter packs. These defaults now remain dependent until the relevant arguments are available.
  • Tests
    • Added regression coverage for empty and nonempty packs, different pack ordering, and defaults that are not instantiated.

@nv-cmeerw
nv-cmeerw requested a review from a team November 12, 2026 14:35
@coderabbitai

coderabbitai Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The compiler now checks whether referenced template parameter packs have corresponding arguments before enabling expansion in a generic-lambda instantiation context. C++20 regression tests cover nested lambda template defaults involving inner and outer packs.

Changes: Nested lambda template defaults

Layer / File(s) Summary
Pack binding check
src/scope_stk.c
The compiler checks referenced packs against current and enclosing template arguments before enabling expansion in a generic-lambda instantiation context.
Regression coverage
tests/tests/regressions/gh-506.sft.cpp, tests/tests/regressions/.gh-506.rto/*, src/pending_changes/gh-506.txt
The C++20 regression test covers defaults combining inner and outer packs, including empty packs, both pack orderings, and an uninstantiated default. Four test commands and a pending-change note are added.

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

Change: Bug fix · Severity of issue fixed: Low

Possibly related PRs

  • edgcpp/compiler#492: Both PRs change pack-expansion handling in src/scope_stk.c for nested generic lambdas and address related false errors.

Suggested labels: bug

Suggested reviewers: daveedvdv-nvidia

Merge Risk: Minimal · up to d942a

This change keeps default template arguments in nested generic lambdas dependent until the lambda is instantiated, which removes a spurious array-bound error. No concrete defect was established in review. The only remaining question is a narrow edge case that has not been shown to be reachable, and regression tests cover the reported scenario.

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: pack expansions in nested generic-lambda template default arguments, tied to GH #506. The raw summary and objectives confirm the change keeps such defaults dependent u…
Linked Issues check Passed Issue #506 requires that the reproducer compile with --c++20 -tused without the spurious array-bound error. The premature expansion comes from is_pack_instantiation_context in src/scope_stk.c. I…
Out of Scope Changes check Passed All changes connect to #506. The has_unbound_template_pack helper and the modified branch in src/scope_stk.c implement the fix. The src/pending_changes/gh-506.txt entry documents the fix. The `t…
Full details: Title check

Explanation

The title names the main change: pack expansions in nested generic-lambda template default arguments, tied to GH #506. The raw summary and objectives confirm the change keeps such defaults dependent until instantiation, so the title matches the changeset. The title uses a technical term and a bracketed issue reference, but it is specific and readable.

Full details: Linked Issues check

Explanation

Issue #506 requires that the reproducer compile with --c++20 -tused without the spurious array-bound error. The premature expansion comes from is_pack_instantiation_context in src/scope_stk.c. In the generic-lambda-in-real-instantiation branch, the previous code returned TRUE unconditionally when the expansion used enclosing packs. The head now returns !has_unbound_template_pack(pedp). The new helper returns TRUE when any referenced template-parameter pack (here the nested lambda's Js) has no argument available. For the reproducer, Js is unbound during the enclosing instantiation, so the expansion stays dependent until the lambda's template arguments exist. The added test tests/tests/regressions/gh-506.sft.cpp covers the reproducer shape in uninstantiated_template_parameter_default and related cases, and the .rto fixtures run it under -tused. Compliance rests on code reading. I did not run the compiler or the tests.

Full details: Out of Scope Changes check

Explanation

All changes connect to #506. The has_unbound_template_pack helper and the modified branch in src/scope_stk.c implement the fix. The src/pending_changes/gh-506.txt entry documents the fix. The tests/tests/regressions/gh-506.sft.cpp file and the .rto fixtures add regression coverage for the fix. The helper's doc comment and the updated comment in is_pack_instantiation_context are part of the same change. No unrelated functional change appears in the reviewed diff.

Finishing Touches

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 8fa21be and d942a42.

Files selected for processing: 7

  • src/pending_changes/gh-506.txt
  • src/scope_stk.c
  • tests/tests/regressions/.gh-506.rto/default.1.1.txt
  • tests/tests/regressions/.gh-506.rto/default.2.1.txt
  • tests/tests/regressions/.gh-506.rto/default.3.1.txt
  • tests/tests/regressions/.gh-506.rto/default.4.1.txt
  • tests/tests/regressions/gh-506.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.

@daveedvdv-nvidia daveedvdv-nvidia 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.

LGTM.

@edgcpp-bot

Copy link
Copy Markdown
Collaborator

AcknowlEDG review results updated for d942a42bc669:

CI success.

@nv-cmeerw
nv-cmeerw added this pull request to the merge queue Nov 12, 2026
Merged via the queue into main with commit f5dab52 Nov 12, 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.

Premature pack expansion in nested generic-lambda template default arguments

3 participants