[clang] [Clang] Implement C++26 P2748R5 "Disallow Binding a Returned Glvalue to a Temporary" (PR #89942)

A. Jiang via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 24 21:10:40 PDT 2024


================
@@ -8340,8 +8340,17 @@ void Sema::checkInitializerLifetime(const InitializedEntity &Entity,
             << Entity.getType()->isReferenceType() << CLE->getInitializer() << 2
             << DiagRange;
       } else {
-        Diag(DiagLoc, diag::warn_ret_local_temp_addr_ref)
-         << Entity.getType()->isReferenceType() << DiagRange;
+        // P2748R5: Disallow Binding a Returned Glvalue to a Temporary.
+        // [stmt.return]/p6: In a function whose return type is a reference,
+        // other than an invented function for std::is_convertible ([meta.rel]),
+        // a return statement that binds the returned reference to a temporary
+        // expression ([class.temporary]) is ill-formed.
----------------
frederick-vs-ja wrote:

> I wanted to implement LWG4028 as well

I don't know which part of LWG4028 is "not yet implemented". As the submitter, my intent was just to reflect what implementations actually did and to avoid crux in the core wording.

https://github.com/llvm/llvm-project/pull/89942


More information about the cfe-commits mailing list