https://bugs.llvm.org/show_bug.cgi?id=48315
Bug ID: 48315
Summary: function_ref and unique_function doesn't handle empty
callables correctly.
Product: libraries
Version: trunk
Hardware: PC
OS: Linux
Status: NEW
Severity: enhancement
Priority: P
Component: Support Libraries
Assignee: unassignedb...@nondot.org
Reporter: n.jame...@hotmail.co.uk
CC: llvm-bugs@lists.llvm.org
Using copy/move constructor and assignment operators on llvm::function_ref and
llvm::unique_function doesn't take into account if the source functor is in a
valid state.
I ran some permutations of assignment and construction with null source
functors and most of the tests failed. This will lead to bugs if one of these
operations is used and the state of the functor isn't checked before.
> using Func = llvm::unique_function<void() const>;
> using FuncRef = llvm::function_ref<void()>;
> Func FEmpty{}, FAssigned{};
> FuncRef REmpty{}, RAssigned{};
>
> Func FConstructed(REmpty);
> FuncRef RConstructed(FEmpty);
> FuncRef RCopyConstructed(REmpty);
>
> FAssigned = REmpty;
> RAssigned = FEmpty;
>
> EXPECT_TRUE(!FEmpty);
> EXPECT_TRUE(!FAssigned); // FAIL
> EXPECT_TRUE(!FConstructed); // FAIL
> EXPECT_TRUE(!REmpty);
> EXPECT_TRUE(!RAssigned); // FAIL
> EXPECT_TRUE(!RConstructed); // FAIL
> EXPECT_TRUE(!RCopyConstructed);
>
> Func FMoveConstructed(std::move(FEmpty));
> Func RMoveConstructed(std::move(REmpty));
>
> EXPECT_TRUE(!FEmpty);
> EXPECT_TRUE(!FMoveConstructed);
> EXPECT_TRUE(!REmpty);
> EXPECT_TRUE(!RMoveConstructed); // FAIL
--
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs