Skip to content

Commit 3119a8b

Browse files
committed
[libc++] Add [[clang::lifetimebound]] to std::identity
1 parent 8ea447b commit 3119a8b

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

libcxx/include/__functional/identity.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ struct __is_identity<reference_wrapper<const __identity> > : true_type {};
4444

4545
struct identity {
4646
template <class _Tp>
47-
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Tp&& operator()(_Tp&& __t) const noexcept {
47+
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Tp&& operator()(_LIBCPP_LIFETIMEBOUND _Tp&& __t) const noexcept {
4848
return std::forward<_Tp>(__t);
4949
}
5050

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
// UNSUPPORTED: c++03, c++11, c++14, c++17
10+
// ADDITIONAL_COMPILE_FLAGS: -Wno-pessimizing-move -Wno-unused-variable
11+
12+
#include <functional>
13+
14+
#include "test_macros.h"
15+
16+
void func() {
17+
auto&& v1 = std::identity()(1); // expected-warning {{temporary bound to local reference 'v1' will be destroyed at the end of the full-expression}}
18+
}

0 commit comments

Comments
 (0)