[clang] [Clang] Properly deprecate `__reference_binds_to_temporary` (PR #141909)

A. Jiang via cfe-commits cfe-commits at lists.llvm.org
Thu May 29 00:57:18 PDT 2025


https://github.com/frederick-vs-ja created https://github.com/llvm/llvm-project/pull/141909

At the time `__reference_constructs_from_temporary` got implemented, `__reference_binds_to_temporary` was mentioned as deprecated in `LanguageExtensions.rst`, but no deprecation warning was emitted. This PR adds the previously missing warning.

Closes #44056.

>From 01ad4047618d700ed7f27e5b062d9eb2d2c5a312 Mon Sep 17 00:00:00 2001
From: "A. Jiang" <de34 at live.cn>
Date: Thu, 29 May 2025 15:55:34 +0800
Subject: [PATCH] [Clang] Properly deprecate `__reference_binds_to_temporary`

At the time `__reference_constructs_from_temporary` got implemented,
`__reference_binds_to_temporary` was mentioned as deprecated in
`LanguageExtensions.rst`, but no deprecation warning was emitted. This
PR adds the previously missing warning.
---
 clang/docs/ReleaseNotes.rst                | 2 ++
 clang/lib/Sema/SemaTypeTraits.cpp          | 3 +++
 clang/test/SemaCXX/deprecated-builtins.cpp | 1 +
 3 files changed, 6 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 32266fce4d3cb..e1ff28e684af5 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -310,6 +310,8 @@ Non-comprehensive list of changes in this release
   different than before.
 - Fixed a crash when a VLA with an invalid size expression was used within a
   ``sizeof`` or ``typeof`` expression. (#GH138444)
+- Deprecation warning is emitted for the deprecated ``__reference_binds_to_temporary`` intrinsic.
+  ``__reference_constructs_from_temporary`` should be used instead. (#GH44056)
 
 New Compiler Flags
 ------------------
diff --git a/clang/lib/Sema/SemaTypeTraits.cpp b/clang/lib/Sema/SemaTypeTraits.cpp
index 7bf3c8eaabf4b..04f54d7044e4f 100644
--- a/clang/lib/Sema/SemaTypeTraits.cpp
+++ b/clang/lib/Sema/SemaTypeTraits.cpp
@@ -1458,6 +1458,9 @@ void DiagnoseBuiltinDeprecation(Sema &S, TypeTrait Kind, SourceLocation KWLoc) {
   case UTT_IsTriviallyRelocatable:
     Replacement = clang::UTT_IsCppTriviallyRelocatable;
     break;
+  case BTT_ReferenceBindsToTemporary:
+    Replacement = clang::BTT_ReferenceConstructsFromTemporary;
+    break;
   default:
     return;
   }
diff --git a/clang/test/SemaCXX/deprecated-builtins.cpp b/clang/test/SemaCXX/deprecated-builtins.cpp
index fafc1da4da13e..1234c8354fcab 100644
--- a/clang/test/SemaCXX/deprecated-builtins.cpp
+++ b/clang/test/SemaCXX/deprecated-builtins.cpp
@@ -15,6 +15,7 @@ void f() {
     a = __has_trivial_constructor(A);  // expected-warning-re {{__has_trivial_constructor {{.*}} use __is_trivially_constructible}}
     a = __has_trivial_move_constructor(A);  // expected-warning-re {{__has_trivial_move_constructor {{.*}} use __is_trivially_constructible}}
     a = __has_trivial_destructor(A);  // expected-warning-re {{__has_trivial_destructor {{.*}} use __is_trivially_destructible}}
+    a = __reference_binds_to_temporary(const A&, A); // expected-warning-re {{__reference_binds_to_temporary {{.*}} use __reference_constructs_from_temporary}}
 
 }
 



More information about the cfe-commits mailing list