Skip to content

Fix crash in alias template CTAD with member template call in constructor noexcept [GH #532] - #531

Merged
nv-cmeerw merged 1 commit into
edgcpp:mainfrom
gwllx:gh-522-alias-ctad-noexcept
Nov 14, 2026
Merged

nv-cmeerw merged 1 commit into
edgcpp:mainfrom
gwllx:gh-522-alias-ctad-noexcept

Conversation

@gwllx

@gwllx gwllx commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #532.

make_operand_for_rescanned_identifier substituted its arguments and then passed the already substituted list to scan_identifier, which substituted them again. This could lead to errors and in the #532 reproducer, a segfault. This fix avoids substituting the explicit template arguments of a dependent member template-id twice.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed a compiler crash when C++20 class template argument deduction uses an alias template and a constructor’s noexcept specification calls a member function template with the constructor’s parameter pack.
  • Tests
    • Added regression coverage for this scenario across multiple compiler configurations.

@gwllx
gwllx requested a review from a team November 13, 2026 11:13
@gwllx gwllx changed the title Fix crash in alias template CTAD with member template call in constructor noexcept Fix crash in alias template CTAD with member template call in constructor noexcept [GH #522] Nov 13, 2026
@coderabbitai

coderabbitai Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The compiler now stores a separately rebuilt template argument list for dependent template references, leaving the explicit list available for later substitution by scan_identifier. A C++20 regression case and compiler-specific fixtures cover alias-template CTAD with a constructor noexcept member-template call.

Changes: GH-532 regression fix

Layer / File(s) Summary
Template argument substitution
src/expr.c
The dependent template reference now uses a separately rebuilt argument list. The original explicit list remains available for substitution by scan_identifier.
Alias-template CTAD regression
tests/tests/regressions/gh-532.sft.cpp, tests/tests/regressions/.gh-532.rto/*, src/pending_changes/gh-532-alias-ctad-noexcept-template-call.txt
The C++20 regression test and compiler-specific fixtures cover the reported alias-template CTAD scenario. The pending-changes note includes its description and reproducer.

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

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: nv-cmeerw, daveedvdv-nvidia

Merge Risk: Minimal · up to b8076

This change fixes a compiler crash by avoiding duplicate template argument substitution, and a regression test covers the reported case. No outstanding risks were identified, so it looks ready to merge.

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 crash fix, the affected feature (alias template CTAD), the triggering construct (member template call in constructor noexcept), and the issue number. The raw summary describes a ch…
Linked Issues check Passed Issue #532 requires that the alias-template CTAD reproducer compile under cpfe --c++20 without a segfault. The issue attributes the crash to double substitution of the explicit template arguments of…
Out of Scope Changes check Passed All changed files relate to #532. src/expr.c contains the substitution fix. src/pending_changes/gh-532-alias-ctad-noexcept-template-call.txt documents the fix. tests/tests/regressions/gh-532.sft.cpp a…
Full details: Title check

Explanation

The title names the crash fix, the affected feature (alias template CTAD), the triggering construct (member template call in constructor noexcept), and the issue number. The raw summary describes a change to src/expr.c that stops explicit template arguments from being substituted twice, which matches the crash fix in the title. The PR objectives describe the same duplicate-substitution bug and link it to issue #532. The title is specific and accurate, so it passes.

Full details: Linked Issues check

Explanation

Issue #532 requires that the alias-template CTAD reproducer compile under cpfe --c++20 without a segfault. The issue attributes the crash to double substitution of the explicit template arguments of a dependent member template-id, which leads to an out-of-range index in get_template_arg_by_list_pos. The diff in src/expr.c (whole PR, merge base to head) changes the dependent non-type template parameter branch of make_operand_for_rescanned_identifier. The expression copy_template_arg_list_with_substitution_rebuilding_arg_operands now writes its result to a new local, subst_templ_arg_list. The unsubstituted expl_templ_arg_list is no longer replaced, so scan_identifier performs the only substitution. The template-reference constant's arg_list takes the rebuilt list. This addresses the root cause that #532 describes. The PR also adds a regression test, tests/tests/regressions/gh-532.sft.cpp, with the reproducer and matching .rto fixtures. I did not execute the compiler, so the absence of the segfault rests on source reading and the added test, not on a run result.

Full details: Out of Scope Changes check

Explanation

All changed files relate to #532. src/expr.c contains the substitution fix. src/pending_changes/gh-532-alias-ctad-noexcept-template-call.txt documents the fix. tests/tests/regressions/gh-532.sft.cpp and the .rto/default.N.1.txt fixtures add the regression test and its command variants. The src/expr.c hunk is limited to the affected branch and its comment. No unrelated behavior change appears in the reviewed hunk. The whole-PR diff of other source files was not inspected in full, but the change summary lists no other source changes.

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 ed0db74 and b8076ed.

Files selected for processing: 7

  • src/expr.c
  • src/pending_changes/gh-532-alias-ctad-noexcept-template-call.txt
  • tests/tests/regressions/.gh-532.rto/default.1.1.txt
  • tests/tests/regressions/.gh-532.rto/default.2.1.txt
  • tests/tests/regressions/.gh-532.rto/default.3.1.txt
  • tests/tests/regressions/.gh-532.rto/default.4.1.txt
  • tests/tests/regressions/gh-532.sft.cpp

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 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 change the GH references to the issue #532

Comment thread tests/tests/regressions/gh-522.sft.cpp Resolved
@edgcpp-bot

Copy link
Copy Markdown
Collaborator

AcknowlEDG review results updated for ed0db74daa3b:

@gwllx gwllx changed the title Fix crash in alias template CTAD with member template call in constructor noexcept [GH #522] Fix crash in alias template CTAD with member template call in constructor noexcept [GH #532] Nov 13, 2026
@edgcpp-bot

Copy link
Copy Markdown
Collaborator

AcknowlEDG review results updated for ed0db74daa3b:

CI success.

@gwllx
gwllx force-pushed the gh-522-alias-ctad-noexcept branch from ed0db74 to b8076ed Compare November 13, 2026 13:37

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

@edgcpp-bot

Copy link
Copy Markdown
Collaborator

AcknowlEDG review results updated for b8076ed3a6e7:

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 fdebe70 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 member template call in constructor noexcept segfaults

3 participants