Skip to content

Conversation

@frederick-vs-ja
Copy link
Contributor

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.

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.
@frederick-vs-ja frederick-vs-ja added the clang:frontend Language frontend issues, e.g. anything involving "Sema" label May 29, 2025
@llvmbot llvmbot added the clang Clang issues not falling into any other category label May 29, 2025
@llvmbot
Copy link
Member

llvmbot commented May 29, 2025

@llvm/pr-subscribers-clang

Author: A. Jiang (frederick-vs-ja)

Changes

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.


Full diff: https://github.com/llvm/llvm-project/pull/141909.diff

3 Files Affected:

  • (modified) clang/docs/ReleaseNotes.rst (+2)
  • (modified) clang/lib/Sema/SemaTypeTraits.cpp (+3)
  • (modified) clang/test/SemaCXX/deprecated-builtins.cpp (+1)
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}}
 
 }
 

@frederick-vs-ja

This comment was marked as resolved.

@frederick-vs-ja
Copy link
Contributor Author

Documentation build failure is probably unrelated and being fixed in #142387.

@frederick-vs-ja frederick-vs-ja merged commit 208e3b0 into llvm:main Jun 3, 2025
11 of 12 checks passed
@frederick-vs-ja frederick-vs-ja deleted the deprecate-__reference_binds_to_temporary branch June 3, 2025 03:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

__reference_binds_to_temporary is missing binding an rvalue reference to a prvalue

3 participants