Skip to content

Emit constructor arguments in compound literals. [GH #619] - #616

Open
jakub-labenski wants to merge 1 commit into
edgcpp:mainfrom
jakub-labenski:fix/gh-614-compound-literal-constructor
Open

jakub-labenski wants to merge 1 commit into
edgcpp:mainfrom
jakub-labenski:fix/gh-614-compound-literal-constructor

Conversation

@jakub-labenski

@jakub-labenski jakub-labenski commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

The C++-generating back end could assert when a compound literal invoked a
constructor and appeared as a temporary, such as in a = b = (S){n, 0};.
The earlier fix for EDGcpfe/19463 handled variable initializers through
gen_dynamic_init. The assignment case reached gen_compound_literal
directly through gen_temp_init.

Move constructor emission into gen_compound_literal so both paths use the
same code. Reuse the existing argument generator to preserve default
arguments and emit the correct braces for std::initializer_list
constructors.

Discussion #614.
Issue: #619.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed C++ code generation for compound literals that invoke constructors when used as temporary values, including in assignments and initializer-list expressions.
  • Tests
    • Added regression coverage for constructor calls, chained assignments, and initializer-list temporaries across supported C++17 modes.

@jakub-labenski
jakub-labenski requested a review from a team November 27, 2026 14:21
@coderabbitai

coderabbitai Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The C++ back end now routes compound literals through gen_compound_literal, which emits constructor arguments for constructor initializers. A regression test checks chained assignment and initializer-list construction of temporaries across compiler options.

Changes: Compound literal constructor handling

Layer / File(s) Summary
Route compound literals through constructor emission
src/cp_gen_be.c
gen_compound_literal handles constructor initializer arguments without surrounding parentheses. gen_dynamic_init routes all compound literals through this helper.
Test temporary construction
tests/tests/regressions/gh-619-compound-literal-constructor.sft.cpp, tests/tests/regressions/.gh-619-compound-literal-constructor.rto/*, src/pending_changes/gh-619-compound-literal-constructor.txt
The regression test checks chained assignment from an S temporary and member access on a List temporary. Fixtures run the test with multiple compiler options. The release note describes the constructor-temporary case.

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

Change: Bug fix · Severity of issue fixed: Low

Possibly related issues

  • The reported assertion for a constructor compound literal used on the right side of an assignment matches the behavior addressed by this change.

Suggested labels: bug

Suggested reviewers: daveedvdv, nv-cmeerw, daveedvdv-nvidia

Merge Risk: Minimal · up to 97c80

This change fixes the code generator's handling of constructor-invoking compound literals used as temporaries, for example in chained assignments. A regression test covers the case. No remaining merge risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "Emit constructor arguments in compound literals. [GH #619]" matches the main change. The raw summary and PR objectives show that gen_compound_literal now emits constructor arguments for con…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Full details: Title check

Explanation

The title "Emit constructor arguments in compound literals. [GH #619]" matches the main change. The raw summary and PR objectives show that gen_compound_literal now emits constructor arguments for constructor-invoking compound literals, including temporaries such as the assignment case. The title is specific and concise. It references GH #619, although the PR objectives say the PR reports fixing #614 and also references #619. This does not make the title misleading.

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 0701342 and 97c80cf.

Files selected for processing: 11

  • src/cp_gen_be.c
  • src/pending_changes/gh-619-compound-literal-constructor.txt
  • tests/tests/regressions/.gh-619-compound-literal-constructor.rto/default.1.1.txt
  • tests/tests/regressions/.gh-619-compound-literal-constructor.rto/default.1.2.txt
  • tests/tests/regressions/.gh-619-compound-literal-constructor.rto/default.2.1.txt
  • tests/tests/regressions/.gh-619-compound-literal-constructor.rto/default.2.2.txt
  • tests/tests/regressions/.gh-619-compound-literal-constructor.rto/default.3.1.txt
  • tests/tests/regressions/.gh-619-compound-literal-constructor.rto/default.3.2.txt
  • tests/tests/regressions/.gh-619-compound-literal-constructor.rto/default.4.1.txt
  • tests/tests/regressions/.gh-619-compound-literal-constructor.rto/default.4.2.txt
  • tests/tests/regressions/gh-619-compound-literal-constructor.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.

@edgcpp-bot

Copy link
Copy Markdown
Collaborator

AcknowlEDG review results updated for 0701342fb79f:

CI success.

@jakub-labenski jakub-labenski changed the title Emit constructor arguments in compound literals. [GH #614] Emit constructor arguments in compound literals. [GH #619] Nov 27, 2026
@jakub-labenski
jakub-labenski force-pushed the fix/gh-614-compound-literal-constructor branch from 0701342 to 97c80cf Compare November 27, 2026 18:28
@edgcpp-bot

Copy link
Copy Markdown
Collaborator

AcknowlEDG review results updated for 97c80cf255fb:

@edgcpp-bot

Copy link
Copy Markdown
Collaborator

AcknowlEDG review results updated for 97c80cf255fb:

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.

2 participants