Skip to content

Fix C++26 references initialized from a reference parameter [GH #525] - #529

Open
mborland wants to merge 1 commit into
edgcpp:mainfrom
mborland:fix/525
Open

mborland wants to merge 1 commit into
edgcpp:mainfrom
mborland:fix/525

Conversation

@mborland

@mborland mborland commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

This PR fixes references initialized from a reference whose referent is not known. This only impacted C++26 mode for reference parameters and for local references. Also now properly errors in C++26 mode when used in constant expressions.

Summary by CodeRabbit

  • Bug Fixes
    • Corrected constant-expression handling for references whose referent cannot be determined at compile time. Such initializations are now rejected where a constant expression is required, including affected constexpr declarations in C++23 and C++26 modes.
    • This also applies to references in aggregates and references initialized from parameters or external references.

@mborland
mborland requested a review from a team November 12, 2026 16:13
@mborland mborland added the bug Something isn't working label Nov 12, 2026
@mborland mborland added this to C++26 Nov 12, 2026
@github-project-automation github-project-automation Bot moved this to Todo in C++26 Nov 12, 2026
@mborland mborland moved this from Todo to In Progress in C++26 Nov 12, 2026
@coderabbitai

coderabbitai Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The constant-folding check now rejects constants that address unknown objects. Regression tests cover reference initialization in C++23 and C++26, including runtime cases and constexpr initializations that produce errors.

Changes: Reference initialization

Layer / File(s) Summary
Unknown-object detection
src/il.h, src/il.c, src/decl_inits.c
A new helper detects addresses of unknown objects in constants. The initializer check uses it to exclude matching constants from the folded-initializer path.
Runtime reference cases
tests/tests/regressions/gh-525.sft.cpp, tests/tests/regressions/.gh-525.rto/*
The regression test covers reference parameters, structured bindings, aggregate and external references, and other reference cases. Fixtures run the test in C++23 and C++26 modes.
Constant-expression diagnostics
tests/tests/regressions/gh-525-negative.sft.cpp, tests/tests/regressions/.gh-525-negative.rto/*, tests/tests/imported/clang/cpp/SemaCXX/.constant-expression-cxx11.rto/*, tests/tests/imported/clang/cpp/SemaCXX/.constant-expression-p2280r4.rto/*, src/pending_changes/gh-525-reference-to-unknown-reference.txt
Negative tests and expected outputs cover rejected constexpr reference initializations. Imported diagnostic baselines also record changed constant-expression results. The pending-change note describes the affected cases.

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

Change: Bug fix

Possibly related issues

Suggested reviewers: nv-cmeerw, daveedvdv-nvidia

Merge Risk: Minimal · up to 78f9f

The change makes references initialized from a reference parameter bind to the right object, and it reports an error when such an initializer is used in a C++26 constant expression. No concrete merge-blocking risk remains. The regression tests and updated diagnostic baselines cover both the runtime and the rejected cases.

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 C++26 reference initialization when the initializing reference refers to an unknown object (reference parameter), tied to issue GH #525. The summary shows the c…
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.
Full details: Title check

Explanation

The title names the main change: fixing C++26 reference initialization when the initializing reference refers to an unknown object (reference parameter), tied to issue GH #525. The summary shows the core change is a new check, constant_addresses_unknown_object, that rejects such initializers in the constant-folding branch, plus tests and a pending-changes note for that behavior. The title matches the changeset and does not claim unrelated work.

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 341b1c2 and 78f9fbd.

Files selected for processing: 25

  • src/decl_inits.c
  • src/il.c
  • src/il.h
  • src/pending_changes/gh-525-reference-to-unknown-reference.txt
  • tests/tests/imported/clang/cpp/SemaCXX/.constant-expression-cxx11.rto/default.1.1.txt
  • tests/tests/imported/clang/cpp/SemaCXX/.constant-expression-cxx11.rto/default.2.1.txt
  • tests/tests/imported/clang/cpp/SemaCXX/.constant-expression-cxx11.rto/default.3.1.txt
  • tests/tests/imported/clang/cpp/SemaCXX/.constant-expression-cxx11.rto/edg_x86_32.1.1.txt
  • tests/tests/imported/clang/cpp/SemaCXX/.constant-expression-cxx11.rto/edg_x86_32.2.1.txt
  • tests/tests/imported/clang/cpp/SemaCXX/.constant-expression-cxx11.rto/edg_x86_32_cp.1.1.txt
  • tests/tests/imported/clang/cpp/SemaCXX/.constant-expression-cxx11.rto/edg_x86_32_cp.2.1.txt
  • tests/tests/imported/clang/cpp/SemaCXX/.constant-expression-cxx11.rto/edg_x86_32_cp.3.1.txt
  • tests/tests/imported/clang/cpp/SemaCXX/.constant-expression-cxx11.rto/edg_x86_64_cp.1.1.txt
  • tests/tests/imported/clang/cpp/SemaCXX/.constant-expression-cxx11.rto/edg_x86_64_cp.2.1.txt
  • tests/tests/imported/clang/cpp/SemaCXX/.constant-expression-cxx11.rto/edg_x86_64_cp.3.1.txt
  • tests/tests/imported/clang/cpp/SemaCXX/.constant-expression-p2280r4.rto/default.1.1.txt
  • tests/tests/imported/clang/cpp/SemaCXX/.constant-expression-p2280r4.rto/default.2.1.txt
  • tests/tests/regressions/.gh-525-negative.rto/default.1.1.txt
  • tests/tests/regressions/.gh-525-negative.rto/default.2.1.txt
  • tests/tests/regressions/.gh-525.rto/default.1.1.txt
  • tests/tests/regressions/.gh-525.rto/default.1.2.txt
  • tests/tests/regressions/.gh-525.rto/default.2.1.txt
  • tests/tests/regressions/.gh-525.rto/default.2.2.txt
  • tests/tests/regressions/gh-525-negative.sft.cpp
  • tests/tests/regressions/gh-525.sft.cpp
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.

@edgcpp-bot

Copy link
Copy Markdown
Collaborator

AcknowlEDG review results updated for 341b1c2757ce:

@edgcpp-bot

Copy link
Copy Markdown
Collaborator

AcknowlEDG review results updated for 341b1c2757ce:

CI failure.

@edgcpp-bot

Copy link
Copy Markdown
Collaborator

AcknowlEDG review results updated for 78f9fbd67e30:

@edgcpp-bot

Copy link
Copy Markdown
Collaborator

AcknowlEDG review results updated for 78f9fbd67e30:

CI success.

@mborland mborland linked an issue Nov 13, 2026 that may be closed by this pull request
7 tasks done

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

Status: In Progress

Development

Successfully merging this pull request may close these issues.

C++26: A reference bound to a reference parameter is wrong

2 participants