Skip to content

Allow lambdas to name template parameters from function decl [GH #338] - #339

Open
mborland wants to merge 3 commits into
edgcpp:mainfrom
mborland:0020
Open

mborland wants to merge 3 commits into
edgcpp:mainfrom
mborland:0020

Conversation

@mborland

@mborland mborland commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

This PR enable lambda to name template parameters from template function declaration such in the case of:

template <class T>
  void f(char (*)[sizeof([](T y) { return y; }(T{}))]) {}
  void g() { char a[4]; f<int>(&a); }  // Was an error: identifier "T" is undefined

Closes: #338

Summary by CodeRabbit

  • Bug Fixes

    • Lambdas in function-template declarations can now use function-template parameters during substitution and rescanning, including in enable_if conditions.
    • Improved overload resolution for affected templates when lambda expressions reference template parameters.
    • Generic lambdas, lambdas with their own template parameters, and references to template parameter packs remain unsupported in this context.
  • Tests

    • Added coverage across C++20 and C++23 for supported cases and documented boundaries.

@mborland mborland self-assigned this Oct 21, 2026
@mborland mborland added the bug Something isn't working label Oct 21, 2026
@mborland mborland removed their assignment Oct 21, 2026
@edgcpp-bot

Copy link
Copy Markdown
Collaborator

AcknowlEDG review results updated for 86215d0800f6:

@edgcpp-bot

Copy link
Copy Markdown
Collaborator

AcknowlEDG review results updated for 86215d0800f6:

CI success.

Comment thread src/Changes
Comment thread src/il.c Outdated
Comment thread src/il.c Outdated
@mborland
mborland requested a review from nv-cmeerw October 22, 2026 16:06
@coderabbitai

coderabbitai Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 1213afa0-cf8a-46d8-8cbd-68cc496f6de5
📥 Commits

Reviewing files that changed from the base of the PR and between 8360528 and 4cb3ad5.

⛔ Files ignored due to path filters: 1
  • tests/expectations/edg_x86_64/imported.log is excluded by !**/*.log
📒 Files selected for processing: 51
  • src/Changes
  • src/il.c
  • src/overload.c
  • tests/tests/changes/.gh-338-lambda-template-param-enable-if.rto/default.1.1.txt
  • tests/tests/changes/.gh-338-lambda-template-param-enable-if.rto/default.2.1.txt
  • tests/tests/changes/.gh-338-lambda-template-param-generic.rto/default.1.1.txt
  • tests/tests/changes/.gh-338-lambda-template-param-generic.rto/default.1.matches.txt
  • tests/tests/changes/.gh-338-lambda-template-param-gnu.rto/default.1.1.txt
  • tests/tests/changes/.gh-338-lambda-template-param-gnu.rto/default.1.matches.txt
  • tests/tests/changes/.gh-338-lambda-template-param-incomplete.rto/default.1.1.txt
  • tests/tests/changes/.gh-338-lambda-template-param-incomplete.rto/default.1.matches.txt
  • tests/tests/changes/.gh-338-lambda-template-param-limits.rto/default.1.1.txt
  • tests/tests/changes/.gh-338-lambda-template-param-limits.rto/default.1.matches.txt
  • tests/tests/changes/.gh-338-lambda-template-param-limits.rto/default.2.1.txt
  • tests/tests/changes/.gh-338-lambda-template-param-limits.rto/default.2.matches.txt
  • tests/tests/changes/.gh-338-lambda-template-param-limits.rto/default.3.1.txt
  • tests/tests/changes/.gh-338-lambda-template-param-limits.rto/default.3.matches.txt
  • tests/tests/changes/.gh-338-lambda-template-param-limits.rto/default.4.1.txt
  • tests/tests/changes/.gh-338-lambda-template-param-limits.rto/default.4.matches.txt
  • tests/tests/changes/.gh-338-lambda-template-param-mismatch.rto/default.1.1.txt
  • tests/tests/changes/.gh-338-lambda-template-param-mismatch.rto/default.1.matches.txt
  • tests/tests/changes/.gh-338-lambda-template-param-outer.rto/default.1.1.txt
  • tests/tests/changes/.gh-338-lambda-template-param-outer.rto/default.1.matches.txt
  • tests/tests/changes/.gh-338-lambda-template-param-outer.rto/default.2.1.txt
  • tests/tests/changes/.gh-338-lambda-template-param-outer.rto/default.2.matches.txt
  • tests/tests/changes/.gh-338-lambda-template-param-overload.rto/default.1.1.txt
  • tests/tests/changes/.gh-338-lambda-template-param-overload.rto/default.2.1.txt
  • tests/tests/changes/.gh-338-lambda-template-param-qualified.rto/default.1.1.txt
  • tests/tests/changes/.gh-338-lambda-template-param-qualified.rto/default.2.1.txt
  • tests/tests/changes/.gh-338-lambda-template-param-variations-negative.rto/default.1.1.txt
  • tests/tests/changes/.gh-338-lambda-template-param-variations-negative.rto/default.1.matches.txt
  • tests/tests/changes/.gh-338-lambda-template-param-variations.rto/default.1.1.txt
  • tests/tests/changes/.gh-338-lambda-template-param-variations.rto/default.2.1.txt
  • tests/tests/changes/.gh-338-lambda-template-param.rto/default.1.1.txt
  • tests/tests/changes/.gh-338-lambda-template-param.rto/default.2.1.txt
  • tests/tests/changes/gh-338-lambda-template-param-enable-if.sft.cpp
  • tests/tests/changes/gh-338-lambda-template-param-generic.sft.cpp
  • tests/tests/changes/gh-338-lambda-template-param-gnu.sft.cpp
  • tests/tests/changes/gh-338-lambda-template-param-incomplete.sft.cpp
  • tests/tests/changes/gh-338-lambda-template-param-limits.sft.cpp
  • tests/tests/changes/gh-338-lambda-template-param-mismatch.sft.cpp
  • tests/tests/changes/gh-338-lambda-template-param-outer.sft.cpp
  • tests/tests/changes/gh-338-lambda-template-param-overload.sft.cpp
  • tests/tests/changes/gh-338-lambda-template-param-qualified.sft.cpp
  • tests/tests/changes/gh-338-lambda-template-param-variations-negative.sft.cpp
  • tests/tests/changes/gh-338-lambda-template-param-variations.sft.cpp
  • tests/tests/changes/gh-338-lambda-template-param.sft.cpp
  • tests/tests/imported/clang/cpp/SemaCXX/.lambda-unevaluated.rto/default.1.1.txt
  • tests/tests/imported/clang/cpp/SemaCXX/.lambda-unevaluated.rto/default.2.1.txt
  • tests/tests/imported/gnu/cpp/cpp2a/.lambda-targ4.rto/default.1.1.txt
  • tests/tests/imported/gnu/cpp/cpp2a/.lambda-uneval7.rto/default.1.1.txt
💤 Files with no reviewable changes: 2
  • tests/tests/imported/gnu/cpp/cpp2a/.lambda-uneval7.rto/default.1.1.txt
  • tests/tests/imported/gnu/cpp/cpp2a/.lambda-targ4.rto/default.1.1.txt

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

📝 Walkthrough

Changes

Lambda template-parameter substitution

Layer / File(s) Summary
Bind parameters during lambda rescanning
src/il.c
Lambda rescanning identifies unqualified template parameters, applies available arguments, and restores symbol state afterward.
Scope enable_if substitution
src/overload.c, tests/tests/changes/gh-338-lambda-template-param-enable-if.sft.cpp, tests/tests/changes/.gh-338-lambda-template-param-enable-if.rto/*
enable_if substitution uses the associated template instantiation scope. Tests cover C++20 and C++23.
Validate supported lambda references
tests/tests/changes/gh-338-lambda-template-param*.sft.cpp, tests/tests/changes/.gh-338-lambda-template-param*.rto/*
Regression tests cover declaration contexts, qualified names, overloads, nested templates, member templates, partial specializations, and GNU-specific cases.
Validate unsupported cases and diagnostics
tests/tests/imported/*, tests/tests/changes/gh-338-lambda-template-param-generic.sft.cpp, tests/tests/changes/gh-338-lambda-template-param-limits.sft.cpp, tests/tests/changes/gh-338-lambda-template-param-variations-negative.sft.cpp
Tests preserve undefined-name diagnostics for generic lambdas, template parameter packs, and other unsupported cases. Affected expected diagnostics are updated. src/Changes documents the supported boundaries.

Priority: ➖ Normal

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

Change: Bug fix · Severity of issue fixed: Medium

Sequence Diagram(s)

sequenceDiagram
  participant FunctionTemplateSubstitution
  participant copy_template_param_lambda_expr
  participant TemplateInstantiationScope
  participant LambdaRescan
  FunctionTemplateSubstitution->>copy_template_param_lambda_expr: substitute lambda expression
  copy_template_param_lambda_expr->>TemplateInstantiationScope: locate matching template parameter list
  TemplateInstantiationScope->>copy_template_param_lambda_expr: provide available arguments
  copy_template_param_lambda_expr->>LambdaRescan: rescan cached lambda tokens
  LambdaRescan-->>FunctionTemplateSubstitution: return substituted lambda
Loading

Suggested reviewers: nv-cmeerw

Merge Risk: ⚪ Minimal · up to 4cb3a

The change appears mergeable after normal checks. The documented unsupported lambda cases remain outside its intended scope.

Pre-merge checks: Passed 4 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Docstring Coverage Inconclusive Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 71 functions across 12 files. (37 skipped:… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly summarizes the main change: allowing lambdas in function-template declarations to name function template parameters. It is concise and related to the pull request objectives.
Linked Issues check Passed The PR satisfies the coding requirements in [#338]. src/il.c binds available template arguments while rescanning cached non-generic lambda expressions and restores the symbol state. src/overload.c…
Out of Scope Changes check Passed The changes remain within [#338]. The release note, regression tests, expected diagnostics, and imported-test updates support the lambda substitution behavior or record its changed diagnostics. No unr…
Full details: Linked Issues check

Explanation

The PR satisfies the coding requirements in [#338]. src/il.c binds available template arguments while rescanning cached non-generic lambda expressions and restores the symbol state. src/overload.c adds the required instantiation scope for enable_if substitution. The new tests cover the reported parameter-type case and additional declaration contexts, including default template arguments, constraints, exception specifications, and nested uses. The tests also record the documented limits for generic lambdas and template parameter packs.

Full details: Out of Scope Changes check

Explanation

The changes remain within [#338]. The release note, regression tests, expected diagnostics, and imported-test updates support the lambda substitution behavior or record its changed diagnostics. No unrelated public API or unrelated feature change appears in the supplied whole-PR summary.

Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 71 functions across 12 files. (37 skipped: 35 unsupported, 2 too large.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@mborland

Copy link
Copy Markdown
Contributor Author

A follow up issue has been added for generics and packs: #346

@edgcpp-bot

Copy link
Copy Markdown
Collaborator

AcknowlEDG review results updated for 4cb3ad5656b4:

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

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A lambda that names a template parameter in a function template's declaration cannot be substituted

3 participants