Repository navigation
make returning a reference bound to a temporary an error in C++26 (P2748), fix for [GH #106] - #388
mohitmishra786 wants to merge 2 commits into
Conversation
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Diagnostic rule and regression coverage src/overload.c, tests/tests/changes/GH106*.sft.cpp, tests/tests/changes/.GH106*.rto/*, tests/tests/cwg/.p2748R5.rto/default.1.1.txt, tests/tests/imported/clang/cpp/CXX/stmt.stmt/stmt.return/.p6.rto/default.1.1.txt, src/pending_changes/gh-106-return-ref-to-temporary.txt |
The diagnostic uses whether the initializer was a similar-type lvalue to distinguish temporary-bound references. Tests and expected output cover C++23 and C++26 modes, compiler-version settings, temporary expressions, and local-variable references. The pending note describes the diagnostic behavior. |
Priority:
Estimated code review effort: 3 (Moderate) | ~20 minutes
Change: Bug fix
Possibly related PRs
- edgcpp/compiler#389: It changes classification of member access on class temporaries, which affects the temporary-member cases covered by this PR.
Suggested reviewers: nv-cmeerw, darkarc
Merge Risk: 
Minimal · up to e5e47
-
This change makes returning a reference bound to a temporary an error in C++26 mode. Older GCC and Clang emulation modes keep a warning, and returns of references to local variables still warn. No remaining merge-blocking issue was found.
Pre-merge checks: 
3 · 
1 · 
1
-
Failed checks: 1 warning · 1 inconclusive Passed checks: 3 passed-
Full details: Title check
-
Explanation
The title names the primary change: returning a reference bound to a temporary becomes an error in C++26 (P2748), and it references the linked issue GH
#106. The raw summary confirms the src/overload.c change, the C++26 error behavior, and the GCC-before-14 and Clang-before-19 warning retention. The objectives describe the same change, so the title matches the changeset. The title is long (92 characters) but still specific and accurate.
Full details: Out of Scope Changes check
-
Explanation
The source change, diagnostic note, tests, and expected outputs support issue
#106. They cover the requested C++26 severity change and the specified compiler-version compatibility behavior. The local-variable warning remains unchanged. No unrelated behavior is demonstrated.
-
Full details: Linked Issues check
-
Explanation
Issue
#106requires P2748R5. The implementation changes the temporary-reference diagnostic to an error in C++26 and preserves warnings for the specified older GCC and Clang emulation modes. The tests cover direct temporaries, converted values, temporary members, rvalue references, and local variables. However, the PR description states that standard non-GNU, non-Clang mode does not diagnosereturn S().x;. The default C++26 expected output also records no error for that case. This leaves a concrete P2748 case unmet.Resolution
Make standard C++26 mode diagnose
return S().x;as an error. Update the related expected output and verify the GNU, Clang, and pre-C++26 mode expectations.
Full details: Docstring Coverage
-
Explanation
Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 12 functions across 2 files. (7 skipped: 6 unsupported, 1 too large.)
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
-
Finishing Touches
-
🧪 Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Comment @coderabbitai help to get the list of available commands.
|
AcknowlEDG review results updated for
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
…types, and update recordings. [GH edgcpp#106]
Fixes #106.
A return statement that binds the returned reference to a temporary is ill-formed in C++26 (P2748). The front end already detected this in
check_for_returning_reference_to_local_entity, but only issued the "returning reference to local temporary" warning.In C++26 that diagnostic is now an error. When emulating GCC before 14 or Clang before 19 it stays a warning, as in those compilers. GCC 14 and 15 with
-std=c++26error on the same cases (prvalue, converted value, member of a temporary, rvalue reference) and still only warn about returning a reference to a local variable, which is unchanged here.Known gap, not changed here: in standard (non-GNU, non-Clang) modes,
return S().x;is not detected as binding to a temporary at all (no warning before this change either), while GNU and Clang modes do catch it. A broader local regression run is in progress; I will follow up if it finds anything.Summary by CodeRabbit
Summary by CodeRabbit