<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - function_ref and unique_function doesn't handle empty callables correctly."
   href="https://bugs.llvm.org/show_bug.cgi?id=48315">48315</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>function_ref and unique_function doesn't handle empty callables correctly.
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Support Libraries
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>N.James93@hotmail.co.uk
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>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.

<span class="quote">>  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</span ></pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>