File tree Expand file tree Collapse file tree 2 files changed +35
-0
lines changed
Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -265,6 +265,14 @@ class _LIBCPP_UNIQUE_PTR_TRIVIAL_ABI unique_ptr {
265265
266266 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 __add_lvalue_reference_t <_Tp> operator *() const
267267 _NOEXCEPT_ (_NOEXCEPT_(*std::declval<pointer>())) {
268+ // TODO(LLVM-21): Remove this workaround
269+ #if __has_builtin(__reference_converts_from_temporary) || \
270+ (defined (_LIBCPP_CLANG_VER) && \
271+ ((!defined (__ANDROID__) && _LIBCPP_CLANG_VER >= 1901 ) || (defined (__ANDROID__) && _LIBCPP_CLANG_VER >= 2000 )))
272+ static_assert (
273+ !__reference_converts_from_temporary (__add_lvalue_reference_t <_Tp>, decltype (*std::declval<pointer>())),
274+ " Reference type _Tp must not convert from a temporary object" );
275+ #endif
268276 return *__ptr_;
269277 }
270278 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 pointer operator ->() const _NOEXCEPT { return __ptr_; }
Original file line number Diff line number Diff line change 1+ // ===----------------------------------------------------------------------===//
2+ //
3+ // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+ // See https://llvm.org/LICENSE.txt for license information.
5+ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+ //
7+ // ===----------------------------------------------------------------------===//
8+
9+ // REQUIRES: std-at-least-c++11
10+
11+ // <memory>
12+
13+ #include < memory>
14+
15+ struct deleter {
16+ using pointer = long *;
17+ void operator ()(pointer) const {}
18+ };
19+
20+ int main (int , char **) {
21+ long l = 0 ;
22+ std::unique_ptr<const int , deleter> p (&l);
23+ // expected-error-re@*:* {{static assertion failed{{.*}}'!__reference_converts_from_temporary(const int &, long &)': Reference type _Tp must not convert from a temporary object}}
24+ // expected-error@*:*{{returning reference to local temporary object}}
25+ int i = *p; // expected-note {{requested here}}
26+ return 0 ;
27+ }
You can’t perform that action at this time.
0 commit comments