Skip to content

Spurious error for pack expansions in nested generic lambdas [GH #491] - #492

Open
nv-cmeerw wants to merge 1 commit into
mainfrom
fix/491
Open

nv-cmeerw wants to merge 1 commit into
mainfrom
fix/491

Conversation

@nv-cmeerw

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

Copy link
Copy Markdown
Contributor

Fixes #491

Previously, valid pack expansions, sizeof... operands, and fold expressions in
nested generic lambdas (for example, in default arguments or exception
specifications) could be rejected during instantiation with spurious missing
parameter pack errors. For example, with --c++14 -tused:

  int f() {
    auto g = [](auto... x) {
      return [](auto, int n = sizeof...(x)) { return n; }(0);
    };
    return g(1, 2);  // Previously a spurious error, now okay.
  }

Summary by CodeRabbit

  • Bug Fixes

    • Fixed spurious parameter-pack errors in nested generic lambdas, including pack expansions, sizeof..., default arguments, and fold expressions.
    • Valid pack-related code is no longer incorrectly rejected during instantiation.
  • Tests

    • Added regression coverage across C++ language versions and updated expected compiler diagnostics.

@nv-cmeerw
nv-cmeerw requested a review from a team November 6, 2026 14:29
@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 tracks pack expansions recorded by earlier scans in nested generic-lambda contexts. This state affects pack-reference checks and diagnostic handling. New regression tests cover default arguments, pack expansions, exception specifications, and fold expressions. Existing expected diagnostic outputs are updated.

Changes: Nested generic-lambda pack handling

Layer / File(s) Summary
Record pack expansion state
src/scope_stk.h, src/scope_stk.c, src/pending_changes/gh-491.txt
The pack-expansion stack entry gains a recorded_pack_expansion flag. Applicable scans set it, and the changelog describes the nested-lambda cases.
Apply recorded expansion state
src/scope_stk.c, src/expr.c
Current-context checks recognize previously recorded expansions. The compiler skips related no-packs and non-pack identifier diagnostics when an earlier scan recorded an expansion.
Add regression coverage
tests/tests/changes/*, tests/tests/regressions/*
New tests cover nested-lambda default arguments, pack expansions, exception specifications, and fold expressions. Test configurations select multiple language modes and compiler settings.
Refresh diagnostic baselines
tests/tests/imported/clang/cpp/SemaCXX/.cxx1y-generic-lambdas.rto/*, tests/tests/imported/clang/cpp/SemaTemplate/.generic-lambda.rto/*
Expected outputs remove pack-expansion and sizeof... diagnostics. They retain unrelated conversion diagnostics and update compilation error totals.

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

Change: Bug fix · Severity of issue fixed: Medium

Suggested labels: bug

Suggested reviewers: wchilders-nvidia, darkarc

Merge Risk: Low · up to 1fae0

This change fixes spurious pack-expansion errors in nested generic lambdas. The new suppression logic could in rare cases hide a real diagnostic, or yield a wrong sizeof... value on a rescan. Neither case is confirmed. The change is mergeable, but the owner should consider adding a test that checks the returned sizeof... value.

Pre-merge checks: Passed 3 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Linked Issues check Inconclusive [#491] The pack-expansion stack records earlier expansions and suppresses spurious no-pack diagnostics. Regression tests cover nested-lambda default arguments, exception specifications, and fold expre… Provide reviewable test results or code evidence for the second issue reproducer with --c++20 -tused in linux-gcc-debug.
Passed Passed checks: 3 passed

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly describes the fix for spurious pack-expansion errors in nested generic lambdas.
Out of Scope Changes check Passed [#491] The compiler changes address recorded pack expansions. The regression tests, diagnostic baselines, and changelog support that fix. No unrelated change is evident in the reviewable summary.
Full details: Linked Issues check

Explanation

[#491] The pack-expansion stack records earlier expansions and suppresses spurious no-pack diagnostics. Regression tests cover nested-lambda default arguments, exception specifications, and fold expressions. The supplied evidence does not establish whether the issue's g(decltype(x){}...) default-argument example compiles with --c++20 -tused in linux-gcc-debug. The C++20 regression fixture uses Microsoft mode.

Resolution

Provide reviewable test results or code evidence for the second issue reproducer with --c++20 -tused in linux-gcc-debug.

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 6972d17 and 1fae051.

Files ignored due to path filters: 1

  • tests/expectations/edg_x86_64/imported.log is excluded by !**/*.log
Files selected for processing: 29

  • src/expr.c
  • src/pending_changes/gh-491.txt
  • src/scope_stk.c
  • src/scope_stk.h
  • tests/tests/changes/.gh-491.rto/default.1.1.txt
  • tests/tests/changes/gh-491.sft.cpp
  • tests/tests/imported/clang/cpp/SemaCXX/.cxx1y-generic-lambdas.rto/default.1.1.txt
  • tests/tests/imported/clang/cpp/SemaCXX/.cxx1y-generic-lambdas.rto/default.2.1.txt
  • tests/tests/imported/clang/cpp/SemaCXX/.cxx1y-generic-lambdas.rto/default.3.1.txt
  • tests/tests/imported/clang/cpp/SemaCXX/.cxx1y-generic-lambdas.rto/default.4.1.txt
  • tests/tests/imported/clang/cpp/SemaCXX/.cxx1y-generic-lambdas.rto/default.5.1.txt
  • tests/tests/imported/clang/cpp/SemaCXX/.cxx1y-generic-lambdas.rto/default.6.1.txt
  • tests/tests/imported/clang/cpp/SemaCXX/.cxx1y-generic-lambdas.rto/default.7.1.txt
  • tests/tests/imported/clang/cpp/SemaCXX/.cxx1y-generic-lambdas.rto/default.8.1.txt
  • tests/tests/imported/clang/cpp/SemaCXX/.cxx1y-generic-lambdas.rto/edg_x86_32_cp.1.1.txt
  • tests/tests/imported/clang/cpp/SemaCXX/.cxx1y-generic-lambdas.rto/edg_x86_32_cp.2.1.txt
  • tests/tests/imported/clang/cpp/SemaCXX/.cxx1y-generic-lambdas.rto/edg_x86_32_cp.3.1.txt
  • tests/tests/imported/clang/cpp/SemaCXX/.cxx1y-generic-lambdas.rto/edg_x86_32_cp.4.1.txt
  • tests/tests/imported/clang/cpp/SemaCXX/.cxx1y-generic-lambdas.rto/edg_x86_64_cp.1.1.txt
  • tests/tests/imported/clang/cpp/SemaCXX/.cxx1y-generic-lambdas.rto/edg_x86_64_cp.2.1.txt
  • tests/tests/imported/clang/cpp/SemaCXX/.cxx1y-generic-lambdas.rto/edg_x86_64_cp.3.1.txt
  • tests/tests/imported/clang/cpp/SemaCXX/.cxx1y-generic-lambdas.rto/edg_x86_64_cp.4.1.txt
  • tests/tests/imported/clang/cpp/SemaTemplate/.generic-lambda.rto/default.1.1.txt
  • tests/tests/regressions/.gh-491.rto/default.1.1.txt
  • tests/tests/regressions/.gh-491.rto/default.2.1.txt
  • tests/tests/regressions/.gh-491.rto/default.3.1.txt
  • tests/tests/regressions/.gh-491.rto/default.4.1.txt
  • tests/tests/regressions/.gh-491.rto/default.5.1.txt
  • tests/tests/regressions/gh-491.sft.cpp
Files with no reviewable changes: 1

  • tests/tests/imported/clang/cpp/SemaTemplate/.generic-lambda.rto/default.1.1.txt
Files skipped from review as they are similar to previous changes: 1

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.

Looks great to me.

@daveedvdv-nvidia
daveedvdv-nvidia dismissed their stale review November 6, 2026 16:07

CI tests failed.

@edgcpp-bot

Copy link
Copy Markdown
Collaborator

AcknowlEDG review results updated for 6972d17d72fc:

@edgcpp-bot

Copy link
Copy Markdown
Collaborator

AcknowlEDG review results updated for 6972d17d72fc:

CI failure.

@edgcpp-bot

Copy link
Copy Markdown
Collaborator

AcknowlEDG review results updated for 1fae051e9af0:

@edgcpp-bot

Copy link
Copy Markdown
Collaborator

AcknowlEDG review results updated for 1fae051e9af0:

CI success.

This branch has not been deployed

No deployments
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.

Spurious missing-parameter-pack errors in nested generic lambdas

3 participants