Skip to content

Fix use of destroyed pack mapping in alias template CTAD [GH #533] - #534

Merged
nv-cmeerw merged 1 commit into
edgcpp:mainfrom
gwllx:gh-523-alias-ctad-pack-mapping
Nov 14, 2026
Merged

nv-cmeerw merged 1 commit into
edgcpp:mainfrom
gwllx:gh-523-alias-ctad-pack-mapping

Conversation

@gwllx

@gwllx gwllx commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #533.

create_transformed_deduction_guide_for_alias_template declared pack_mapping and alias_pack_mapping in an inner block, but ctws_state.alias_parameter_pack_mapping still points to one of them following that block. This fix keep the pack mappings alive for as long as ctws_state refers to them.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed a crash in C++20 alias-template class argument deduction when the underlying variadic class template has a constrained constructor.
  • Tests
    • Added regression coverage across multiple compiler frontends.

@gwllx
gwllx requested a review from a team November 13, 2026 11:21
@coderabbitai

coderabbitai Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The change moves deduction-guide pack-mapping declarations outside a conditional block and adds a C++20 regression test with four compiler configurations.

Changes: Alias-template CTAD regression

Layer / File(s) Summary
Deduction-guide pack-mapping scope
src/templates.c
pack_mapping and alias_pack_mapping are declared before the conditional block. A comment notes that alias_pack_mapping is also used later for requires-clause processing.
Regression test and compiler fixtures
tests/tests/regressions/gh-533.sft.cpp, tests/tests/regressions/.gh-533.rto/*, src/pending_changes/gh-533-alias-ctad-pack-requires.txt
The regression test covers alias-template CTAD with a constrained variadic constructor. Four fixtures specify C++20 compiler configurations. The pending-change report describes the case.

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

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: nv-cmeerw

Merge Risk: Minimal · up to 7e50c

The change fixes a use-after-free crash in alias-template CTAD and adds a regression test. No remaining merge-blocking risk was identified.

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: fixing a use of a destroyed pack mapping in alias template CTAD, which matches the raw summary (pack_mapping and alias_pack_mapping moved out of the conditional block)…
Linked Issues check Passed Issue #533 requires that valid C++20 alias-template CTAD for a variadic class template with a constrained constructor not read freed memory. The reported cause is that ctws_state.alias_parameter_pack_…
Out of Scope Changes check Passed All changes connect to #533. src/templates.c contains only the scope hoisting and its explanatory comment. The pending_changes entry documents the GH #533 report. The regression fixtures under tests/t…
Full details: Title check

Explanation

The title names the main change: fixing a use of a destroyed pack mapping in alias template CTAD, which matches the raw summary (pack_mapping and alias_pack_mapping moved out of the conditional block) and the linked objectives (keeping pack mappings alive while ctws_state refers to them). The GH #533 reference identifies the linked issue. No unrelated or vague wording was found.

Full details: Linked Issues check

Explanation

Issue #533 requires that valid C++20 alias-template CTAD for a variadic class template with a constrained constructor not read freed memory. The reported cause is that ctws_state.alias_parameter_pack_mapping points to pack_mapping declared in an inner block that ends before the guide requires-clause is substituted. The diff against the merge base hoists the declarations of pack_mapping and alias_pack_mapping from the inner block in create_transformed_deduction_guide_for_alias_template (src/templates.c) to the enclosing function scope. The added comment states that alias_pack_mapping stays in use after the block. The object now outlives its use by ctws_state, which addresses the stated cause. A regression test, tests/tests/regressions/gh-533.sft.cpp, defines S with a constructor constrained by a static member and instantiates alias A, matching the issue reproducer. The regression fixture files are present. Limit: I did not inspect the rest of the function to confirm that no cleanup inside the former block depends on the old scope. The test outcome in debug or ASan builds is not confirmed from the evidence available.

Full details: Out of Scope Changes check

Explanation

All changes connect to #533. src/templates.c contains only the scope hoisting and its explanatory comment. The pending_changes entry documents the GH #533 report. The regression fixtures under tests/tests/regressions/.gh-533.rto/ and the test source gh-533.sft.cpp are supporting test artifacts for the same issue. No unrelated code or public declarations changed, according to the diff and the summary.

Finishing Touches

Generate unit tests (beta)

  • 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 9b6450a and 7e50cd3.

Files selected for processing: 7

  • src/pending_changes/gh-533-alias-ctad-pack-requires.txt
  • src/templates.c
  • tests/tests/regressions/.gh-533.rto/default.1.1.txt
  • tests/tests/regressions/.gh-533.rto/default.2.1.txt
  • tests/tests/regressions/.gh-533.rto/default.3.1.txt
  • tests/tests/regressions/.gh-533.rto/default.4.1.txt
  • tests/tests/regressions/gh-533.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.

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

Thanks. Just a few minor comments, and please also change the references to the issue number #533

Comment thread tests/tests/regressions/gh-523.sft.cpp Resolved
@gwllx gwllx changed the title Fix use of destroyed pack mapping in alias template CTAD [GH #523] Fix use of destroyed pack mapping in alias template CTAD [GH #533] Nov 13, 2026
@edgcpp-bot

Copy link
Copy Markdown
Collaborator

AcknowlEDG review results updated for 9b6450a923af:

@edgcpp-bot

Copy link
Copy Markdown
Collaborator

AcknowlEDG review results updated for 9b6450a923af:

CI success.

@gwllx
gwllx force-pushed the gh-523-alias-ctad-pack-mapping branch from 9b6450a to 7e50cd3 Compare November 13, 2026 13:35
@gwllx

gwllx commented Nov 13, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @nv-cmeerw. Regarding process: is there a better way to request issue creation from the discussion before opening a PR?

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

Thanks, looks good to me.

@nv-cmeerw

Copy link
Copy Markdown
Contributor

Thanks @nv-cmeerw. Regarding process: is there a better way to request issue creation from the discussion before opening a PR?

I don't really know yet, it's something we need to discuss.

@edgcpp-bot

Copy link
Copy Markdown
Collaborator

AcknowlEDG review results updated for 7e50cd380024:

@edgcpp-bot

Copy link
Copy Markdown
Collaborator

AcknowlEDG review results updated for 7e50cd380024:

CI success.

@nv-cmeerw
nv-cmeerw added this pull request to the merge queue Nov 14, 2026
Merged via the queue into edgcpp:main with commit 177765b Nov 14, 2026
22 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.

Alias template CTAD with a constructor trailing requires clause causes segfault

3 participants