You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Fix C++26 references initialized from a reference parameter [GH #525] - #529
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.
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.
A new helper detects addresses of unknown objects in constants. The initializer check uses it to exclude matching constants from the folded-initializer path.
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.
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.
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: 4
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
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
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
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.
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
constexprdeclarations in C++23 and C++26 modes.