[LLVMbugs] [Bug 20039] New: Constructing std::function from empty compatible std::function results in half-empty state

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Sat Jun 14 10:42:39 PDT 2014


http://llvm.org/bugs/show_bug.cgi?id=20039

            Bug ID: 20039
           Summary: Constructing std::function from empty compatible
                    std::function results in half-empty state
           Product: libc++
           Version: unspecified
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: All Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: kaballo86 at hotmail.com
                CC: llvmbugs at cs.uiuc.edu, mclow.lists at gmail.com
    Classification: Unclassified

Created attachment 12657
  --> http://llvm.org/bugs/attachment.cgi?id=12657&action=edit
proposed fix

Constructing an `std::function` from an instance of `std::function` with a
compatible signature fails to meet the precondition when the source argument is
empty:

> template<class F> function(F f);
> Postconditions: !*this if any of the following hold:
> — F is an instance of the function class template, and !f.

    int main() {
      std::function<double(double)> f;
      std::function<float(double)> g = f;
      std::function<double(float)> h = f;
      std::function<float(float)> i = f;

      assert(!f);
      assert(!g); // fails
      assert(!h); // fails
      assert(!i); // fails
    }

This results in a half-empty state of sorts, where the wrapper isn't empty but
invoking it will result in invoking an empty wrapper.

This is due to a typo in `function::__not_null`, resulting in an overload for
`std::function` that has a non-deducible template parameter and thus isn't a
candidate for overload resolution. This applies to both the variadic and
non-variadic definitions. The non-variadic definition for a nullary function is
also missing an overload for function pointers.

-- 
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/20140614/42421fa7/attachment.html>


More information about the llvm-bugs mailing list