mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-31 12:41:49 +01:00
FunctionRef: Strip cv qualifiers in the converting constructor
Without this some instances of copy construction would use the converting constructor & lead to the destination function_ref referring to the source function_ref instead of the underlying functor. Discovered in feedback from 857bf5da35af8e1f9425e1865dab5f5fce5e38f2 Thanks to Johannes Doerfert, Arthur O'Dwyer, and Richard Smith for the discussion and debugging.
This commit is contained in:
parent
b64d6b2ba8
commit
5704836e92
@ -114,9 +114,11 @@ public:
|
||||
function_ref(std::nullptr_t) {}
|
||||
|
||||
template <typename Callable>
|
||||
function_ref(Callable &&callable,
|
||||
std::enable_if_t<!std::is_same<std::remove_reference_t<Callable>,
|
||||
function_ref>::value> * = nullptr)
|
||||
function_ref(
|
||||
Callable &&callable,
|
||||
std::enable_if_t<
|
||||
!std::is_same<std::remove_cv_t<std::remove_reference_t<Callable>>,
|
||||
function_ref>::value> * = nullptr)
|
||||
: callback(callback_fn<typename std::remove_reference<Callable>::type>),
|
||||
callable(reinterpret_cast<intptr_t>(&callable)) {}
|
||||
|
||||
|
@ -38,4 +38,14 @@ TEST(FunctionRefTest, Copy) {
|
||||
EXPECT_EQ(1, Y());
|
||||
}
|
||||
|
||||
TEST(FunctionRefTest, BadCopy) {
|
||||
auto A = [] { return 1; };
|
||||
function_ref<int()> X;
|
||||
function_ref<int()> Y = A;
|
||||
function_ref<int()> Z = static_cast<const function_ref<int()> &&>(Y);
|
||||
X = Z;
|
||||
Y = nullptr;
|
||||
ASSERT_EQ(1, X());
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
Loading…
x
Reference in New Issue
Block a user