[libcxx-commits] [libcxx] [libc++][type_traits] Implements "A type trait to detect reference binding to temporary" (PR #128649)

A. Jiang via libcxx-commits libcxx-commits at lists.llvm.org
Thu Feb 27 21:57:05 PST 2025


================
@@ -0,0 +1,44 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP___TYPE_TRAITS_REFERENCE_CONVERTS_FROM_TEMPORARARY_H
+#define _LIBCPP___TYPE_TRAITS_REFERENCE_CONVERTS_FROM_TEMPORARARY_H
+
+#include <__config>
+#include <__type_traits/integral_constant.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if __has_builtin(__reference_converts_from_temporary) ||                                                              \
+    (defined(_LIBCPP_COMPILER_CLANG_BASED) && (__clang_major__ >= 19) && (__clang_minor__ >= 1) &&                     \
+     (__clang_patchlevel__ >= 2))
----------------
frederick-vs-ja wrote:

I think it would be clearer to move the conditions to `<__config>` and create a temporary macro.
Also, couldn't we enable the code for Clang 19.1.0? IIUC in that version `__has_builtin(__reference_converts_from_temporary)` was wrong but `__reference_converts_from_temporary` already worked.

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


More information about the libcxx-commits mailing list