[llvm-bugs] [Bug 48315] New: function_ref and unique_function doesn't handle empty callables correctly.

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Nov 27 04:49:02 PST 2020


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: unassignedbugs at nondot.org
          Reporter: N.James93 at hotmail.co.uk
                CC: llvm-bugs at 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20201127/83109cb9/attachment.html>


More information about the llvm-bugs mailing list